Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/sound.c
| Show First 20 Lines • Show All 405 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (sound->cache) { | if (sound->cache) { | ||||
| AUD_Sound_free(sound->cache); | AUD_Sound_free(sound->cache); | ||||
| sound->cache = NULL; | sound->cache = NULL; | ||||
| sound->playback_handle = sound->handle; | sound->playback_handle = sound->handle; | ||||
| } | } | ||||
| } | } | ||||
| static void sound_load_audio(Main *bmain, bSound *sound) | static void sound_load_audio(Main *bmain, bSound *sound, bool free_waveform) | ||||
| { | { | ||||
| if (sound->cache) { | if (sound->cache) { | ||||
| AUD_Sound_free(sound->cache); | AUD_Sound_free(sound->cache); | ||||
| sound->cache = NULL; | sound->cache = NULL; | ||||
| } | } | ||||
| if (sound->handle) { | if (sound->handle) { | ||||
| AUD_Sound_free(sound->handle); | AUD_Sound_free(sound->handle); | ||||
| sound->handle = NULL; | sound->handle = NULL; | ||||
| sound->playback_handle = NULL; | sound->playback_handle = NULL; | ||||
| } | } | ||||
| if (free_waveform) { | |||||
| BKE_sound_free_waveform(sound); | BKE_sound_free_waveform(sound); | ||||
| } | |||||
| /* XXX unused currently */ | /* XXX unused currently */ | ||||
| # if 0 | # if 0 | ||||
| switch (sound->type) { | switch (sound->type) { | ||||
| case SOUND_TYPE_FILE: | case SOUND_TYPE_FILE: | ||||
| # endif | # endif | ||||
| { | { | ||||
| char fullpath[FILE_MAX]; | char fullpath[FILE_MAX]; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | # endif | ||||
| else { | else { | ||||
| sound->playback_handle = sound->handle; | sound->playback_handle = sound->handle; | ||||
| } | } | ||||
| } | } | ||||
| void BKE_sound_load(Main *bmain, bSound *sound) | void BKE_sound_load(Main *bmain, bSound *sound) | ||||
| { | { | ||||
| sound_verify_evaluated_id(&sound->id); | sound_verify_evaluated_id(&sound->id); | ||||
| sound_load_audio(bmain, sound); | sound_load_audio(bmain, sound, true); | ||||
| } | } | ||||
| AUD_Device *BKE_sound_mixdown(Scene *scene, AUD_DeviceSpecs specs, int start, float volume) | AUD_Device *BKE_sound_mixdown(Scene *scene, AUD_DeviceSpecs specs, int start, float volume) | ||||
| { | { | ||||
| sound_verify_evaluated_id(&scene->id); | sound_verify_evaluated_id(&scene->id); | ||||
| return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); | return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | void BKE_sound_free_waveform(bSound *sound) | ||||
| sound->tags &= ~SOUND_TAGS_WAVEFORM_NO_RELOAD; | sound->tags &= ~SOUND_TAGS_WAVEFORM_NO_RELOAD; | ||||
| } | } | ||||
| void BKE_sound_read_waveform(Main *bmain, bSound *sound, short *stop) | void BKE_sound_read_waveform(Main *bmain, bSound *sound, short *stop) | ||||
| { | { | ||||
| bool need_close_audio_handles = false; | bool need_close_audio_handles = false; | ||||
| if (sound->playback_handle == NULL) { | if (sound->playback_handle == NULL) { | ||||
| /* TODO(sergey): Make it fully independent audio handle. */ | /* TODO(sergey): Make it fully independent audio handle. */ | ||||
| sound_load_audio(bmain, sound); | sound_load_audio(bmain, sound, true); | ||||
| need_close_audio_handles = true; | need_close_audio_handles = true; | ||||
| } | } | ||||
| AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); | AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); | ||||
| SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); | SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); | ||||
| if (info.length > 0) { | if (info.length > 0) { | ||||
| int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; | int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; | ||||
| ▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| bool BKE_sound_info_get(struct Main *main, struct bSound *sound, SoundInfo *sound_info) | bool BKE_sound_info_get(struct Main *main, struct bSound *sound, SoundInfo *sound_info) | ||||
| { | { | ||||
| if (sound->playback_handle != NULL) { | if (sound->playback_handle != NULL) { | ||||
| return sound_info_from_playback_handle(sound->playback_handle, sound_info); | return sound_info_from_playback_handle(sound->playback_handle, sound_info); | ||||
| } | } | ||||
| /* TODO(sergey): Make it fully independent audio handle. */ | /* TODO(sergey): Make it fully independent audio handle. */ | ||||
| sound_load_audio(main, sound); | /* Don't free waveforms during non-destructive queries. | ||||
| * This causes unnecessary recalculation - see T69921 */ | |||||
| sound_load_audio(main, sound, false); | |||||
sybren: This could use a comment to explain why this doesn't cause a memory leak. And maybe also… | |||||
| const bool result = sound_info_from_playback_handle(sound->playback_handle, sound_info); | const bool result = sound_info_from_playback_handle(sound->playback_handle, sound_info); | ||||
| sound_free_audio(sound); | sound_free_audio(sound); | ||||
| return result; | return result; | ||||
| } | } | ||||
| #else /* WITH_AUDASPACE */ | #else /* WITH_AUDASPACE */ | ||||
| # include "BLI_utildefines.h" | # include "BLI_utildefines.h" | ||||
| ▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines | |||||
This could use a comment to explain why this doesn't cause a memory leak. And maybe also document the reason why memory shouldn't be freed here, as it's not instantly obvious.