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