I have created a new component from scratch for Professional Music Driver files.
The alpha version works as in, it generates sound, however the sound is incredibly distorted. A reference console implementation using SDL plays the same file without a problem. So I think the problem must be in my foobar2000 wrapper code.
Before I release an alpha of the plugin and the code I'd like to get this distortion problem solved.
A long shot: is there a developer with more audio experience that can point me in the right direction simply by listening to the example file?
Some parameters:
- The driver outputs 16-bit signed integers in blocks of 512 stereo samples.
- Sample rate 44100 Hz
- 2 channels
This is the core of decode_run()
const uint32_t SamplesToRender = _Decoder->GetSampleCount();
const uint32_t ChannelCount = _Decoder->GetChannelCount();
audioChunk.set_data_size((t_size) SamplesToRender * ChannelCount);
audioChunk.set_channels(ChannelCount);
audioChunk.set_sample_rate(_SampleRate);
audio_sample * Samples = audioChunk.get_data();
size_t SamplesRendered =_Decoder->Render(Samples, SamplesToRender);
if (SamplesRendered == 0)
return false;
audioChunk.set_sample_count(SamplesRendered);
_SamplesRendered += SamplesRendered;
And this converts the samples to an audio chunk:
size_t PMDDecoder::Render(audio_sample * samples, size_t sampleCount) const noexcept
{
::getpcmdata(_Samples, (int) SampleCount);
audio_math::convert_from_int16(_Samples, SampleCount, samples, (audio_sample) 2.0);
return sampleCount;
}
Sample (512K)