f2d92154c66762dce7152b5034fdbcc14fa01c7b
[blender.git] / source / blender / blenkernel / intern / sound.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/blenkernel/intern/sound.c
31  *  \ingroup bke
32  */
33
34 #include <string.h>
35 #include <stdlib.h>
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_blenlib.h"
40 #include "BLI_math.h"
41
42 #include "DNA_anim_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_sequence_types.h"
46 #include "DNA_packedFile_types.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_sound_types.h"
49 #include "DNA_speaker_types.h"
50
51 #ifdef WITH_AUDASPACE
52 #  include "AUD_C-API.h"
53 #endif
54
55 #include "BKE_utildefines.h"
56 #include "BKE_global.h"
57 #include "BKE_main.h"
58 #include "BKE_sound.h"
59 #include "BKE_context.h"
60 #include "BKE_library.h"
61 #include "BKE_packedFile.h"
62 #include "BKE_animsys.h"
63 #include "BKE_sequencer.h"
64 #include "BKE_scene.h"
65
66 #ifdef WITH_AUDASPACE
67 // evil global ;-)
68 static int sound_cfra;
69 #endif
70
71 struct bSound* sound_new_file(struct Main *bmain, const char *filename)
72 {
73         bSound* sound = NULL;
74
75         char str[FILE_MAX];
76         char *path;
77
78         int len;
79
80         strcpy(str, filename);
81
82         path = /*bmain ? bmain->name :*/ G.main->name;
83
84         BLI_path_abs(str, path);
85
86         len = strlen(filename);
87         while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\')
88                 len--;
89
90         sound = alloc_libblock(&bmain->sound, ID_SO, filename+len);
91         BLI_strncpy(sound->name, filename, FILE_MAX);
92 // XXX unused currently sound->type = SOUND_TYPE_FILE;
93
94         sound_load(bmain, sound);
95
96         if(!sound->playback_handle)
97         {
98                 free_libblock(&bmain->sound, sound);
99                 sound = NULL;
100         }
101
102         return sound;
103 }
104
105 void sound_free(struct bSound* sound)
106 {
107         if (sound->packedfile)
108         {
109                 freePackedFile(sound->packedfile);
110                 sound->packedfile = NULL;
111         }
112
113 #ifdef WITH_AUDASPACE
114         if(sound->handle)
115         {
116                 AUD_unload(sound->handle);
117                 sound->handle = NULL;
118                 sound->playback_handle = NULL;
119         }
120
121         if(sound->cache)
122         {
123                 AUD_unload(sound->cache);
124                 sound->cache = NULL;
125         }
126
127         sound_free_waveform(sound);
128 #endif // WITH_AUDASPACE
129 }
130
131 #ifdef WITH_AUDASPACE
132
133 static int force_device = -1;
134
135 #ifdef WITH_JACK
136 static void sound_sync_callback(void* data, int mode, float time)
137 {
138         struct Main* bmain = (struct Main*)data;
139         struct Scene* scene;
140
141         scene = bmain->scene.first;
142         while(scene)
143         {
144                 if(scene->audio.flag & AUDIO_SYNC)
145                 {
146                         if(mode)
147                                 sound_play_scene(scene);
148                         else
149                                 sound_stop_scene(scene);
150                         if(scene->sound_scene_handle)
151                                 AUD_seek(scene->sound_scene_handle, time);
152                 }
153                 scene = scene->id.next;
154         }
155 }
156 #endif
157
158 int sound_define_from_str(const char *str)
159 {
160         if (BLI_strcaseeq(str, "NULL"))
161                 return AUD_NULL_DEVICE;
162         if (BLI_strcaseeq(str, "SDL"))
163                 return AUD_SDL_DEVICE;
164         if (BLI_strcaseeq(str, "OPENAL"))
165                 return AUD_OPENAL_DEVICE;
166         if (BLI_strcaseeq(str, "JACK"))
167                 return AUD_JACK_DEVICE;
168
169         return -1;
170 }
171
172 void sound_force_device(int device)
173 {
174         force_device = device;
175 }
176
177 void sound_init_once(void)
178 {
179         AUD_initOnce();
180 }
181
182 void sound_init(struct Main *bmain)
183 {
184         AUD_DeviceSpecs specs;
185         int device, buffersize;
186
187         device = U.audiodevice;
188         buffersize = U.mixbufsize;
189         specs.channels = U.audiochannels;
190         specs.format = U.audioformat;
191         specs.rate = U.audiorate;
192
193         if(force_device >= 0)
194                 device = force_device;
195
196         if(buffersize < 128)
197                 buffersize = AUD_DEFAULT_BUFFER_SIZE;
198
199         if(specs.rate < AUD_RATE_8000)
200                 specs.rate = AUD_RATE_44100;
201
202         if(specs.format <= AUD_FORMAT_INVALID)
203                 specs.format = AUD_FORMAT_S16;
204
205         if(specs.channels <= AUD_CHANNELS_INVALID)
206                 specs.channels = AUD_CHANNELS_STEREO;
207
208         if(!AUD_init(device, specs, buffersize))
209                 AUD_init(AUD_NULL_DEVICE, specs, buffersize);
210
211         sound_init_main(bmain);
212 }
213
214 void sound_init_main(struct Main *bmain)
215 {
216 #ifdef WITH_JACK
217         AUD_setSyncCallback(sound_sync_callback, bmain);
218 #else
219         (void)bmain; /* unused */
220 #endif
221 }
222
223 void sound_exit(void)
224 {
225         AUD_exit();
226 }
227
228 // XXX unused currently
229 #if 0
230 struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source)
231 {
232         bSound* sound = NULL;
233
234         char name[25];
235         strcpy(name, "buf_");
236         strcpy(name + 4, source->id.name);
237
238         sound = alloc_libblock(&bmain->sound, ID_SO, name);
239
240         sound->child_sound = source;
241         sound->type = SOUND_TYPE_BUFFER;
242
243         sound_load(bmain, sound);
244
245         if(!sound->playback_handle)
246         {
247                 free_libblock(&bmain->sound, sound);
248                 sound = NULL;
249         }
250
251         return sound;
252 }
253
254 struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end)
255 {
256         bSound* sound = NULL;
257
258         char name[25];
259         strcpy(name, "lim_");
260         strcpy(name + 4, source->id.name);
261
262         sound = alloc_libblock(&bmain->sound, ID_SO, name);
263
264         sound->child_sound = source;
265         sound->start = start;
266         sound->end = end;
267         sound->type = SOUND_TYPE_LIMITER;
268
269         sound_load(bmain, sound);
270
271         if(!sound->playback_handle)
272         {
273                 free_libblock(&bmain->sound, sound);
274                 sound = NULL;
275         }
276
277         return sound;
278 }
279 #endif
280
281 void sound_delete(struct Main *bmain, struct bSound* sound)
282 {
283         if(sound)
284         {
285                 sound_free(sound);
286
287                 free_libblock(&bmain->sound, sound);
288         }
289 }
290
291 void sound_cache(struct bSound* sound)
292 {
293         sound->flags |= SOUND_FLAGS_CACHING;
294         if(sound->cache)
295                 AUD_unload(sound->cache);
296
297         sound->cache = AUD_bufferSound(sound->handle);
298         sound->playback_handle = sound->cache;
299 }
300
301 void sound_cache_notifying(struct Main* main, struct bSound* sound)
302 {
303         sound_cache(sound);
304         sound_update_sequencer(main, sound);
305 }
306
307 void sound_delete_cache(struct bSound* sound)
308 {
309         sound->flags &= ~SOUND_FLAGS_CACHING;
310         if(sound->cache)
311         {
312                 AUD_unload(sound->cache);
313                 sound->cache = NULL;
314                 sound->playback_handle = sound->handle;
315         }
316 }
317
318 void sound_load(struct Main *bmain, struct bSound* sound)
319 {
320         if(sound)
321         {
322                 if(sound->cache)
323                 {
324                         AUD_unload(sound->cache);
325                         sound->cache = NULL;
326                 }
327
328                 if(sound->handle)
329                 {
330                         AUD_unload(sound->handle);
331                         sound->handle = NULL;
332                         sound->playback_handle = NULL;
333                 }
334
335 // XXX unused currently
336 #if 0
337                 switch(sound->type)
338                 {
339                 case SOUND_TYPE_FILE:
340 #endif
341                 {
342                         char fullpath[FILE_MAX];
343
344                         /* load sound */
345                         PackedFile* pf = sound->packedfile;
346
347                         /* dont modify soundact->sound->name, only change a copy */
348                         BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
349                         BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id));
350
351                         /* but we need a packed file then */
352                         if (pf)
353                                 sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
354                         /* or else load it from disk */
355                         else
356                                 sound->handle = AUD_load(fullpath);
357                 }
358 // XXX unused currently
359 #if 0
360                         break;
361                 }
362                 case SOUND_TYPE_BUFFER:
363                         if(sound->child_sound && sound->child_sound->handle)
364                                 sound->handle = AUD_bufferSound(sound->child_sound->handle);
365                         break;
366                 case SOUND_TYPE_LIMITER:
367                         if(sound->child_sound && sound->child_sound->handle)
368                                 sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
369                         break;
370                 }
371 #endif
372                 if(sound->flags & SOUND_FLAGS_MONO)
373                 {
374                         void* handle = AUD_monoSound(sound->handle);
375                         AUD_unload(sound->handle);
376                         sound->handle = handle;
377                 }
378
379                 if(sound->flags & SOUND_FLAGS_CACHING)
380                 {
381                         sound->cache = AUD_bufferSound(sound->handle);
382                 }
383
384                 if(sound->cache)
385                         sound->playback_handle = sound->cache;
386                 else
387                         sound->playback_handle = sound->handle;
388
389                 sound_update_sequencer(bmain, sound);
390         }
391 }
392
393 AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume)
394 {
395         return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS);
396 }
397
398 void sound_create_scene(struct Scene *scene)
399 {
400         scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE);
401         AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound,
402                                                         scene->audio.doppler_factor, scene->audio.distance_model);
403         scene->sound_scene_handle = NULL;
404         scene->sound_scrub_handle = NULL;
405         scene->speaker_handles = NULL;
406 }
407
408 void sound_destroy_scene(struct Scene *scene)
409 {
410         if(scene->sound_scene_handle)
411                 AUD_stop(scene->sound_scene_handle);
412         if(scene->sound_scrub_handle)
413                 AUD_stop(scene->sound_scrub_handle);
414         if(scene->sound_scene)
415                 AUD_destroySequencer(scene->sound_scene);
416         if(scene->speaker_handles)
417                 AUD_destroySet(scene->speaker_handles);
418 }
419
420 void sound_mute_scene(struct Scene *scene, int muted)
421 {
422         if(scene->sound_scene)
423                 AUD_setSequencerMuted(scene->sound_scene, muted);
424 }
425
426 void sound_update_fps(struct Scene *scene)
427 {
428         if(scene->sound_scene)
429                 AUD_setSequencerFPS(scene->sound_scene, FPS);
430 }
431
432 void sound_update_scene_listener(struct Scene *scene)
433 {
434         AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound,
435                                                         scene->audio.doppler_factor, scene->audio.distance_model);
436 }
437
438 void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
439 {
440         if(scene != sequence->scene)
441                 return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, startframe / FPS, endframe / FPS, frameskip / FPS);
442         return NULL;
443 }
444
445 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
446 {
447         void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS);
448         AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0);
449         AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0);
450         AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0);
451         AUD_setSequenceAnimData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0);
452         return handle;
453 }
454
455 void sound_remove_scene_sound(struct Scene *scene, void* handle)
456 {
457         AUD_removeSequence(scene->sound_scene, handle);
458 }
459
460 void sound_mute_scene_sound(void* handle, char mute)
461 {
462         AUD_muteSequence(handle, mute);
463 }
464
465 void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip)
466 {
467         AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS);
468 }
469
470 void sound_update_scene_sound(void* handle, struct bSound* sound)
471 {
472         AUD_updateSequenceSound(handle, sound->playback_handle);
473 }
474
475 void sound_set_cfra(int cfra)
476 {
477         sound_cfra = cfra;
478 }
479
480 void sound_set_scene_volume(struct Scene *scene, float volume)
481 {
482         AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0);
483 }
484
485 void sound_set_scene_sound_volume(void* handle, float volume, char animated)
486 {
487         AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
488 }
489
490 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated)
491 {
492         AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
493 }
494
495 void sound_set_scene_sound_pan(void* handle, float pan, char animated)
496 {
497         AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
498 }
499
500 void sound_update_sequencer(struct Main* main, struct bSound* sound)
501 {
502         struct Scene* scene;
503
504         for(scene = main->scene.first; scene; scene = scene->id.next)
505                 seq_update_sound(scene, sound);
506 }
507
508 static void sound_start_play_scene(struct Scene *scene)
509 {
510         if(scene->sound_scene_handle)
511                 AUD_stop(scene->sound_scene_handle);
512
513         AUD_setSequencerDeviceSpecs(scene->sound_scene);
514
515         if((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1)))
516                 AUD_setLoop(scene->sound_scene_handle, -1);
517 }
518
519 void sound_play_scene(struct Scene *scene)
520 {
521         AUD_Status status;
522         AUD_lock();
523
524         status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
525
526         if(status == AUD_STATUS_INVALID)
527                 sound_start_play_scene(scene);
528
529         if(!scene->sound_scene_handle)
530         {
531                 AUD_unlock();
532                 return;
533         }
534
535         if(status != AUD_STATUS_PLAYING)
536         {
537                 AUD_seek(scene->sound_scene_handle, CFRA / FPS);
538                 AUD_resume(scene->sound_scene_handle);
539         }
540
541         if(scene->audio.flag & AUDIO_SYNC)
542                 AUD_startPlayback();
543
544         AUD_unlock();
545 }
546
547 void sound_stop_scene(struct Scene *scene)
548 {
549         if(scene->sound_scene_handle)
550         {
551                 AUD_pause(scene->sound_scene_handle);
552
553                 if(scene->audio.flag & AUDIO_SYNC)
554                         AUD_stopPlayback();
555         }
556 }
557
558 void sound_seek_scene(struct Main *bmain, struct Scene *scene)
559 {
560         AUD_Status status;
561         bScreen *screen;
562         int animation_playing;
563
564         AUD_lock();
565
566         status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
567
568         if(status == AUD_STATUS_INVALID)
569         {
570                 sound_start_play_scene(scene);
571
572                 if(!scene->sound_scene_handle)
573                 {
574                         AUD_unlock();
575                         return;
576                 }
577
578                 AUD_pause(scene->sound_scene_handle);
579         }
580
581         animation_playing = 0;
582         for(screen=bmain->screen.first; screen; screen=screen->id.next)
583                 if(screen->animtimer)
584                         animation_playing = 1;
585
586         if(scene->audio.flag & AUDIO_SCRUB && !animation_playing)
587         {
588                 if(scene->audio.flag & AUDIO_SYNC)
589                 {
590                         AUD_seek(scene->sound_scene_handle, CFRA / FPS);
591                         AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
592                 }
593                 else
594                         AUD_seek(scene->sound_scene_handle, CFRA / FPS);
595                 AUD_resume(scene->sound_scene_handle);
596                 if(scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID)
597                         AUD_seek(scene->sound_scrub_handle, 0);
598                 else
599                 {
600                         if(scene->sound_scrub_handle)
601                                 AUD_stop(scene->sound_scrub_handle);
602                         scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS);
603                 }
604         }
605         else
606         {
607                 if(scene->audio.flag & AUDIO_SYNC)
608                         AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
609                 else
610                 {
611                         if(status == AUD_STATUS_PLAYING)
612                                 AUD_seek(scene->sound_scene_handle, CFRA / FPS);
613                 }
614         }
615
616         AUD_unlock();
617 }
618
619 float sound_sync_scene(struct Scene *scene)
620 {
621         if(scene->sound_scene_handle)
622         {
623                 if(scene->audio.flag & AUDIO_SYNC)
624                         return AUD_getSequencerPosition(scene->sound_scene_handle);
625                 else
626                         return AUD_getPosition(scene->sound_scene_handle);
627         }
628         return 0.0f;
629 }
630
631 int sound_scene_playing(struct Scene *scene)
632 {
633         if(scene->audio.flag & AUDIO_SYNC)
634                 return AUD_doesPlayback();
635         else
636                 return -1;
637 }
638
639 void sound_free_waveform(struct bSound* sound)
640 {
641         if(sound->waveform)
642         {
643                 MEM_freeN(((SoundWaveform*)sound->waveform)->data);
644                 MEM_freeN(sound->waveform);
645         }
646
647         sound->waveform = NULL;
648 }
649
650 void sound_read_waveform(struct bSound* sound)
651 {
652         AUD_SoundInfo info;
653
654         info = AUD_getInfo(sound->playback_handle);
655
656         if(info.length > 0)
657         {
658                 SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform");
659                 int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
660
661                 waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples");
662                 waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND);
663
664                 sound_free_waveform(sound);
665                 sound->waveform = waveform;
666         }
667 }
668
669 void sound_update_scene(struct Scene* scene)
670 {
671         Object* ob;
672         Base* base;
673         NlaTrack* track;
674         NlaStrip* strip;
675         Speaker* speaker;
676         Scene* sce_it;
677
678         void* new_set = AUD_createSet();
679         void* handle;
680         float quat[4];
681
682         for(SETLOOPER(scene, sce_it, base))
683         {
684                 ob = base->object;
685                 if(ob->type == OB_SPEAKER)
686                 {
687                         if(ob->adt)
688                         {
689                                 for(track = ob->adt->nla_tracks.first; track; track = track->next)
690                                 {
691                                         for(strip = track->strips.first; strip; strip = strip->next)
692                                         {
693                                                 if(strip->type == NLASTRIP_TYPE_SOUND)
694                                                 {
695                                                         speaker = (Speaker*)ob->data;
696
697                                                         if(AUD_removeSet(scene->speaker_handles, strip->speaker_handle))
698                                                         {
699                                                                 if(speaker->sound)
700                                                                         AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0);
701                                                                 else
702                                                                 {
703                                                                         AUD_removeSequence(scene->sound_scene, strip->speaker_handle);
704                                                                         strip->speaker_handle = NULL;
705                                                                 }
706                                                         }
707                                                         else
708                                                         {
709                                                                 if(speaker->sound)
710                                                                 {
711                                                                         strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0);
712                                                                         AUD_setRelativeSequence(strip->speaker_handle, 0);
713                                                                 }
714                                                         }
715
716                                                         if(strip->speaker_handle)
717                                                         {
718                                                                 AUD_addSet(new_set, strip->speaker_handle);
719                                                                 AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max,
720                                                                                                            speaker->volume_min, speaker->distance_max,
721                                                                                                            speaker->distance_reference, speaker->attenuation,
722                                                                                                            speaker->cone_angle_outer, speaker->cone_angle_inner,
723                                                                                                            speaker->cone_volume_outer);
724
725                                                                 mat4_to_quat(quat, ob->obmat);
726                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
727                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
728                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1);
729                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1);
730                                                                 AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle);
731                                                                 AUD_muteSequence(strip->speaker_handle, ((strip->flag & NLASTRIP_FLAG_MUTED) != 0) || ((speaker->flag & SPK_MUTED) != 0));
732                                                         }
733                                                 }
734                                         }
735                                 }
736                         }
737                 }
738         }
739
740         while((handle = AUD_getSet(scene->speaker_handles)))
741         {
742                 AUD_removeSequence(scene->sound_scene, handle);
743         }
744
745         if(scene->camera)
746         {
747                 mat4_to_quat(quat, scene->camera->obmat);
748                 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1);
749                 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1);
750         }
751
752         AUD_destroySet(scene->speaker_handles);
753         scene->speaker_handles = new_set;
754 }
755
756 void* sound_get_factory(void* sound)
757 {
758         return ((struct bSound*) sound)->playback_handle;
759 }
760
761 #else // WITH_AUDASPACE
762
763 #include "BLI_utildefines.h"
764
765 int sound_define_from_str(const char *UNUSED(str)) { return -1;}
766 void sound_force_device(int UNUSED(device)) {}
767 void sound_init_once(void) {}
768 void sound_init(struct Main *UNUSED(bmain)) {}
769 void sound_exit(void) {}
770 void sound_cache(struct bSound* UNUSED(sound)) { }
771 void sound_delete_cache(struct bSound* UNUSED(sound)) {}
772 void sound_load(struct Main *UNUSED(bmain), struct bSound* UNUSED(sound)) {}
773 void sound_create_scene(struct Scene *UNUSED(scene)) {}
774 void sound_destroy_scene(struct Scene *UNUSED(scene)) {}
775 void sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {}
776 void* sound_scene_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; }
777 void* sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; }
778 void sound_remove_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle)) {}
779 void sound_mute_scene_sound(void* UNUSED(handle), char UNUSED(mute)) {}
780 void sound_move_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) {}
781 static void sound_start_play_scene(struct Scene *UNUSED(scene)) {}
782 void sound_play_scene(struct Scene *UNUSED(scene)) {}
783 void sound_stop_scene(struct Scene *UNUSED(scene)) {}
784 void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {}
785 float sound_sync_scene(struct Scene *UNUSED(scene)) { return 0.0f; }
786 int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
787 int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; }
788 void sound_read_waveform(struct bSound* sound) { (void)sound; }
789 void sound_init_main(struct Main *bmain) { (void)bmain; }
790 void sound_set_cfra(int cfra) { (void)cfra; }
791 void sound_update_sequencer(struct Main* main, struct bSound* sound) { (void)main; (void)sound; }
792 void sound_update_scene(struct Scene* scene) { (void)scene; }
793 void sound_update_scene_sound(void* handle, struct bSound* sound) { (void)handle; (void)sound; }
794 void sound_update_scene_listener(struct Scene *scene) { (void)scene; }
795 void sound_update_fps(struct Scene *scene) { (void)scene; }
796 void sound_set_scene_sound_volume(void* handle, float volume, char animated) { (void)handle; (void)volume; (void)animated; }
797 void sound_set_scene_sound_pan(void* handle, float pan, char animated) { (void)handle; (void)pan; (void)animated; }
798 void sound_set_scene_volume(struct Scene *scene, float volume) { (void)scene; (void)volume; }
799 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) { (void)handle; (void)pitch; (void)animated; }
800
801 #endif // WITH_AUDASPACE