Skip to content

Commit

Permalink
Merge pull request #525 from wheremyfoodat/bleh
Browse files Browse the repository at this point in the history
HLE DSP: Add PCM8 audio decoding
  • Loading branch information
wheremyfoodat committed Jul 2, 2024
2 parents eacf290 + 800c11f commit 5b408e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/audio/hle_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 21 additions & 1 deletion src/core/audio/hle_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<const s16*>(data);
Expand Down

0 comments on commit 5b408e7

Please sign in to comment.