89
192
specs.format = U.audioformat;
90
193
specs.rate = U.audiorate;
195
if (force_device >= 0)
93
196
device = force_device;
198
if (buffersize < 128)
96
199
buffersize = AUD_DEFAULT_BUFFER_SIZE;
98
if(specs.rate < AUD_RATE_8000)
201
if (specs.rate < AUD_RATE_8000)
99
202
specs.rate = AUD_RATE_44100;
101
if(specs.format <= AUD_FORMAT_INVALID)
204
if (specs.format <= AUD_FORMAT_INVALID)
102
205
specs.format = AUD_FORMAT_S16;
104
if(specs.channels <= AUD_CHANNELS_INVALID)
207
if (specs.channels <= AUD_CHANNELS_INVALID)
105
208
specs.channels = AUD_CHANNELS_STEREO;
107
if(!AUD_init(device, specs, buffersize))
210
if (!AUD_init(device, specs, buffersize))
108
211
AUD_init(AUD_NULL_DEVICE, specs, buffersize);
213
sound_init_main(bmain);
216
void sound_init_main(struct Main *bmain)
111
219
AUD_setSyncCallback(sound_sync_callback, bmain);
221
(void)bmain; /* unused */
225
void sound_exit(void)
120
struct bSound* sound_new_file(struct Main *bmain, char* filename)
122
bSound* sound = NULL;
129
strcpy(str, filename);
131
path = /*bmain ? bmain->name :*/ G.sce;
133
BLI_path_abs(str, path);
135
len = strlen(filename);
136
while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\')
139
sound = alloc_libblock(&bmain->sound, ID_SO, filename+len);
140
BLI_strncpy(sound->name, filename, FILE_MAX);
141
// XXX unused currently sound->type = SOUND_TYPE_FILE;
143
sound_load(bmain, sound);
145
if(!sound->playback_handle)
147
free_libblock(&bmain->sound, sound);
154
230
// XXX unused currently
156
struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source)
232
struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source)
158
234
bSound* sound = NULL;
236
char name[MAX_ID_NAME+5];
161
237
strcpy(name, "buf_");
162
238
strcpy(name + 4, source->id.name);
164
sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name);
240
sound = alloc_libblock(&bmain->sound, ID_SO, name);
166
242
sound->child_sound = source;
167
243
sound->type = SOUND_TYPE_BUFFER;
169
sound_load(CTX_data_main(C), sound);
245
sound_load(bmain, sound);
171
if(!sound->playback_handle)
247
if (!sound->playback_handle)
173
free_libblock(&CTX_data_main(C)->sound, sound);
249
free_libblock(&bmain->sound, sound);
180
struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, float start, float end)
256
struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end)
182
258
bSound* sound = NULL;
260
char name[MAX_ID_NAME+5];
185
261
strcpy(name, "lim_");
186
262
strcpy(name + 4, source->id.name);
188
sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name);
264
sound = alloc_libblock(&bmain->sound, ID_SO, name);
190
266
sound->child_sound = source;
191
267
sound->start = start;
192
268
sound->end = end;
193
269
sound->type = SOUND_TYPE_LIMITER;
195
sound_load(CTX_data_main(C), sound);
271
sound_load(bmain, sound);
197
if(!sound->playback_handle)
273
if (!sound->playback_handle)
199
free_libblock(&CTX_data_main(C)->sound, sound);
275
free_libblock(&bmain->sound, sound);
273
361
/* or else load it from disk */
275
363
sound->handle = AUD_load(fullpath);
277
365
// XXX unused currently
281
369
case SOUND_TYPE_BUFFER:
282
if(sound->child_sound && sound->child_sound->handle)
370
if (sound->child_sound && sound->child_sound->handle)
283
371
sound->handle = AUD_bufferSound(sound->child_sound->handle);
285
373
case SOUND_TYPE_LIMITER:
286
if(sound->child_sound && sound->child_sound->handle)
374
if (sound->child_sound && sound->child_sound->handle)
287
375
sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
379
if (sound->flags & SOUND_FLAGS_MONO)
381
void* handle = AUD_monoSound(sound->handle);
382
AUD_unload(sound->handle);
383
sound->handle = handle;
386
if (sound->flags & SOUND_FLAGS_CACHING)
388
sound->cache = AUD_bufferSound(sound->handle);
292
392
sound->playback_handle = sound->cache;
294
394
sound->playback_handle = sound->handle;
298
void sound_free(struct bSound* sound)
300
if (sound->packedfile)
302
freePackedFile(sound->packedfile);
303
sound->packedfile = NULL;
308
AUD_unload(sound->handle);
309
sound->handle = NULL;
310
sound->playback_handle = NULL;
314
static float sound_get_volume(Scene* scene, Sequence* sequence, float time)
316
AnimData *adt= BKE_animdata_from_id(&scene->id);
320
/* NOTE: this manually constructed path needs to be used here to avoid problems with RNA crashes */
321
sprintf(buf, "sequence_editor.sequences_all[\"%s\"].volume", sequence->name+2);
322
if (adt && adt->action && adt->action->curves.first)
323
fcu= list_find_fcurve(&adt->action->curves, buf, 0);
326
return evaluate_fcurve(fcu, time * FPS);
328
return sequence->volume;
396
sound_update_sequencer(bmain, sound);
331
400
AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume)
333
AUD_Device* mixdown = AUD_openReadDevice(specs);
335
AUD_setDeviceVolume(mixdown, volume);
337
AUD_playDevice(mixdown, scene->sound_scene, start / FPS);
402
return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS);
342
405
void sound_create_scene(struct Scene *scene)
344
scene->sound_scene = AUD_createSequencer(scene, (AUD_volumeFunction)&sound_get_volume);
407
scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE);
408
AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound,
409
scene->audio.doppler_factor, scene->audio.distance_model);
410
scene->sound_scene_handle = NULL;
411
scene->sound_scrub_handle = NULL;
412
scene->speaker_handles = NULL;
347
415
void sound_destroy_scene(struct Scene *scene)
349
if(scene->sound_scene_handle)
417
if (scene->sound_scene_handle)
350
418
AUD_stop(scene->sound_scene_handle);
351
if(scene->sound_scene)
419
if (scene->sound_scrub_handle)
420
AUD_stop(scene->sound_scrub_handle);
421
if (scene->sound_scene)
352
422
AUD_destroySequencer(scene->sound_scene);
423
if (scene->speaker_handles)
424
AUD_destroySet(scene->speaker_handles);
427
void sound_mute_scene(struct Scene *scene, int muted)
429
if (scene->sound_scene)
430
AUD_setSequencerMuted(scene->sound_scene, muted);
433
void sound_update_fps(struct Scene *scene)
435
if (scene->sound_scene)
436
AUD_setSequencerFPS(scene->sound_scene, FPS);
439
void sound_update_scene_listener(struct Scene *scene)
441
AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound,
442
scene->audio.doppler_factor, scene->audio.distance_model);
355
445
void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
357
if(scene != sequence->scene)
358
return AUD_addSequencer(scene->sound_scene, &(sequence->scene->sound_scene), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
447
if (scene != sequence->scene)
448
return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, startframe / FPS, endframe / FPS, frameskip / FPS);
452
void* sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence)
454
return sound_scene_add_scene_sound(scene, sequence,
455
sequence->startdisp, sequence->enddisp,
456
sequence->startofs + sequence->anim_startofs);
362
459
void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
364
return AUD_addSequencer(scene->sound_scene, &(sequence->sound->playback_handle), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
461
void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS);
462
AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0);
463
AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0);
464
AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0);
465
AUD_setSequenceAnimData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0);
469
void* sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence)
471
return sound_add_scene_sound(scene, sequence,
472
sequence->startdisp, sequence->enddisp,
473
sequence->startofs + sequence->anim_startofs);
367
476
void sound_remove_scene_sound(struct Scene *scene, void* handle)
369
AUD_removeSequencer(scene->sound_scene, handle);
478
AUD_removeSequence(scene->sound_scene, handle);
372
void sound_mute_scene_sound(struct Scene *scene, void* handle, char mute)
481
void sound_mute_scene_sound(void* handle, char mute)
374
AUD_muteSequencer(scene->sound_scene, handle, mute);
483
AUD_muteSequence(handle, mute);
377
486
void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip)
379
AUD_moveSequencer(scene->sound_scene, handle, startframe / FPS, endframe / FPS, frameskip / FPS);
382
void sound_start_play_scene(struct Scene *scene)
385
sound = AUD_loopSound(scene->sound_scene);
386
scene->sound_scene_handle = AUD_play(sound, 1);
488
AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS);
491
void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence)
493
if (sequence->scene_sound) {
494
sound_move_scene_sound(scene, sequence->scene_sound,
495
sequence->startdisp, sequence->enddisp,
496
sequence->startofs + sequence->anim_startofs);
500
void sound_update_scene_sound(void* handle, struct bSound* sound)
502
AUD_updateSequenceSound(handle, sound->playback_handle);
505
void sound_set_cfra(int cfra)
510
void sound_set_scene_volume(struct Scene *scene, float volume)
512
AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0);
515
void sound_set_scene_sound_volume(void* handle, float volume, char animated)
517
AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
520
void sound_set_scene_sound_pitch(void* handle, float pitch, char animated)
522
AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
525
void sound_set_scene_sound_pan(void* handle, float pan, char animated)
527
AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
530
void sound_update_sequencer(struct Main* main, struct bSound* sound)
534
for (scene = main->scene.first; scene; scene = scene->id.next) {
535
seq_update_sound(scene, sound);
539
static void sound_start_play_scene(struct Scene *scene)
541
if (scene->sound_scene_handle)
542
AUD_stop(scene->sound_scene_handle);
544
AUD_setSequencerDeviceSpecs(scene->sound_scene);
546
if ((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1)))
547
AUD_setLoop(scene->sound_scene_handle, -1);
390
550
void sound_play_scene(struct Scene *scene)
414
578
void sound_stop_scene(struct Scene *scene)
416
AUD_pause(scene->sound_scene_handle);
580
if (scene->sound_scene_handle)
582
AUD_pause(scene->sound_scene_handle);
418
if(scene->audio.flag & AUDIO_SYNC)
584
if (scene->audio.flag & AUDIO_SYNC)
422
void sound_seek_scene(struct bContext *C)
589
void sound_seek_scene(struct Main *bmain, struct Scene *scene)
424
struct Scene *scene = CTX_data_scene(C);
425
591
AUD_Status status;
593
int animation_playing;
429
status = AUD_getStatus(scene->sound_scene_handle);
597
status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID;
431
if(status == AUD_STATUS_INVALID)
599
if (status == AUD_STATUS_INVALID)
433
601
sound_start_play_scene(scene);
603
if (!scene->sound_scene_handle)
434
609
AUD_pause(scene->sound_scene_handle);
437
if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer)
612
animation_playing = 0;
613
for (screen=bmain->screen.first; screen; screen=screen->id.next) {
614
if (screen->animtimer) {
615
animation_playing = 1;
619
if (scene->audio.flag & AUDIO_SCRUB && !animation_playing)
439
AUD_setLoop(scene->sound_scene_handle, -1, 1 / FPS);
440
if(scene->audio.flag & AUDIO_SYNC)
621
if (scene->audio.flag & AUDIO_SYNC)
623
AUD_seek(scene->sound_scene_handle, CFRA / FPS);
441
624
AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
443
627
AUD_seek(scene->sound_scene_handle, CFRA / FPS);
444
628
AUD_resume(scene->sound_scene_handle);
629
if (scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID)
630
AUD_seek(scene->sound_scrub_handle, 0);
632
if (scene->sound_scrub_handle)
633
AUD_stop(scene->sound_scrub_handle);
634
scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS);
448
if(scene->audio.flag & AUDIO_SYNC)
638
if (scene->audio.flag & AUDIO_SYNC)
449
639
AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
452
if(status == AUD_STATUS_PLAYING)
641
if (status == AUD_STATUS_PLAYING)
453
642
AUD_seek(scene->sound_scene_handle, CFRA / FPS);
460
649
float sound_sync_scene(struct Scene *scene)
462
if(scene->audio.flag & AUDIO_SYNC)
463
return AUD_getSequencerPosition(scene->sound_scene_handle);
465
return AUD_getPosition(scene->sound_scene_handle);
651
if (scene->sound_scene_handle)
653
if (scene->audio.flag & AUDIO_SYNC)
654
return AUD_getSequencerPosition(scene->sound_scene_handle);
656
return AUD_getPosition(scene->sound_scene_handle);
468
661
int sound_scene_playing(struct Scene *scene)
470
if(scene->audio.flag & AUDIO_SYNC)
663
if (scene->audio.flag & AUDIO_SYNC)
471
664
return AUD_doesPlayback();
476
int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, float start, float end)
478
AUD_Sound* limiter = AUD_limitSound(sound->cache, start, end);
479
return AUD_readSound(limiter, buffer, length);
669
void sound_free_waveform(struct bSound* sound)
673
MEM_freeN(((SoundWaveform*)sound->waveform)->data);
674
MEM_freeN(sound->waveform);
677
sound->waveform = NULL;
680
void sound_read_waveform(struct bSound* sound)
684
info = AUD_getInfo(sound->playback_handle);
688
SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform");
689
int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
691
waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples");
692
waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND);
694
sound_free_waveform(sound);
695
sound->waveform = waveform;
699
void sound_update_scene(struct Scene* scene)
708
void* new_set = AUD_createSet();
712
for (SETLOOPER(scene, sce_it, base))
715
if (ob->type == OB_SPEAKER)
719
for (track = ob->adt->nla_tracks.first; track; track = track->next)
721
for (strip = track->strips.first; strip; strip = strip->next)
723
if (strip->type == NLASTRIP_TYPE_SOUND)
725
speaker = (Speaker*)ob->data;
727
if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle))
730
AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0);
732
AUD_removeSequence(scene->sound_scene, strip->speaker_handle);
733
strip->speaker_handle = NULL;
739
strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0);
740
AUD_setRelativeSequence(strip->speaker_handle, 0);
744
if (strip->speaker_handle)
746
AUD_addSet(new_set, strip->speaker_handle);
747
AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max,
748
speaker->volume_min, speaker->distance_max,
749
speaker->distance_reference, speaker->attenuation,
750
speaker->cone_angle_outer, speaker->cone_angle_inner,
751
speaker->cone_volume_outer);
753
mat4_to_quat(quat, ob->obmat);
754
AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
755
AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
756
AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1);
757
AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1);
758
AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle);
759
AUD_muteSequence(strip->speaker_handle, ((strip->flag & NLASTRIP_FLAG_MUTED) != 0) || ((speaker->flag & SPK_MUTED) != 0));
768
while ((handle = AUD_getSet(scene->speaker_handles)))
770
AUD_removeSequence(scene->sound_scene, handle);
775
mat4_to_quat(quat, scene->camera->obmat);
776
AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1);
777
AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1);
780
AUD_destroySet(scene->speaker_handles);
781
scene->speaker_handles = new_set;
784
void* sound_get_factory(void* sound)
786
return ((struct bSound*) sound)->playback_handle;
789
#else // WITH_AUDASPACE
791
#include "BLI_utildefines.h"
793
int sound_define_from_str(const char *UNUSED(str)) { return -1;}
794
void sound_force_device(int UNUSED(device)) {}
795
void sound_init_once(void) {}
796
void sound_init(struct Main *UNUSED(bmain)) {}
797
void sound_exit(void) {}
798
void sound_cache(struct bSound* UNUSED(sound)) { }
799
void sound_delete_cache(struct bSound* UNUSED(sound)) {}
800
void sound_load(struct Main *UNUSED(bmain), struct bSound* UNUSED(sound)) {}
801
void sound_create_scene(struct Scene *UNUSED(scene)) {}
802
void sound_destroy_scene(struct Scene *UNUSED(scene)) {}
803
void sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {}
804
void* sound_scene_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; }
805
void* sound_scene_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence)) { return NULL; }
806
void* sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; }
807
void* sound_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence)) { return NULL; }
808
void sound_remove_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle)) {}
809
void sound_mute_scene_sound(void* UNUSED(handle), char UNUSED(mute)) {}
810
void sound_move_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) {}
811
void sound_move_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) {}
812
void sound_play_scene(struct Scene *UNUSED(scene)) {}
813
void sound_stop_scene(struct Scene *UNUSED(scene)) {}
814
void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {}
815
float sound_sync_scene(struct Scene *UNUSED(scene)) { return NAN_FLT; }
816
int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
817
int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; }
818
void sound_read_waveform(struct bSound* sound) { (void)sound; }
819
void sound_init_main(struct Main *bmain) { (void)bmain; }
820
void sound_set_cfra(int cfra) { (void)cfra; }
821
void sound_update_sequencer(struct Main* main, struct bSound* sound) { (void)main; (void)sound; }
822
void sound_update_scene(struct Scene* scene) { (void)scene; }
823
void sound_update_scene_sound(void* handle, struct bSound* sound) { (void)handle; (void)sound; }
824
void sound_update_scene_listener(struct Scene *scene) { (void)scene; }
825
void sound_update_fps(struct Scene *scene) { (void)scene; }
826
void sound_set_scene_sound_volume(void* handle, float volume, char animated) { (void)handle; (void)volume; (void)animated; }
827
void sound_set_scene_sound_pan(void* handle, float pan, char animated) { (void)handle; (void)pan; (void)animated; }
828
void sound_set_scene_volume(struct Scene *scene, float volume) { (void)scene; (void)volume; }
829
void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) { (void)handle; (void)pitch; (void)animated; }
831
#endif // WITH_AUDASPACE