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