diff options
Diffstat (limited to 'source/blender/blenkernel/intern/sound.c')
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index da6ead06d98..3c7b01f9052 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" @@ -116,6 +117,12 @@ void BKE_sound_free(bSound *sound) } sound_free_waveform(sound); + + if (sound->mutex) { + BLI_mutex_free(sound->mutex); + sound->mutex = NULL; + } + #endif /* WITH_AUDASPACE */ } @@ -296,12 +303,6 @@ void sound_cache(bSound *sound) 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) { sound->flags &= ~SOUND_FLAGS_CACHING; @@ -680,22 +681,40 @@ void sound_free_waveform(bSound *sound) sound->waveform = NULL; } -void sound_read_waveform(bSound *sound) +void sound_read_waveform(bSound *sound, bool locked, short *stop) { AUD_SoundInfo info; - + SoundWaveform *waveform = NULL; + info = AUD_getInfo(sound->playback_handle); - + if (info.length > 0) { - SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; - + + waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); 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); + + if (*stop) { + MEM_freeN(waveform->data); + MEM_freeN(waveform); + if (locked) + BLI_mutex_lock(sound->mutex); + sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; + if (locked) + BLI_mutex_unlock(sound->mutex); + return; + } + sound_free_waveform(sound); - sound->waveform = waveform; } + + if (locked) + BLI_mutex_lock(sound->mutex); + sound->waveform = waveform; + sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; + if (locked) + BLI_mutex_unlock(sound->mutex); } void sound_update_scene(Main *bmain, struct Scene *scene) @@ -830,7 +849,7 @@ 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_read_waveform(struct bSound *sound, bool locked, short *stop) { UNUSED_VARS(sound, locked, stop); } 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)) {} |