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