diff --git a/include/audio/hle_core.hpp b/include/audio/hle_core.hpp index c57f221e0..b59dc811c 100644 --- a/include/audio/hle_core.hpp +++ b/include/audio/hle_core.hpp @@ -176,6 +176,7 @@ namespace Audio { // Decode an entire buffer worth of audio void decodeBuffer(DSPSource& source); + SampleBuffer decodePCM8(const u8* data, usize sampleCount, Source& source); SampleBuffer decodePCM16(const u8* data, usize sampleCount, Source& source); SampleBuffer decodeADPCM(const u8* data, usize sampleCount, Source& source); diff --git a/src/core/audio/hle_core.cpp b/src/core/audio/hle_core.cpp index 146c7bdfb..12c8f4c81 100644 --- a/src/core/audio/hle_core.cpp +++ b/src/core/audio/hle_core.cpp @@ -355,7 +355,7 @@ namespace Audio { } switch (buffer.format) { - case SampleFormat::PCM8: Helpers::warn("Unimplemented sample format!"); break; + case SampleFormat::PCM8: source.currentSamples = decodePCM8(data, buffer.sampleCount, source); break; case SampleFormat::PCM16: source.currentSamples = decodePCM16(data, buffer.sampleCount, source); break; case SampleFormat::ADPCM: source.currentSamples = decodeADPCM(data, buffer.sampleCount, source); break; @@ -406,6 +406,26 @@ namespace Audio { } } + HLE_DSP::SampleBuffer HLE_DSP::decodePCM8(const u8* data, usize sampleCount, Source& source) { + SampleBuffer decodedSamples(sampleCount); + + if (source.sourceType == SourceType::Stereo) { + for (usize i = 0; i < sampleCount; i++) { + const s16 left = s16(u16(*data++) << 8); + const s16 right = s16(u16(*data++) << 8); + decodedSamples[i] = {left, right}; + } + } else { + // Mono + for (usize i = 0; i < sampleCount; i++) { + const s16 sample = s16(u16(*data++) << 8); + decodedSamples[i] = {sample, sample}; + } + } + + return decodedSamples; + } + HLE_DSP::SampleBuffer HLE_DSP::decodePCM16(const u8* data, usize sampleCount, Source& source) { SampleBuffer decodedSamples(sampleCount); const s16* data16 = reinterpret_cast(data);