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