Reverting my windows build fix because it breaks the bug fix committed in r40995
[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         if(sound->cache)
299                 sound->playback_handle = sound->cache;
300         else
301                 sound->playback_handle = sound->handle;
302 }
303
304 void sound_cache_notifying(struct Main* main, struct bSound* sound)
305 {
306         sound_cache(sound);
307         sound_update_sequencer(main, sound);
308 }
309
310 void sound_delete_cache(struct bSound* sound)
311 {
312         sound->flags &= ~SOUND_FLAGS_CACHING;
313         if(sound->cache)
314         {
315                 AUD_unload(sound->cache);
316                 sound->cache = NULL;
317                 sound->playback_handle = sound->handle;
318         }
319 }
320
321 void sound_load(struct Main *bmain, struct bSound* sound)
322 {
323         if(sound)
324         {
325                 if(sound->cache)
326                 {
327                         AUD_unload(sound->cache);
328                         sound->cache = NULL;
329                 }
330
331                 if(sound->handle)
332                 {
333                         AUD_unload(sound->handle);
334                         sound->handle = NULL;
335                         sound->playback_handle = NULL;
336                 }
337
338                 sound_free_waveform(sound);
339
340 // XXX unused currently
341 #if 0
342                 switch(sound->type)
343                 {
344                 case SOUND_TYPE_FILE:
345 #endif
346                 {
347                         char fullpath[FILE_MAX];
348
349                         /* load sound */
350                         PackedFile* pf = sound->packedfile;
351
352                         /* dont modify soundact->sound->name, only change a copy */
353                         BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
354                         BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id));
355
356                         /* but we need a packed file then */
357                         if (pf)
358                                 sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
359                         /* or else load it from disk */
360                         else
361                                 sound->handle = AUD_load(fullpath);
362                 }
363 // XXX unused currently
364 #if 0
365                         break;
366                 }
367                 case SOUND_TYPE_BUFFER:
368                         if(sound->child_sound && sound->child_sound->handle)
369                                 sound->handle = AUD_bufferSound(sound->child_sound->handle);
370                         break;
371                 case SOUND_TYPE_LIMITER:
372                         if(sound->child_sound && sound->child_sound->handle)
373                                 sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
374                         break;
375                 }
376 #endif
377                 if(sound->flags & SOUND_FLAGS_MONO)
378                 {
379                         void* handle = AUD_monoSound(sound->handle);
380                         AUD_unload(sound->handle);
381                         sound->handle = handle;
382                 }
383
384                 if(sound->flags & SOUND_FLAGS_CACHING)
385                 {
386                         sound->cache = AUD_bufferSound(sound->handle);
387                 }
388
389                 if(sound->cache)
390                         sound->playback_handle = sound->cache;
391                 else
392                         sound->playback_handle = sound->handle;
393
394                 sound_update_sequencer(bmain, sound);
395         }
396 }
397
398 AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume)
399 {
400         return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS);
401 }
402
403 void sound_create_scene(struct Scene *scene)
404 {
405         scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE);
406         AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound,
407                                                         scene->audio.doppler_factor, scene->audio.distance_model);
408         scene->sound_scene_handle = NULL;
409         scene->sound_scrub_handle = NULL;
410         scene->speaker_handles = NULL;
411 }
412
413 void sound_destroy_scene(struct Scene *scene)
414 {
415         if(scene->sound_scene_handle)
416                 AUD_stop(scene->sound_scene_handle);
417         if(scene->sound_scrub_handle)
418                 AUD_stop(scene->sound_scrub_handle);
419         if(scene->sound_scene)
420                 AUD_destroySequencer(scene->sound_scene);
421         if(scene->speaker_handles)
422                 AUD_destroySet(scene->speaker_handles);
423 }
424
425 void sound_mute_scene(struct Scene *scene, int muted)
426 {
427         if(scene->sound_scene)
428                 AUD_setSequencerMuted(scene->sound_scene, muted);
429 }
430
431 void sound_update_fps(struct Scene *scene)
432 {
433         if(scene->sound_scene)
434                 AUD_setSequencerFPS(scene->sound_scene, FPS);
435 }
436
437 void sound_update_scene_listener(struct Scene *scene)
438 {
439         AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound,
440                                                         scene->audio.doppler_factor, scene->audio.distance_model);
441 }
442
443 void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
444 {
445         if(scene != sequence->scene)
446                 return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, startframe / FPS, endframe / FPS, frameskip / FPS);
447         return NULL;
448 }
449
450 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
451 {
452         void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS);
453         AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0);
454         AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0);
455         AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0);
456         AUD_setSequenceAnimData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0);
457         return handle;
458 }
459
460 void sound_remove_scene_sound(struct Scene *scene, void* handle)
461 {
462         AUD_removeSequence(scene->sound_scene, handle);
463 }
464
465 void sound_mute_scene_sound(void* handle, char mute)
466 {
467         AUD_muteSequence(handle, mute);
468 }
469
470 void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip)
471 {
472         AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS);
473 }
474
475 void sound_update_scene_sound(void* handle, struct bSound* sound)
476 {
477         AUD_updateSequenceSound(handle, sound->playback_handle);
478 }
479
480 void sound_set_cfra(int cfra)
481 {
482         sound_cfra = cfra;
483 }
484
485 void sound_set_scene_volume(struct Scene *scene, float volume)
486 {
487         AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0);
488 }
489
490 void sound_set_scene_sound_volume(void* handle, float volume, char animated)
491 {
492         AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
493 }
494
495 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated)
496 {
497         AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
498 }
499
500 void sound_set_scene_sound_pan(void* handle, float pan, char animated)
501 {
502         AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
503 }
504
505 void sound_update_sequencer(struct Main* main, struct bSound* sound)
506 {
507         struct Scene* scene;
508
509         for(scene = main->scene.first; scene; scene = scene->id.next)
510                 seq_update_sound(scene, sound);
511 }
512
513 static void sound_start_play_scene(struct Scene *scene)
514 {
515         if(scene->sound_scene_handle)
516                 AUD_stop(scene->sound_scene_handle);
517
518         AUD_setSequencerDeviceSpecs(scene->sound_scene);
519
520         if((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1)))
521                 AUD_setLoop(scene->sound_scene_handle, -1);
522 }
523
524 void sound_play_scene(struct Scene *scene)
525 {
526         AUD_Status status;
527         AUD_lock();
528
529         status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
530
531         if(status == AUD_STATUS_INVALID)
532                 sound_start_play_scene(scene);
533
534         if(!scene->sound_scene_handle)
535         {
536                 AUD_unlock();
537                 return;
538         }
539
540         if(status != AUD_STATUS_PLAYING)
541         {
542                 AUD_seek(scene->sound_scene_handle, CFRA / FPS);
543                 AUD_resume(scene->sound_scene_handle);
544         }
545
546         if(scene->audio.flag & AUDIO_SYNC)
547                 AUD_startPlayback();
548
549         AUD_unlock();
550 }
551
552 void sound_stop_scene(struct Scene *scene)
553 {
554         if(scene->sound_scene_handle)
555         {
556                 AUD_pause(scene->sound_scene_handle);
557
558                 if(scene->audio.flag & AUDIO_SYNC)
559                         AUD_stopPlayback();
560         }
561 }
562
563 void sound_seek_scene(struct Main *bmain, struct Scene *scene)
564 {
565         AUD_Status status;
566         bScreen *screen;
567         int animation_playing;
568
569         AUD_lock();
570
571         status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
572
573         if(status == AUD_STATUS_INVALID)
574         {
575                 sound_start_play_scene(scene);
576
577                 if(!scene->sound_scene_handle)
578                 {
579                         AUD_unlock();
580                         return;
581                 }
582
583                 AUD_pause(scene->sound_scene_handle);
584         }
585
586         animation_playing = 0;
587         for(screen=bmain->screen.first; screen; screen=screen->id.next)
588                 if(screen->animtimer)
589                         animation_playing = 1;
590
591         if(scene->audio.flag & AUDIO_SCRUB && !animation_playing)
592         {
593                 if(scene->audio.flag & AUDIO_SYNC)
594                 {
595                         AUD_seek(scene->sound_scene_handle, CFRA / FPS);
596                         AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
597                 }
598                 else
599                         AUD_seek(scene->sound_scene_handle, CFRA / FPS);
600                 AUD_resume(scene->sound_scene_handle);
601                 if(scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID)
602                         AUD_seek(scene->sound_scrub_handle, 0);
603                 else
604                 {
605                         if(scene->sound_scrub_handle)
606                                 AUD_stop(scene->sound_scrub_handle);
607                         scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS);
608                 }
609         }
610         else
611         {
612                 if(scene->audio.flag & AUDIO_SYNC)
613                         AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
614                 else
615                 {
616                         if(status == AUD_STATUS_PLAYING)
617                                 AUD_seek(scene->sound_scene_handle, CFRA / FPS);
618                 }
619         }
620
621         AUD_unlock();
622 }
623
624 float sound_sync_scene(struct Scene *scene)
625 {
626         if(scene->sound_scene_handle)
627         {
628                 if(scene->audio.flag & AUDIO_SYNC)
629                         return AUD_getSequencerPosition(scene->sound_scene_handle);
630                 else
631                         return AUD_getPosition(scene->sound_scene_handle);
632         }
633         return .0f/.0f;
634 }
635
636 int sound_scene_playing(struct Scene *scene)
637 {
638         if(scene->audio.flag & AUDIO_SYNC)
639                 return AUD_doesPlayback();
640         else
641                 return -1;
642 }
643
644 void sound_free_waveform(struct bSound* sound)
645 {
646         if(sound->waveform)
647         {
648                 MEM_freeN(((SoundWaveform*)sound->waveform)->data);
649                 MEM_freeN(sound->waveform);
650         }
651
652         sound->waveform = NULL;
653 }
654
655 void sound_read_waveform(struct bSound* sound)
656 {
657         AUD_SoundInfo info;
658
659         info = AUD_getInfo(sound->playback_handle);
660
661         if(info.length > 0)
662         {
663                 SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform");
664                 int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
665
666                 waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples");
667                 waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND);
668
669                 sound_free_waveform(sound);
670                 sound->waveform = waveform;
671         }
672 }
673
674 void sound_update_scene(struct Scene* scene)
675 {
676         Object* ob;
677         Base* base;
678         NlaTrack* track;
679         NlaStrip* strip;
680         Speaker* speaker;
681         Scene* sce_it;
682
683         void* new_set = AUD_createSet();
684         void* handle;
685         float quat[4];
686
687         for(SETLOOPER(scene, sce_it, base))
688         {
689                 ob = base->object;
690                 if(ob->type == OB_SPEAKER)
691                 {
692                         if(ob->adt)
693                         {
694                                 for(track = ob->adt->nla_tracks.first; track; track = track->next)
695                                 {
696                                         for(strip = track->strips.first; strip; strip = strip->next)
697                                         {
698                                                 if(strip->type == NLASTRIP_TYPE_SOUND)
699                                                 {
700                                                         speaker = (Speaker*)ob->data;
701
702                                                         if(AUD_removeSet(scene->speaker_handles, strip->speaker_handle))
703                                                         {
704                                                                 if(speaker->sound)
705                                                                         AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0);
706                                                                 else
707                                                                 {
708                                                                         AUD_removeSequence(scene->sound_scene, strip->speaker_handle);
709                                                                         strip->speaker_handle = NULL;
710                                                                 }
711                                                         }
712                                                         else
713                                                         {
714                                                                 if(speaker->sound)
715                                                                 {
716                                                                         strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0);
717                                                                         AUD_setRelativeSequence(strip->speaker_handle, 0);
718                                                                 }
719                                                         }
720
721                                                         if(strip->speaker_handle)
722                                                         {
723                                                                 AUD_addSet(new_set, strip->speaker_handle);
724                                                                 AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max,
725                                                                                                            speaker->volume_min, speaker->distance_max,
726                                                                                                            speaker->distance_reference, speaker->attenuation,
727                                                                                                            speaker->cone_angle_outer, speaker->cone_angle_inner,
728                                                                                                            speaker->cone_volume_outer);
729
730                                                                 mat4_to_quat(quat, ob->obmat);
731                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
732                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
733                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1);
734                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1);
735                                                                 AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle);
736                                                                 AUD_muteSequence(strip->speaker_handle, ((strip->flag & NLASTRIP_FLAG_MUTED) != 0) || ((speaker->flag & SPK_MUTED) != 0));
737                                                         }
738                                                 }
739                                         }
740                                 }
741                         }
742                 }
743         }
744
745         while((handle = AUD_getSet(scene->speaker_handles)))
746         {
747                 AUD_removeSequence(scene->sound_scene, handle);
748         }
749
750         if(scene->camera)
751         {
752                 mat4_to_quat(quat, scene->camera->obmat);
753                 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1);
754                 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1);
755         }
756
757         AUD_destroySet(scene->speaker_handles);
758         scene->speaker_handles = new_set;
759 }
760
761 void* sound_get_factory(void* sound)
762 {
763         return ((struct bSound*) sound)->playback_handle;
764 }
765
766 #else // WITH_AUDASPACE
767
768 #include "BLI_utildefines.h"
769
770 int sound_define_from_str(const char *UNUSED(str)) { return -1;}
771 void sound_force_device(int UNUSED(device)) {}
772 void sound_init_once(void) {}
773 void sound_init(struct Main *UNUSED(bmain)) {}
774 void sound_exit(void) {}
775 void sound_cache(struct bSound* UNUSED(sound)) { }
776 void sound_delete_cache(struct bSound* UNUSED(sound)) {}
777 void sound_load(struct Main *UNUSED(bmain), struct bSound* UNUSED(sound)) {}
778 void sound_create_scene(struct Scene *UNUSED(scene)) {}
779 void sound_destroy_scene(struct Scene *UNUSED(scene)) {}
780 void sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {}
781 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; }
782 void* sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; }
783 void sound_remove_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle)) {}
784 void sound_mute_scene_sound(void* UNUSED(handle), char UNUSED(mute)) {}
785 void sound_move_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) {}
786 static void sound_start_play_scene(struct Scene *UNUSED(scene)) {}
787 void sound_play_scene(struct Scene *UNUSED(scene)) {}
788 void sound_stop_scene(struct Scene *UNUSED(scene)) {}
789 void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {}
790 float sound_sync_scene(struct Scene *UNUSED(scene)) { return .0f/.0f; }
791 int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
792 int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; }
793 void sound_read_waveform(struct bSound* sound) { (void)sound; }
794 void sound_init_main(struct Main *bmain) { (void)bmain; }
795 void sound_set_cfra(int cfra) { (void)cfra; }
796 void sound_update_sequencer(struct Main* main, struct bSound* sound) { (void)main; (void)sound; }
797 void sound_update_scene(struct Scene* scene) { (void)scene; }
798 void sound_update_scene_sound(void* handle, struct bSound* sound) { (void)handle; (void)sound; }
799 void sound_update_scene_listener(struct Scene *scene) { (void)scene; }
800 void sound_update_fps(struct Scene *scene) { (void)scene; }
801 void sound_set_scene_sound_volume(void* handle, float volume, char animated) { (void)handle; (void)volume; (void)animated; }
802 void sound_set_scene_sound_pan(void* handle, float pan, char animated) { (void)handle; (void)pan; (void)animated; }
803 void sound_set_scene_volume(struct Scene *scene, float volume) { (void)scene; (void)volume; }
804 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) { (void)handle; (void)pitch; (void)animated; }
805
806 #endif // WITH_AUDASPACE