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