diff options
Diffstat (limited to 'source/blender/blenkernel/intern/sound.c')
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 570 |
1 files changed, 316 insertions, 254 deletions
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index da6ead06d98..0b89931aa75 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -36,6 +36,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" +#include "BLI_threads.h" #include "DNA_anim_types.h" #include "DNA_object_types.h" @@ -47,7 +48,13 @@ #include "DNA_speaker_types.h" #ifdef WITH_AUDASPACE -# include "AUD_C-API.h" +# include AUD_SOUND_H +# include AUD_SEQUENCE_H +# include AUD_HANDLE_H +# include AUD_SPECIAL_H +# ifdef WITH_SYSTEM_AUDASPACE +# include "../../../intern/audaspace/intern/AUD_Set.h" +# endif #endif #include "BKE_global.h" @@ -59,13 +66,14 @@ #include "BKE_scene.h" #ifdef WITH_AUDASPACE -/* evil global ;-) */ +/* evil globals ;-) */ static int sound_cfra; +static char **audio_device_names = NULL; #endif -bSound *sound_new_file(struct Main *bmain, const char *filename) +bSound *BKE_sound_new_file(struct Main *bmain, const char *filename) { - bSound *sound = NULL; + bSound *sound; char str[FILE_MAX]; const char *path; @@ -86,12 +94,7 @@ bSound *sound_new_file(struct Main *bmain, const char *filename) BLI_strncpy(sound->name, filename, FILE_MAX); /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */ - sound_load(bmain, sound); - - if (!sound->playback_handle) { - BKE_libblock_free(bmain, sound); - sound = NULL; - } + BKE_sound_load(bmain, sound); return sound; } @@ -105,23 +108,30 @@ void BKE_sound_free(bSound *sound) #ifdef WITH_AUDASPACE if (sound->handle) { - AUD_unload(sound->handle); + AUD_Sound_free(sound->handle); sound->handle = NULL; sound->playback_handle = NULL; } if (sound->cache) { - AUD_unload(sound->cache); + AUD_Sound_free(sound->cache); sound->cache = NULL; } - sound_free_waveform(sound); + BKE_sound_free_waveform(sound); + + if (sound->spinlock) { + BLI_spin_end(sound->spinlock); + MEM_freeN(sound->spinlock); + sound->spinlock = NULL; + } + #endif /* WITH_AUDASPACE */ } #ifdef WITH_AUDASPACE -static int force_device = -1; +static const char *force_device = NULL; #ifdef WITH_JACK static void sound_sync_callback(void *data, int mode, float time) @@ -133,46 +143,40 @@ static void sound_sync_callback(void *data, int mode, float time) while (scene) { if (scene->audio.flag & AUDIO_SYNC) { if (mode) - sound_play_scene(scene); + BKE_sound_play_scene(scene); else - sound_stop_scene(scene); - if (scene->sound_scene_handle) - AUD_seek(scene->sound_scene_handle, time); + BKE_sound_stop_scene(scene); + if (scene->playback_handle) + AUD_Handle_setPosition(scene->playback_handle, time); } scene = scene->id.next; } } #endif -int sound_define_from_str(const char *str) +void BKE_sound_force_device(const char *device) { - if (BLI_strcaseeq(str, "NULL")) - return AUD_NULL_DEVICE; - if (BLI_strcaseeq(str, "SDL")) - return AUD_SDL_DEVICE; - if (BLI_strcaseeq(str, "OPENAL")) - return AUD_OPENAL_DEVICE; - if (BLI_strcaseeq(str, "JACK")) - return AUD_JACK_DEVICE; - - return -1; + force_device = device; } -void sound_force_device(int device) +void BKE_sound_init_once(void) { - force_device = device; + AUD_initOnce(); + atexit(BKE_sound_exit_once); } -void sound_init_once(void) +static AUD_Device *sound_device; + +void *BKE_sound_get_device(void) { - AUD_initOnce(); - atexit(sound_exit_once); + return sound_device; } -void sound_init(struct Main *bmain) +void BKE_sound_init(struct Main *bmain) { AUD_DeviceSpecs specs; int device, buffersize; + const char *device_name; device = U.audiodevice; buffersize = U.mixbufsize; @@ -180,11 +184,23 @@ void sound_init(struct Main *bmain) specs.format = U.audioformat; specs.rate = U.audiorate; - if (force_device >= 0) - device = force_device; + if (force_device == NULL) { + int i; + char **names = BKE_sound_get_device_names(); + device_name = names[0]; + + /* make sure device is within the bounds of the array */ + for (i = 0; names[i]; i++) { + if (i == device) { + device_name = names[i]; + } + } + } + else + device_name = force_device; if (buffersize < 128) - buffersize = AUD_DEFAULT_BUFFER_SIZE; + buffersize = 1024; if (specs.rate < AUD_RATE_8000) specs.rate = AUD_RATE_44100; @@ -195,35 +211,48 @@ void sound_init(struct Main *bmain) if (specs.channels <= AUD_CHANNELS_INVALID) specs.channels = AUD_CHANNELS_STEREO; - if (!AUD_init(device, specs, buffersize)) - AUD_init(AUD_NULL_DEVICE, specs, buffersize); + if (!(sound_device = AUD_init(device_name, specs, buffersize, "Blender"))) + sound_device = AUD_init("Null", specs, buffersize, "Blender"); - sound_init_main(bmain); + BKE_sound_init_main(bmain); } -void sound_init_main(struct Main *bmain) +void BKE_sound_init_main(struct Main *bmain) { #ifdef WITH_JACK - AUD_setSyncCallback(sound_sync_callback, bmain); + AUD_setSynchronizerCallback(sound_sync_callback, bmain); #else (void)bmain; /* unused */ #endif } -void sound_exit(void) +void BKE_sound_exit(void) { - AUD_exit(); + AUD_exit(sound_device); + sound_device = NULL; } -void sound_exit_once(void) +void BKE_sound_exit_once(void) { - AUD_exit(); + AUD_exit(sound_device); + sound_device = NULL; AUD_exitOnce(); + +#ifdef WITH_SYSTEM_AUDASPACE + if (audio_device_names != NULL) { + int i; + for (i = 0; audio_device_names[i]; i++) { + free(audio_device_names[i]); + } + free(audio_device_names); + audio_device_names = NULL; + } +#endif } /* XXX unused currently */ #if 0 -bSound *sound_new_buffer(struct Main *bmain, bSound *source) +bSound *BKE_sound_new_buffer(struct Main *bmain, bSound *source) { bSound *sound = NULL; @@ -238,16 +267,10 @@ bSound *sound_new_buffer(struct Main *bmain, bSound *source) sound_load(bmain, sound); - if (!sound->playback_handle) - { - BKE_libblock_free(bmain, sound); - sound = NULL; - } - return sound; } -bSound *sound_new_limiter(struct Main *bmain, bSound *source, float start, float end) +bSound *BKE_sound_new_limiter(struct Main *bmain, bSound *source, float start, float end) { bSound *sound = NULL; @@ -264,17 +287,11 @@ bSound *sound_new_limiter(struct Main *bmain, bSound *source, float start, float sound_load(bmain, sound); - if (!sound->playback_handle) - { - BKE_libblock_free(bmain, sound); - sound = NULL; - } - return sound; } #endif -void sound_delete(struct Main *bmain, bSound *sound) +void BKE_sound_delete(struct Main *bmain, bSound *sound) { if (sound) { BKE_sound_free(sound); @@ -283,50 +300,44 @@ void sound_delete(struct Main *bmain, bSound *sound) } } -void sound_cache(bSound *sound) +void BKE_sound_cache(bSound *sound) { sound->flags |= SOUND_FLAGS_CACHING; if (sound->cache) - AUD_unload(sound->cache); + AUD_Sound_free(sound->cache); - sound->cache = AUD_bufferSound(sound->handle); + sound->cache = AUD_Sound_cache(sound->handle); if (sound->cache) sound->playback_handle = sound->cache; else sound->playback_handle = sound->handle; } -void sound_cache_notifying(struct Main *main, bSound *sound) -{ - sound_cache(sound); - sound_update_sequencer(main, sound); -} - -void sound_delete_cache(bSound *sound) +void BKE_sound_delete_cache(bSound *sound) { sound->flags &= ~SOUND_FLAGS_CACHING; if (sound->cache) { - AUD_unload(sound->cache); + AUD_Sound_free(sound->cache); sound->cache = NULL; sound->playback_handle = sound->handle; } } -void sound_load(struct Main *bmain, bSound *sound) +void BKE_sound_load(struct Main *bmain, bSound *sound) { if (sound) { if (sound->cache) { - AUD_unload(sound->cache); + AUD_Sound_free(sound->cache); sound->cache = NULL; } if (sound->handle) { - AUD_unload(sound->handle); + AUD_Sound_free(sound->handle); sound->handle = NULL; sound->playback_handle = NULL; } - sound_free_waveform(sound); + BKE_sound_free_waveform(sound); /* XXX unused currently */ #if 0 @@ -346,10 +357,10 @@ void sound_load(struct Main *bmain, bSound *sound) /* but we need a packed file then */ if (pf) - sound->handle = AUD_loadBuffer((unsigned char *) pf->data, pf->size); + sound->handle = AUD_Sound_bufferFile((unsigned char *) pf->data, pf->size); /* or else load it from disk */ else - sound->handle = AUD_load(fullpath); + sound->handle = AUD_Sound_file(fullpath); } /* XXX unused currently */ #if 0 @@ -366,13 +377,13 @@ void sound_load(struct Main *bmain, bSound *sound) } #endif if (sound->flags & SOUND_FLAGS_MONO) { - void *handle = AUD_monoSound(sound->handle); - AUD_unload(sound->handle); + void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO); + AUD_Sound_free(sound->handle); sound->handle = handle; } if (sound->flags & SOUND_FLAGS_CACHING) { - sound->cache = AUD_bufferSound(sound->handle); + sound->cache = AUD_Sound_cache(sound->handle); } if (sound->cache) @@ -380,155 +391,157 @@ void sound_load(struct Main *bmain, bSound *sound) else sound->playback_handle = sound->handle; - sound_update_sequencer(bmain, sound); + BKE_sound_update_sequencer(bmain, sound); } } -AUD_Device *sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) +AUD_Device *BKE_sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) { return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); } -void sound_create_scene(struct Scene *scene) +void BKE_sound_create_scene(struct Scene *scene) { /* should be done in version patch, but this gets called before */ if (scene->r.frs_sec_base == 0) scene->r.frs_sec_base = 1; - scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE); - AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, - scene->audio.doppler_factor, scene->audio.distance_model); - scene->sound_scene_handle = NULL; + scene->sound_scene = AUD_Sequence_create(FPS, scene->audio.flag & AUDIO_MUTE); + AUD_Sequence_setSpeedOfSound(scene->sound_scene, scene->audio.speed_of_sound); + AUD_Sequence_setDopplerFactor(scene->sound_scene, scene->audio.doppler_factor); + AUD_Sequence_setDistanceModel(scene->sound_scene, scene->audio.distance_model); + scene->playback_handle = NULL; scene->sound_scrub_handle = NULL; scene->speaker_handles = NULL; } -void sound_destroy_scene(struct Scene *scene) +void BKE_sound_destroy_scene(struct Scene *scene) { - if (scene->sound_scene_handle) - AUD_stop(scene->sound_scene_handle); + if (scene->playback_handle) + AUD_Handle_stop(scene->playback_handle); if (scene->sound_scrub_handle) - AUD_stop(scene->sound_scrub_handle); + AUD_Handle_stop(scene->sound_scrub_handle); if (scene->sound_scene) - AUD_destroySequencer(scene->sound_scene); + AUD_Sequence_free(scene->sound_scene); if (scene->speaker_handles) AUD_destroySet(scene->speaker_handles); } -void sound_mute_scene(struct Scene *scene, int muted) +void BKE_sound_mute_scene(struct Scene *scene, int muted) { if (scene->sound_scene) - AUD_setSequencerMuted(scene->sound_scene, muted); + AUD_Sequence_setMuted(scene->sound_scene, muted); } -void sound_update_fps(struct Scene *scene) +void BKE_sound_update_fps(struct Scene *scene) { if (scene->sound_scene) - AUD_setSequencerFPS(scene->sound_scene, FPS); + AUD_Sequence_setFPS(scene->sound_scene, FPS); BKE_sequencer_refresh_sound_length(scene); } -void sound_update_scene_listener(struct Scene *scene) +void BKE_sound_update_scene_listener(struct Scene *scene) { - AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, - scene->audio.doppler_factor, scene->audio.distance_model); + AUD_Sequence_setSpeedOfSound(scene->sound_scene, scene->audio.speed_of_sound); + AUD_Sequence_setDopplerFactor(scene->sound_scene, scene->audio.doppler_factor); + AUD_Sequence_setDistanceModel(scene->sound_scene, scene->audio.distance_model); } -void *sound_scene_add_scene_sound(struct Scene *scene, struct Sequence *sequence, +void *BKE_sound_scene_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) { if (scene != sequence->scene) { const double fps = FPS; - return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, + return AUD_Sequence_add(scene->sound_scene, sequence->scene->sound_scene, startframe / fps, endframe / fps, frameskip / fps); } return NULL; } -void *sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) +void *BKE_sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { - return sound_scene_add_scene_sound(scene, sequence, + return BKE_sound_scene_add_scene_sound(scene, sequence, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } -void *sound_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) +void *BKE_sound_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) { const double fps = FPS; - void *handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, + void *handle = AUD_Sequence_add(scene->sound_scene, sequence->sound->playback_handle, startframe / fps, endframe / fps, frameskip / fps); - AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0); - AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0); - AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0); - AUD_setSequenceAnimData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0); + AUD_SequenceEntry_setMuted(handle, (sequence->flag & SEQ_MUTE) != 0); + AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0); + AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0); + AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0); return handle; } -void *sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) +void *BKE_sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { - return sound_add_scene_sound(scene, sequence, + return BKE_sound_add_scene_sound(scene, sequence, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } -void sound_remove_scene_sound(struct Scene *scene, void *handle) +void BKE_sound_remove_scene_sound(struct Scene *scene, void *handle) { - AUD_removeSequence(scene->sound_scene, handle); + AUD_Sequence_remove(scene->sound_scene, handle); } -void sound_mute_scene_sound(void *handle, char mute) +void BKE_sound_mute_scene_sound(void *handle, char mute) { - AUD_muteSequence(handle, mute); + AUD_SequenceEntry_setMuted(handle, mute); } -void sound_move_scene_sound(struct Scene *scene, void *handle, int startframe, int endframe, int frameskip) +void BKE_sound_move_scene_sound(struct Scene *scene, void *handle, int startframe, int endframe, int frameskip) { const double fps = FPS; - AUD_moveSequence(handle, startframe / fps, endframe / fps, frameskip / fps); + AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps); } -void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) +void BKE_sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { if (sequence->scene_sound) { - sound_move_scene_sound(scene, sequence->scene_sound, + BKE_sound_move_scene_sound(scene, sequence->scene_sound, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } } -void sound_update_scene_sound(void *handle, bSound *sound) +void BKE_sound_update_scene_sound(void *handle, bSound *sound) { - AUD_updateSequenceSound(handle, sound->playback_handle); + AUD_SequenceEntry_setSound(handle, sound->playback_handle); } -void sound_set_cfra(int cfra) +void BKE_sound_set_cfra(int cfra) { sound_cfra = cfra; } -void sound_set_scene_volume(struct Scene *scene, float volume) +void BKE_sound_set_scene_volume(struct Scene *scene, float volume) { - AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, + AUD_Sequence_setAnimationData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0); } -void sound_set_scene_sound_volume(void *handle, float volume, char animated) +void BKE_sound_set_scene_sound_volume(void *handle, float volume, char animated) { - AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated); + AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated); } -void sound_set_scene_sound_pitch(void *handle, float pitch, char animated) +void BKE_sound_set_scene_sound_pitch(void *handle, float pitch, char animated) { - AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated); + AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated); } -void sound_set_scene_sound_pan(void *handle, float pan, char animated) +void BKE_sound_set_scene_sound_pan(void *handle, float pan, char animated) { - AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated); + AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated); } -void sound_update_sequencer(struct Main *main, bSound *sound) +void BKE_sound_update_sequencer(struct Main *main, bSound *sound) { struct Scene *scene; @@ -539,55 +552,60 @@ void sound_update_sequencer(struct Main *main, bSound *sound) static void sound_start_play_scene(struct Scene *scene) { - if (scene->sound_scene_handle) - AUD_stop(scene->sound_scene_handle); + AUD_Specs specs; - AUD_setSequencerDeviceSpecs(scene->sound_scene); + if (scene->playback_handle) + AUD_Handle_stop(scene->playback_handle); - if ((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1))) - AUD_setLoop(scene->sound_scene_handle, -1); + specs.channels = AUD_Device_getChannels(sound_device); + specs.rate = AUD_Device_getRate(sound_device); + + AUD_Sequence_setSpecs(scene->sound_scene, specs); + + if ((scene->playback_handle = AUD_Device_play(sound_device, scene->sound_scene, 1))) + AUD_Handle_setLoopCount(scene->playback_handle, -1); } -void sound_play_scene(struct Scene *scene) +void BKE_sound_play_scene(struct Scene *scene) { AUD_Status status; const float cur_time = (float)((double)CFRA / FPS); - AUD_lock(); + AUD_Device_lock(sound_device); - status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; + status = scene->playback_handle ? AUD_Handle_getStatus(scene->playback_handle) : AUD_STATUS_INVALID; if (status == AUD_STATUS_INVALID) { sound_start_play_scene(scene); - if (!scene->sound_scene_handle) { - AUD_unlock(); + if (!scene->playback_handle) { + AUD_Device_unlock(sound_device); return; } } if (status != AUD_STATUS_PLAYING) { - AUD_seek(scene->sound_scene_handle, cur_time); - AUD_resume(scene->sound_scene_handle); + AUD_Handle_setPosition(scene->playback_handle, cur_time); + AUD_Handle_resume(scene->playback_handle); } if (scene->audio.flag & AUDIO_SYNC) - AUD_startPlayback(); + AUD_playSynchronizer(); - AUD_unlock(); + AUD_Device_unlock(sound_device); } -void sound_stop_scene(struct Scene *scene) +void BKE_sound_stop_scene(struct Scene *scene) { - if (scene->sound_scene_handle) { - AUD_pause(scene->sound_scene_handle); + if (scene->playback_handle) { + AUD_Handle_pause(scene->playback_handle); if (scene->audio.flag & AUDIO_SYNC) - AUD_stopPlayback(); + AUD_stopSynchronizer(); } } -void sound_seek_scene(struct Main *bmain, struct Scene *scene) +void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene) { AUD_Status status; bScreen *screen; @@ -596,109 +614,131 @@ void sound_seek_scene(struct Main *bmain, struct Scene *scene) const float one_frame = (float)(1.0 / FPS); const float cur_time = (float)((double)CFRA / FPS); - AUD_lock(); + AUD_Device_lock(sound_device); - status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; + status = scene->playback_handle ? AUD_Handle_getStatus(scene->playback_handle) : AUD_STATUS_INVALID; if (status == AUD_STATUS_INVALID) { sound_start_play_scene(scene); - if (!scene->sound_scene_handle) { - AUD_unlock(); + if (!scene->playback_handle) { + AUD_Device_unlock(sound_device); return; } - AUD_pause(scene->sound_scene_handle); + AUD_Handle_pause(scene->playback_handle); } animation_playing = 0; for (screen = bmain->screen.first; screen; screen = screen->id.next) { if (screen->animtimer) { animation_playing = 1; + break; } } if (scene->audio.flag & AUDIO_SCRUB && !animation_playing) { + AUD_Handle_setPosition(scene->playback_handle, cur_time); if (scene->audio.flag & AUDIO_SYNC) { - AUD_seek(scene->sound_scene_handle, cur_time); - AUD_seekSequencer(scene->sound_scene_handle, cur_time); + AUD_seekSynchronizer(scene->playback_handle, cur_time); } - else { - AUD_seek(scene->sound_scene_handle, cur_time); - } - AUD_resume(scene->sound_scene_handle); - if (scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) { - AUD_seek(scene->sound_scrub_handle, 0); + AUD_Handle_resume(scene->playback_handle); + if (scene->sound_scrub_handle && AUD_Handle_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) { + AUD_Handle_setPosition(scene->sound_scrub_handle, 0); } else { if (scene->sound_scrub_handle) { - AUD_stop(scene->sound_scrub_handle); + AUD_Handle_stop(scene->sound_scrub_handle); } - scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, one_frame); + scene->sound_scrub_handle = AUD_pauseAfter(scene->playback_handle, one_frame); } } else { if (scene->audio.flag & AUDIO_SYNC) { - AUD_seekSequencer(scene->sound_scene_handle, cur_time); + AUD_seekSynchronizer(scene->playback_handle, cur_time); } else { if (status == AUD_STATUS_PLAYING) { - AUD_seek(scene->sound_scene_handle, cur_time); + AUD_Handle_setPosition(scene->playback_handle, cur_time); } } } - AUD_unlock(); + AUD_Device_unlock(sound_device); } -float sound_sync_scene(struct Scene *scene) +float BKE_sound_sync_scene(struct Scene *scene) { - if (scene->sound_scene_handle) { + if (scene->playback_handle) { if (scene->audio.flag & AUDIO_SYNC) - return AUD_getSequencerPosition(scene->sound_scene_handle); + return AUD_getSynchronizerPosition(scene->playback_handle); else - return AUD_getPosition(scene->sound_scene_handle); + return AUD_Handle_getPosition(scene->playback_handle); } return NAN_FLT; } -int sound_scene_playing(struct Scene *scene) +int BKE_sound_scene_playing(struct Scene *scene) { if (scene->audio.flag & AUDIO_SYNC) - return AUD_doesPlayback(); + return AUD_isSynchronizerPlaying(); else return -1; } -void sound_free_waveform(bSound *sound) +void BKE_sound_free_waveform(bSound *sound) { - if (sound->waveform) { - MEM_freeN(((SoundWaveform *)sound->waveform)->data); - MEM_freeN(sound->waveform); + SoundWaveform *waveform = sound->waveform; + if (waveform) { + if (waveform->data) { + MEM_freeN(waveform->data); + } + MEM_freeN(waveform); } sound->waveform = NULL; } -void sound_read_waveform(bSound *sound) +void BKE_sound_read_waveform(bSound *sound, short *stop) { - AUD_SoundInfo info; - - info = AUD_getInfo(sound->playback_handle); + AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); + SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); if (info.length > 0) { - SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; - + waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples"); - waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND); + waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND, stop); + } + else { + /* Create an empty waveform here if the sound couldn't be + * read. This indicates that reading the waveform is "done", + * whereas just setting sound->waveform to NULL causes other + * code to think the waveform still needs to be created. */ + waveform->data = NULL; + waveform->length = 0; + } - sound_free_waveform(sound); - sound->waveform = waveform; + if (*stop) { + if (waveform->data) { + MEM_freeN(waveform->data); + } + MEM_freeN(waveform); + BLI_spin_lock(sound->spinlock); + sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; + BLI_spin_unlock(sound->spinlock); + return; } + + BKE_sound_free_waveform(sound); + + BLI_spin_lock(sound->spinlock); + sound->waveform = waveform; + sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; + BLI_spin_unlock(sound->spinlock); } -void sound_update_scene(Main *bmain, struct Scene *scene) +void BKE_sound_update_scene(Main *bmain, struct Scene *scene) { Object *ob; Base *base; @@ -727,38 +767,41 @@ void sound_update_scene(Main *bmain, struct Scene *scene) if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) { if (speaker->sound) { - AUD_moveSequence(strip->speaker_handle, (double)strip->start / FPS, FLT_MAX, 0); + AUD_SequenceEntry_move(strip->speaker_handle, (double)strip->start / FPS, FLT_MAX, 0); } else { - AUD_removeSequence(scene->sound_scene, strip->speaker_handle); + AUD_Sequence_remove(scene->sound_scene, strip->speaker_handle); strip->speaker_handle = NULL; } } else { if (speaker->sound) { - strip->speaker_handle = AUD_addSequence(scene->sound_scene, + strip->speaker_handle = AUD_Sequence_add(scene->sound_scene, speaker->sound->playback_handle, (double)strip->start / FPS, FLT_MAX, 0); - AUD_setRelativeSequence(strip->speaker_handle, 0); + AUD_SequenceEntry_setRelative(strip->speaker_handle, 0); } } if (strip->speaker_handle) { const bool mute = ((strip->flag & NLASTRIP_FLAG_MUTED) || (speaker->flag & SPK_MUTED)); AUD_addSet(new_set, strip->speaker_handle); - AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max, - speaker->volume_min, speaker->distance_max, - speaker->distance_reference, speaker->attenuation, - speaker->cone_angle_outer, speaker->cone_angle_inner, - speaker->cone_volume_outer); + AUD_SequenceEntry_setVolumeMaximum(strip->speaker_handle, speaker->volume_max); + AUD_SequenceEntry_setVolumeMinimum(strip->speaker_handle, speaker->volume_min); + AUD_SequenceEntry_setDistanceMaximum(strip->speaker_handle, speaker->distance_max); + AUD_SequenceEntry_setDistanceReference(strip->speaker_handle, speaker->distance_reference); + AUD_SequenceEntry_setAttenuation(strip->speaker_handle, speaker->attenuation); + AUD_SequenceEntry_setConeAngleOuter(strip->speaker_handle, speaker->cone_angle_outer); + AUD_SequenceEntry_setConeAngleInner(strip->speaker_handle, speaker->cone_angle_inner); + AUD_SequenceEntry_setConeVolumeOuter(strip->speaker_handle, speaker->cone_volume_outer); mat4_to_quat(quat, ob->obmat); - AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1); - AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1); - AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1); - AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1); - AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle); - AUD_muteSequence(strip->speaker_handle, mute); + AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1); + AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1); + AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1); + AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1); + AUD_SequenceEntry_setSound(strip->speaker_handle, speaker->sound->playback_handle); + AUD_SequenceEntry_setMuted(strip->speaker_handle, mute); } } } @@ -766,82 +809,101 @@ void sound_update_scene(Main *bmain, struct Scene *scene) } while ((handle = AUD_getSet(scene->speaker_handles))) { - AUD_removeSequence(scene->sound_scene, handle); + AUD_Sequence_remove(scene->sound_scene, handle); } if (scene->camera) { mat4_to_quat(quat, scene->camera->obmat); - AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1); - AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1); + AUD_Sequence_setAnimationData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1); + AUD_Sequence_setAnimationData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1); } AUD_destroySet(scene->speaker_handles); scene->speaker_handles = new_set; } -void *sound_get_factory(void *sound) +void *BKE_sound_get_factory(void *sound) { return ((bSound *)sound)->playback_handle; } /* stupid wrapper because AUD_C-API.h includes Python.h which makesrna doesn't like */ -float sound_get_length(bSound *sound) +float BKE_sound_get_length(bSound *sound) { AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); return info.length; } -bool sound_is_jack_supported(void) +char **BKE_sound_get_device_names(void) { + if (audio_device_names == NULL) { +#ifdef WITH_SYSTEM_AUDASPACE + audio_device_names = AUD_getDeviceNames(); +#else + static const char *names[] = { + "Null", "SDL", "OpenAL", "Jack", NULL + }; + audio_device_names = (char **)names; +#endif + } + + return audio_device_names; +} + +bool BKE_sound_is_jack_supported(void) +{ +#ifdef WITH_SYSTEM_AUDASPACE + return 1; +#else return (bool)AUD_isJackSupported(); +#endif } #else /* WITH_AUDASPACE */ #include "BLI_utildefines.h" -int sound_define_from_str(const char *UNUSED(str)) { return -1; } -void sound_force_device(int UNUSED(device)) {} -void sound_init_once(void) {} -void sound_init(struct Main *UNUSED(bmain)) {} -void sound_exit(void) {} -void sound_exit_once(void) {} -void sound_cache(struct bSound *UNUSED(sound)) {} -void sound_delete_cache(struct bSound *UNUSED(sound)) {} -void sound_load(struct Main *UNUSED(bmain), struct bSound *UNUSED(sound)) {} -void sound_create_scene(struct Scene *UNUSED(scene)) {} -void sound_destroy_scene(struct Scene *UNUSED(scene)) {} -void sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {} -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; } -void *sound_scene_add_scene_sound_defaults(struct Scene *UNUSED(scene), - struct Sequence *UNUSED(sequence)) { return NULL; } -void *sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence), int UNUSED(startframe), - int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } -void *sound_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) { return NULL; } -void sound_remove_scene_sound(struct Scene *UNUSED(scene), void *UNUSED(handle)) {} -void sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute)) {} -void sound_move_scene_sound(struct Scene *UNUSED(scene), void *UNUSED(handle), int UNUSED(startframe), - int UNUSED(endframe), int UNUSED(frameskip)) {} -void sound_move_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) {} -void sound_play_scene(struct Scene *UNUSED(scene)) {} -void sound_stop_scene(struct Scene *UNUSED(scene)) {} -void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {} -float sound_sync_scene(struct Scene *UNUSED(scene)) { return NAN_FLT; } -int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; } -void sound_read_waveform(struct bSound *UNUSED(sound)) {} -void sound_init_main(struct Main *UNUSED(bmain)) {} -void sound_set_cfra(int UNUSED(cfra)) {} -void sound_update_sequencer(struct Main *UNUSED(main), struct bSound *UNUSED(sound)) {} -void sound_update_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {} -void sound_update_scene_sound(void *UNUSED(handle), struct bSound *UNUSED(sound)) {} -void sound_update_scene_listener(struct Scene *UNUSED(scene)) {} -void sound_update_fps(struct Scene *UNUSED(scene)) {} -void sound_set_scene_sound_volume(void *UNUSED(handle), float UNUSED(volume), char UNUSED(animated)) {} -void sound_set_scene_sound_pan(void *UNUSED(handle), float UNUSED(pan), char UNUSED(animated)) {} -void sound_set_scene_volume(struct Scene *UNUSED(scene), float UNUSED(volume)) {} -void sound_set_scene_sound_pitch(void *UNUSED(handle), float UNUSED(pitch), char UNUSED(animated)) {} -float sound_get_length(struct bSound *UNUSED(sound)) { return 0; } -bool sound_is_jack_supported(void) { return false; } +void BKE_sound_force_device(const char *UNUSED(device)) {} +void BKE_sound_init_once(void) {} +void BKE_sound_init(struct Main *UNUSED(bmain)) {} +void BKE_sound_exit(void) {} +void BKE_sound_exit_once(void) {} +void BKE_sound_cache(struct bSound *UNUSED(sound)) {} +void BKE_sound_delete_cache(struct bSound *UNUSED(sound)) {} +void BKE_sound_load(struct Main *UNUSED(bmain), struct bSound *UNUSED(sound)) {} +void BKE_sound_create_scene(struct Scene *UNUSED(scene)) {} +void BKE_sound_destroy_scene(struct Scene *UNUSED(scene)) {} +void BKE_sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {} +void *BKE_sound_scene_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence), + int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } +void *BKE_sound_scene_add_scene_sound_defaults(struct Scene *UNUSED(scene), + struct Sequence *UNUSED(sequence)) { return NULL; } +void *BKE_sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence), int UNUSED(startframe), + int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } +void *BKE_sound_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) { return NULL; } +void BKE_sound_remove_scene_sound(struct Scene *UNUSED(scene), void *UNUSED(handle)) {} +void BKE_sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute)) {} +void BKE_sound_move_scene_sound(struct Scene *UNUSED(scene), void *UNUSED(handle), int UNUSED(startframe), + int UNUSED(endframe), int UNUSED(frameskip)) {} +void BKE_sound_move_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) {} +void BKE_sound_play_scene(struct Scene *UNUSED(scene)) {} +void BKE_sound_stop_scene(struct Scene *UNUSED(scene)) {} +void BKE_sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {} +float BKE_sound_sync_scene(struct Scene *UNUSED(scene)) { return NAN_FLT; } +int BKE_sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; } +void BKE_sound_read_waveform(struct bSound *sound, short *stop) { UNUSED_VARS(sound, stop); } +void BKE_sound_init_main(struct Main *UNUSED(bmain)) {} +void BKE_sound_set_cfra(int UNUSED(cfra)) {} +void BKE_sound_update_sequencer(struct Main *UNUSED(main), struct bSound *UNUSED(sound)) {} +void BKE_sound_update_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {} +void BKE_sound_update_scene_sound(void *UNUSED(handle), struct bSound *UNUSED(sound)) {} +void BKE_sound_update_scene_listener(struct Scene *UNUSED(scene)) {} +void BKE_sound_update_fps(struct Scene *UNUSED(scene)) {} +void BKE_sound_set_scene_sound_volume(void *UNUSED(handle), float UNUSED(volume), char UNUSED(animated)) {} +void BKE_sound_set_scene_sound_pan(void *UNUSED(handle), float UNUSED(pan), char UNUSED(animated)) {} +void BKE_sound_set_scene_volume(struct Scene *UNUSED(scene), float UNUSED(volume)) {} +void BKE_sound_set_scene_sound_pitch(void *UNUSED(handle), float UNUSED(pitch), char UNUSED(animated)) {} +float BKE_sound_get_length(struct bSound *UNUSED(sound)) { return 0; } +bool BKE_sound_is_jack_supported(void) { return false; } #endif /* WITH_AUDASPACE */ |