09846269dccf6700bbecb0222f13ffa4befe0c62
[blender.git] / intern / SoundSystem / intern / SND_C-api.cpp
1 /*
2  * SND_C-Api.cpp
3  *
4  * C Api for soundmodule
5  *
6  * $Id$
7  *
8  * ***** BEGIN GPL LICENSE BLOCK *****
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  *
24  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
25  * All rights reserved.
26  *
27  * The Original Code is: all of this file.
28  *
29  * Contributor(s): none yet.
30  *
31  * ***** END GPL LICENSE BLOCK *****
32  */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include "SND_C-api.h"
39 #include "SND_DeviceManager.h"
40 #include "SND_Scene.h"
41
42 #ifdef WIN32
43 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
44 #endif //WIN32
45
46
47
48 void SND_SetDeviceType(int device_type)
49 {
50         SND_DeviceManager::SetDeviceType(device_type);
51 }
52
53
54
55 SND_AudioDeviceInterfaceHandle SND_GetAudioDevice()
56 {
57         SND_IAudioDevice* audiodevice = NULL;
58
59         SND_DeviceManager::Subscribe();
60         audiodevice = SND_DeviceManager::Instance();
61
62         if (!audiodevice->IsInitialized())
63         {
64                 SND_DeviceManager::SetDeviceType(snd_e_dummydevice);
65                 audiodevice = SND_DeviceManager::Instance();
66         }
67
68         return (SND_AudioDeviceInterfaceHandle)audiodevice;
69 }
70
71
72
73 void SND_ReleaseDevice()
74 {
75         SND_DeviceManager::Unsubscribe();
76 }
77
78
79
80 int SND_IsPlaybackWanted(SND_SceneHandle scene)
81 {
82         assert(scene);
83         bool result = ((SND_Scene*)scene)->IsPlaybackWanted();
84
85         return (int)result;
86 }
87
88
89
90 // create a scene
91 SND_SceneHandle SND_CreateScene(SND_AudioDeviceInterfaceHandle audiodevice)
92 {
93         // initialize sound scene and object
94         SND_Scene* scene = new SND_Scene((SND_IAudioDevice*)audiodevice);
95
96         return (SND_SceneHandle)scene; 
97 }
98
99
100
101 void SND_DeleteScene(SND_SceneHandle scene)
102 {
103     assert(scene);
104     delete (SND_Scene*)scene;
105 }
106
107
108
109 int SND_AddSample(SND_SceneHandle scene,
110                                   const char* filename,
111                                   void* memlocation,
112                                   int size)
113 {
114         assert(scene);
115         assert(memlocation);
116         int buffer = ((SND_Scene*)scene)->LoadSample(filename, memlocation, size);
117         
118         return buffer;
119 }
120
121
122
123 void SND_RemoveAllSamples(SND_SceneHandle scene)
124 {
125         assert(scene);
126         ((SND_Scene*)scene)->RemoveAllSamples();
127 }
128
129
130
131 int SND_CheckBuffer(SND_SceneHandle scene, SND_ObjectHandle object)
132 {
133         assert(scene);
134         assert(object);
135         int result = (int)((SND_Scene*)scene)->CheckBuffer((SND_SoundObject*)object);
136
137         return result;
138 }
139
140
141
142 void SND_AddSound(SND_SceneHandle scene, SND_ObjectHandle object)
143 {
144     assert(scene);
145     assert(object);
146     ((SND_Scene*)scene)->AddObject((SND_SoundObject *)object);
147 }
148
149
150
151 void SND_RemoveSound(SND_SceneHandle scene, SND_ObjectHandle object)
152 {
153     assert(scene);
154     assert(object);
155     ((SND_Scene*)scene)->DeleteObject((SND_SoundObject *)object);
156 }
157
158
159
160 void SND_RemoveAllSounds(SND_SceneHandle scene)
161 {
162         assert(scene);
163     ((SND_Scene*)scene)->RemoveAllObjects();    
164 }
165
166
167
168 void SND_StopAllSounds(SND_SceneHandle scene)
169 {
170         assert(scene);
171         ((SND_Scene*)scene)->StopAllObjects();
172 }
173
174
175
176 void SND_Proceed(SND_AudioDeviceInterfaceHandle audiodevice, SND_SceneHandle scene)
177 {
178         assert(scene);
179         ((SND_Scene*)scene)->Proceed();
180         ((SND_IAudioDevice*)audiodevice)->NextFrame();
181 }
182
183
184
185 SND_ListenerHandle SND_GetListener(SND_SceneHandle scene)
186 {
187         assert(scene);
188         return (SND_ListenerHandle)((SND_Scene*)scene)->GetListener();
189 }
190
191
192
193 void SND_SetListenerGain(SND_SceneHandle scene, double gain)
194 {
195         assert(scene);
196         SND_SoundListener* listener = ((SND_Scene*)scene)->GetListener();
197         listener->SetGain((MT_Scalar)gain);
198 }
199
200
201
202 void SND_SetDopplerFactor(SND_SceneHandle scene, double dopplerfactor)
203 {
204         assert(scene);
205         SND_SoundListener* listener = ((SND_Scene*)scene)->GetListener();
206         listener->SetDopplerFactor(dopplerfactor);
207 }
208
209
210
211 void SND_SetDopplerVelocity(SND_SceneHandle scene, double dopplervelocity)
212 {
213         assert(scene);
214         SND_SoundListener* listener = ((SND_Scene*)scene)->GetListener();
215         listener->SetDopplerVelocity(dopplervelocity);
216 }
217
218
219
220 // Object instantiation
221 SND_ObjectHandle SND_CreateSound()
222 {
223         return (SND_ObjectHandle)new SND_SoundObject();
224 }
225
226
227
228 void SND_DeleteSound(SND_ObjectHandle object)
229 {
230         assert(object);
231     delete (SND_SoundObject*)object;
232 }
233
234
235
236 // Object control
237 void SND_StartSound(SND_SceneHandle scene, SND_ObjectHandle object)
238 {
239         assert(scene);
240         assert(object);
241         ((SND_Scene*)scene)->AddActiveObject((SND_SoundObject*)object, 0);
242 }
243
244
245
246 void SND_StopSound(SND_SceneHandle scene, SND_ObjectHandle object)
247 {
248         assert(scene);
249         assert(object);
250         ((SND_Scene*)scene)->RemoveActiveObject((SND_SoundObject*)object);
251 }
252
253
254
255 void SND_PauseSound(SND_SceneHandle scene, SND_ObjectHandle object)
256 {
257         assert(scene);
258         assert(object);
259         ((SND_Scene*)scene)->RemoveActiveObject((SND_SoundObject*)object);
260 }
261
262
263
264 void SND_SetSampleName(SND_ObjectHandle object, char* samplename)
265 {
266         assert(object);
267         STR_String name = samplename;
268         ((SND_SoundObject*)object)->SetSampleName(name);
269 }
270
271
272
273 void SND_SetGain(SND_ObjectHandle object, double gain)
274 {
275         assert(object);
276         ((SND_SoundObject*)object)->SetGain(gain);
277 }
278
279
280
281 void SND_SetMinimumGain(SND_ObjectHandle object, double minimumgain)
282 {
283         assert(object);
284         ((SND_SoundObject*)object)->SetMinGain(minimumgain);
285 }
286
287
288
289 void SND_SetMaximumGain(SND_ObjectHandle object, double maximumgain)
290 {
291         assert(object);
292         ((SND_SoundObject*)object)->SetMaxGain(maximumgain);
293 }
294
295
296
297 void SND_SetRollOffFactor(SND_ObjectHandle object, double rollofffactor)
298 {
299         assert(object);
300         ((SND_SoundObject*)object)->SetRollOffFactor(rollofffactor);
301 }
302
303
304
305 void SND_SetReferenceDistance(SND_ObjectHandle object, double referencedistance)
306 {
307         assert(object);
308         ((SND_SoundObject*)object)->SetReferenceDistance(referencedistance);
309 }
310
311
312
313 void SND_SetPitch(SND_ObjectHandle object, double pitch)
314 {
315         assert(object);
316         ((SND_SoundObject*)object)->SetPitch(pitch);
317 }
318
319
320
321 void SND_SetPosition(SND_ObjectHandle object, double* position) 
322 {
323         assert(object);
324         ((SND_SoundObject*)object)->SetPosition(position);
325 }
326
327
328
329 void SND_SetVelocity(SND_ObjectHandle object, double* velocity)
330 {
331         assert(object);
332         ((SND_SoundObject*)object)->SetVelocity(velocity);
333 }
334
335
336
337 void SND_SetOrientation(SND_ObjectHandle object, double* orientation)
338 {
339         assert(object);
340         ((SND_SoundObject*)object)->SetOrientation(orientation);
341 }
342
343
344
345 void SND_SetLoopMode(SND_ObjectHandle object, int loopmode)
346 {
347         assert(object);
348         ((SND_SoundObject*)object)->SetLoopMode(loopmode);
349 }
350
351
352
353 void SND_SetLoopPoints(SND_ObjectHandle object, unsigned int loopstart, unsigned int loopend)
354 {
355         assert(object);
356         ((SND_SoundObject*)object)->SetLoopStart(loopstart);
357         ((SND_SoundObject*)object)->SetLoopEnd(loopend);
358 }
359
360
361
362 float SND_GetGain(SND_ObjectHandle object)
363 {
364         assert(object);
365         MT_Scalar gain = ((SND_SoundObject*)object)->GetGain();
366         return (float) gain;
367 }
368
369
370
371 float SND_GetPitch(SND_ObjectHandle object) 
372 {
373         assert(object);
374         MT_Scalar pitch = ((SND_SoundObject*)object)->GetPitch();
375         return (float) pitch;
376 }
377
378
379
380 int SND_GetLoopMode(SND_ObjectHandle object) 
381 {
382         assert(object);
383         return ((SND_SoundObject*)object)->GetLoopMode();
384 }
385
386
387
388 int SND_GetPlaystate(SND_ObjectHandle object) 
389 {
390         assert(object);
391         return ((SND_SoundObject*)object)->GetPlaystate();
392 }