-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathScene+Sound.mm
127 lines (96 loc) · 2.34 KB
/
Scene+Sound.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Scene+Sound.m
// Core3D
//
// Created by CoreCode on 16.11.07.
// Copyright 2007 - 2012 CoreCode. Licensed under the MIT License, see LICENSE.txt
//
#ifndef DISABLE_SOUND
#import "Core3D.h"
#ifdef ALUT
#include <AL/alut.h>
#endif
extern int soundNodes;
@implementation Scene (Sound)
- (void)initSound
{
//#ifdef __APPLE__SHIT
//
ALCcontext *newContext = NULL;
ALCdevice *newDevice = NULL;
// Create a new OpenAL Device
// Pass NULL to specify the system’s default output device
newDevice = alcOpenDevice(NULL);
if (newDevice != NULL)
{
// Create a new OpenAL Context
// The new context will render to the OpenAL Device just created
newContext = alcCreateContext(newDevice, 0);
if (newContext != NULL)
{
// Make the new context the Current OpenAL Context
alcMakeContextCurrent(newContext);
}
}
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
int error = alGetError();
if (error != AL_NO_ERROR)
fatal("initSound alError %i", error);
error = alcGetError(newDevice);
if (error)
fatal("alcError %i", error);
#ifdef ALUT
static BOOL alutInited = FALSE;
if (!alutInited)
{
if (!alutInitWithoutContext(0, NULL))
NSLog(@"alutInit error %i", alutGetError());
alutInited = TRUE;
}
#endif
//#else
// static BOOL inited = FALSE;
//
// if (inited) return;
//
// inited = TRUE;
// if (!alutInit(0, NULL))
// {
// printf("alutInit error %li", (long)alutGetError);
// }
//#endif
alListenerfv(AL_VELOCITY, vector3f(0, 0, 0).data());
alListenerf(AL_GAIN, globalSettings.soundVolume);
}
- (void)deallocSound
{
@synchronized (self)
{
// NSLog(@"dealloc sound");
ALCcontext *context = NULL;
ALCdevice *device = NULL;
//Get active context
context = alcGetCurrentContext();
//Get device for active context
device = alcGetContextsDevice(context);
alcMakeContextCurrent(NULL);
//Release context
alcDestroyContext(context);
//Close device
alcCloseDevice(device);
#ifdef __APPLE__
int error = alGetError();
if (error != AL_NO_ERROR)
{
NSLog(@"Error: Scene+Sound dealloc: alError %i soundNodes %i soundBuffers %@", error, soundNodes, [[SoundBuffer allBuffers] description]);
}
#endif
//#ifdef ALUT
// NSLog(@"alutExit");
// if (!alutExit())
// NSLog(@"alutExit error %li", (long)alutGetError);
//#endif
}
}
@end
#endif