From: Anton Baskanov baskanov@gmail.com
--- dlls/dmsynth/synth.c | 30 +++++++++++++++++++----------- dlls/dmsynth/tests/dmsynth.c | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/dlls/dmsynth/synth.c b/dlls/dmsynth/synth.c index cc095a5e89d..5b93ff5da6f 100644 --- a/dlls/dmsynth/synth.c +++ b/dlls/dmsynth/synth.c @@ -219,11 +219,9 @@ struct wave
WAVEFORMATEX format; UINT sample_count; - short samples[]; + short *samples; };
-C_ASSERT(sizeof(struct wave) == offsetof(struct wave, samples[0])); - static void wave_addref(struct wave *wave) { InterlockedIncrement(&wave->ref); @@ -237,6 +235,7 @@ static void wave_release(struct wave *wave) if (wave->callback) wave->callback(wave, wave->user_data); delete_fluid_sample(wave->fluid_sample); + free(wave->samples); free(wave); } } @@ -823,6 +822,7 @@ static HRESULT synth_download_wave(struct synth *This, DMUS_DOWNLOADINFO *info, DMUS_WAVEDATA *wave_data = (DMUS_WAVEDATA *)(data + offsets[wave_info->ulWaveDataIdx]); struct wave *wave; UINT sample_count; + short *samples;
if (TRACE_ON(dmsynth)) { @@ -841,25 +841,32 @@ static HRESULT synth_download_wave(struct synth *This, DMUS_DOWNLOADINFO *info, if (wave_info->WaveformatEx.wFormatTag != WAVE_FORMAT_PCM) return DMUS_E_NOTPCM;
sample_count = wave_data->cbSize / wave_info->WaveformatEx.nBlockAlign; - if (!(wave = calloc(1, offsetof(struct wave, samples[sample_count])))) return E_OUTOFMEMORY; + if (!(wave = calloc(1, sizeof(struct wave)))) return E_OUTOFMEMORY; wave->ref = 1; wave->id = info->dwDLId; wave->format = wave_info->WaveformatEx; wave->sample_count = sample_count;
- if (wave_info->WaveformatEx.nBlockAlign == 1) + if (wave_info->WaveformatEx.nBlockAlign == 2) { - while (sample_count--) + samples = (short *)wave_data->byData; + } + else + { + if (!(wave->samples = malloc(sample_count * sizeof(short)))) { - short sample = (wave_data->byData[sample_count] - 0x80) << 8; - wave->samples[sample_count] = sample; + WARN("Failed to allocate FluidSynth sample data\n"); + free(wave); + return FLUID_FAILED; } + samples = wave->samples; } - else if (wave_info->WaveformatEx.nBlockAlign == 2) + + if (wave_info->WaveformatEx.nBlockAlign == 1) { while (sample_count--) { - short sample = ((short *)wave_data->byData)[sample_count]; + short sample = (wave_data->byData[sample_count] - 0x80) << 8; wave->samples[sample_count] = sample; } } @@ -881,7 +888,7 @@ static HRESULT synth_download_wave(struct synth *This, DMUS_DOWNLOADINFO *info,
/* Although the doc says there should be 8-frame padding around the data, * FluidSynth doesn't actually require this since version 1.0.8. */ - fluid_sample_set_sound_data(wave->fluid_sample, wave->samples, NULL, wave->sample_count, + fluid_sample_set_sound_data(wave->fluid_sample, samples, NULL, wave->sample_count, wave->format.nSamplesPerSec, FALSE);
EnterCriticalSection(&This->cs); @@ -922,6 +929,7 @@ static HRESULT WINAPI synth_Download(IDirectMusicSynth8 *iface, HANDLE *ret_hand case DMUS_DOWNLOADINFO_INSTRUMENT2: return synth_download_instrument(This, info, offsets, data, ret_handle); case DMUS_DOWNLOADINFO_WAVE: + *ret_free = FALSE; return synth_download_wave(This, info, offsets, data, ret_handle); case DMUS_DOWNLOADINFO_WAVEARTICULATION: FIXME("Download type DMUS_DOWNLOADINFO_WAVEARTICULATION not yet supported\n"); diff --git a/dlls/dmsynth/tests/dmsynth.c b/dlls/dmsynth/tests/dmsynth.c index b0dd4d8838b..696eceda612 100644 --- a/dlls/dmsynth/tests/dmsynth.c +++ b/dlls/dmsynth/tests/dmsynth.c @@ -1200,7 +1200,7 @@ static void test_IDirectMusicSynth(void) hr = IDirectMusicSynth_Download(synth, &wave_handle, &wave_download, &can_free); ok(hr == S_OK, "got %#lx\n", hr); ok(!!wave_handle, "got %p\n", wave_handle); - todo_wine ok(can_free == FALSE, "got %u\n", can_free); + ok(can_free == FALSE, "got %u\n", can_free);
can_free = 0xdeadbeef; instrument_handle = NULL;