style cleanup, brackets in else/if, some indentation.
[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[MAX_ID_NAME+5];
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[MAX_ID_NAME+5];
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_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence)
453 {
454         return sound_scene_add_scene_sound(scene, sequence,
455                                            sequence->startdisp, sequence->enddisp,
456                                            sequence->startofs + sequence->anim_startofs);
457 }
458
459 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
460 {
461         void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS);
462         AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0);
463         AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0);
464         AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0);
465         AUD_setSequenceAnimData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0);
466         return handle;
467 }
468
469 void* sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence)
470 {
471         return sound_add_scene_sound(scene, sequence,
472                                      sequence->startdisp, sequence->enddisp,
473                                      sequence->startofs + sequence->anim_startofs);
474 }
475
476 void sound_remove_scene_sound(struct Scene *scene, void* handle)
477 {
478         AUD_removeSequence(scene->sound_scene, handle);
479 }
480
481 void sound_mute_scene_sound(void* handle, char mute)
482 {
483         AUD_muteSequence(handle, mute);
484 }
485
486 void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip)
487 {
488         AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS);
489 }
490
491 void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence)
492 {
493         if (sequence->scene_sound) {
494                 sound_move_scene_sound(scene, sequence->scene_sound,
495                                        sequence->startdisp, sequence->enddisp,
496                                        sequence->startofs + sequence->anim_startofs);
497         }
498 }
499
500 void sound_update_scene_sound(void* handle, struct bSound* sound)
501 {
502         AUD_updateSequenceSound(handle, sound->playback_handle);
503 }
504
505 void sound_set_cfra(int cfra)
506 {
507         sound_cfra = cfra;
508 }
509
510 void sound_set_scene_volume(struct Scene *scene, float volume)
511 {
512         AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0);
513 }
514
515 void sound_set_scene_sound_volume(void* handle, float volume, char animated)
516 {
517         AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
518 }
519
520 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated)
521 {
522         AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
523 }
524
525 void sound_set_scene_sound_pan(void* handle, float pan, char animated)
526 {
527         AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
528 }
529
530 void sound_update_sequencer(struct Main* main, struct bSound* sound)
531 {
532         struct Scene* scene;
533
534         for (scene = main->scene.first; scene; scene = scene->id.next) {
535                 seq_update_sound(scene, sound);
536         }
537 }
538
539 static void sound_start_play_scene(struct Scene *scene)
540 {
541         if (scene->sound_scene_handle)
542                 AUD_stop(scene->sound_scene_handle);
543
544         AUD_setSequencerDeviceSpecs(scene->sound_scene);
545
546         if ((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1)))
547                 AUD_setLoop(scene->sound_scene_handle, -1);
548 }
549
550 void sound_play_scene(struct Scene *scene)
551 {
552         AUD_Status status;
553         AUD_lock();
554
555         status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
556
557         if (status == AUD_STATUS_INVALID)
558                 sound_start_play_scene(scene);
559
560         if (!scene->sound_scene_handle)
561         {
562                 AUD_unlock();
563                 return;
564         }
565
566         if (status != AUD_STATUS_PLAYING)
567         {
568                 AUD_seek(scene->sound_scene_handle, CFRA / FPS);
569                 AUD_resume(scene->sound_scene_handle);
570         }
571
572         if (scene->audio.flag & AUDIO_SYNC)
573                 AUD_startPlayback();
574
575         AUD_unlock();
576 }
577
578 void sound_stop_scene(struct Scene *scene)
579 {
580         if (scene->sound_scene_handle)
581         {
582                 AUD_pause(scene->sound_scene_handle);
583
584                 if (scene->audio.flag & AUDIO_SYNC)
585                         AUD_stopPlayback();
586         }
587 }
588
589 void sound_seek_scene(struct Main *bmain, struct Scene *scene)
590 {
591         AUD_Status status;
592         bScreen *screen;
593         int animation_playing;
594
595         AUD_lock();
596
597         status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
598
599         if (status == AUD_STATUS_INVALID)
600         {
601                 sound_start_play_scene(scene);
602
603                 if (!scene->sound_scene_handle)
604                 {
605                         AUD_unlock();
606                         return;
607                 }
608
609                 AUD_pause(scene->sound_scene_handle);
610         }
611
612         animation_playing = 0;
613         for (screen=bmain->screen.first; screen; screen=screen->id.next) {
614                 if (screen->animtimer) {
615                         animation_playing = 1;
616                 }
617         }
618
619         if (scene->audio.flag & AUDIO_SCRUB && !animation_playing)
620         {
621                 if (scene->audio.flag & AUDIO_SYNC)
622                 {
623                         AUD_seek(scene->sound_scene_handle, CFRA / FPS);
624                         AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
625                 }
626                 else
627                         AUD_seek(scene->sound_scene_handle, CFRA / FPS);
628                 AUD_resume(scene->sound_scene_handle);
629                 if (scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID)
630                         AUD_seek(scene->sound_scrub_handle, 0);
631                 else {
632                         if (scene->sound_scrub_handle)
633                                 AUD_stop(scene->sound_scrub_handle);
634                         scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS);
635                 }
636         }
637         else {
638                 if (scene->audio.flag & AUDIO_SYNC)
639                         AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
640                 else {
641                         if (status == AUD_STATUS_PLAYING)
642                                 AUD_seek(scene->sound_scene_handle, CFRA / FPS);
643                 }
644         }
645
646         AUD_unlock();
647 }
648
649 float sound_sync_scene(struct Scene *scene)
650 {
651         if (scene->sound_scene_handle)
652         {
653                 if (scene->audio.flag & AUDIO_SYNC)
654                         return AUD_getSequencerPosition(scene->sound_scene_handle);
655                 else
656                         return AUD_getPosition(scene->sound_scene_handle);
657         }
658         return NAN_FLT;
659 }
660
661 int sound_scene_playing(struct Scene *scene)
662 {
663         if (scene->audio.flag & AUDIO_SYNC)
664                 return AUD_doesPlayback();
665         else
666                 return -1;
667 }
668
669 void sound_free_waveform(struct bSound* sound)
670 {
671         if (sound->waveform)
672         {
673                 MEM_freeN(((SoundWaveform*)sound->waveform)->data);
674                 MEM_freeN(sound->waveform);
675         }
676
677         sound->waveform = NULL;
678 }
679
680 void sound_read_waveform(struct bSound* sound)
681 {
682         AUD_SoundInfo info;
683
684         info = AUD_getInfo(sound->playback_handle);
685
686         if (info.length > 0)
687         {
688                 SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform");
689                 int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
690
691                 waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples");
692                 waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND);
693
694                 sound_free_waveform(sound);
695                 sound->waveform = waveform;
696         }
697 }
698
699 void sound_update_scene(struct Scene* scene)
700 {
701         Object* ob;
702         Base* base;
703         NlaTrack* track;
704         NlaStrip* strip;
705         Speaker* speaker;
706         Scene* sce_it;
707
708         void* new_set = AUD_createSet();
709         void* handle;
710         float quat[4];
711
712         for (SETLOOPER(scene, sce_it, base))
713         {
714                 ob = base->object;
715                 if (ob->type == OB_SPEAKER)
716                 {
717                         if (ob->adt)
718                         {
719                                 for (track = ob->adt->nla_tracks.first; track; track = track->next)
720                                 {
721                                         for (strip = track->strips.first; strip; strip = strip->next)
722                                         {
723                                                 if (strip->type == NLASTRIP_TYPE_SOUND)
724                                                 {
725                                                         speaker = (Speaker*)ob->data;
726
727                                                         if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle))
728                                                         {
729                                                                 if (speaker->sound)
730                                                                         AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0);
731                                                                 else {
732                                                                         AUD_removeSequence(scene->sound_scene, strip->speaker_handle);
733                                                                         strip->speaker_handle = NULL;
734                                                                 }
735                                                         }
736                                                         else {
737                                                                 if (speaker->sound)
738                                                                 {
739                                                                         strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0);
740                                                                         AUD_setRelativeSequence(strip->speaker_handle, 0);
741                                                                 }
742                                                         }
743
744                                                         if (strip->speaker_handle)
745                                                         {
746                                                                 AUD_addSet(new_set, strip->speaker_handle);
747                                                                 AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max,
748                                                                                                            speaker->volume_min, speaker->distance_max,
749                                                                                                            speaker->distance_reference, speaker->attenuation,
750                                                                                                            speaker->cone_angle_outer, speaker->cone_angle_inner,
751                                                                                                            speaker->cone_volume_outer);
752
753                                                                 mat4_to_quat(quat, ob->obmat);
754                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
755                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
756                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1);
757                                                                 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1);
758                                                                 AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle);
759                                                                 AUD_muteSequence(strip->speaker_handle, ((strip->flag & NLASTRIP_FLAG_MUTED) != 0) || ((speaker->flag & SPK_MUTED) != 0));
760                                                         }
761                                                 }
762                                         }
763                                 }
764                         }
765                 }
766         }
767
768         while((handle = AUD_getSet(scene->speaker_handles)))
769         {
770                 AUD_removeSequence(scene->sound_scene, handle);
771         }
772
773         if (scene->camera)
774         {
775                 mat4_to_quat(quat, scene->camera->obmat);
776                 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1);
777                 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1);
778         }
779
780         AUD_destroySet(scene->speaker_handles);
781         scene->speaker_handles = new_set;
782 }
783
784 void* sound_get_factory(void* sound)
785 {
786         return ((struct bSound*) sound)->playback_handle;
787 }
788
789 #else // WITH_AUDASPACE
790
791 #include "BLI_utildefines.h"
792
793 int sound_define_from_str(const char *UNUSED(str)) { return -1;}
794 void sound_force_device(int UNUSED(device)) {}
795 void sound_init_once(void) {}
796 void sound_init(struct Main *UNUSED(bmain)) {}
797 void sound_exit(void) {}
798 void sound_cache(struct bSound* UNUSED(sound)) { }
799 void sound_delete_cache(struct bSound* UNUSED(sound)) {}
800 void sound_load(struct Main *UNUSED(bmain), struct bSound* UNUSED(sound)) {}
801 void sound_create_scene(struct Scene *UNUSED(scene)) {}
802 void sound_destroy_scene(struct Scene *UNUSED(scene)) {}
803 void sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {}
804 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; }
805 void* sound_scene_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence)) { return NULL; }
806 void* sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; }
807 void* sound_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence)) { return NULL; }
808 void sound_remove_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle)) {}
809 void sound_mute_scene_sound(void* UNUSED(handle), char UNUSED(mute)) {}
810 void sound_move_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) {}
811 void sound_move_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) {}
812 void sound_play_scene(struct Scene *UNUSED(scene)) {}
813 void sound_stop_scene(struct Scene *UNUSED(scene)) {}
814 void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {}
815 float sound_sync_scene(struct Scene *UNUSED(scene)) { return NAN_FLT; }
816 int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
817 int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; }
818 void sound_read_waveform(struct bSound* sound) { (void)sound; }
819 void sound_init_main(struct Main *bmain) { (void)bmain; }
820 void sound_set_cfra(int cfra) { (void)cfra; }
821 void sound_update_sequencer(struct Main* main, struct bSound* sound) { (void)main; (void)sound; }
822 void sound_update_scene(struct Scene* scene) { (void)scene; }
823 void sound_update_scene_sound(void* handle, struct bSound* sound) { (void)handle; (void)sound; }
824 void sound_update_scene_listener(struct Scene *scene) { (void)scene; }
825 void sound_update_fps(struct Scene *scene) { (void)scene; }
826 void sound_set_scene_sound_volume(void* handle, float volume, char animated) { (void)handle; (void)volume; (void)animated; }
827 void sound_set_scene_sound_pan(void* handle, float pan, char animated) { (void)handle; (void)pan; (void)animated; }
828 void sound_set_scene_volume(struct Scene *scene, float volume) { (void)scene; (void)volume; }
829 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) { (void)handle; (void)pitch; (void)animated; }
830
831 #endif // WITH_AUDASPACE