From 863fa2c3ff72490ff6afeea449ec9ef759a6133e Mon Sep 17 00:00:00 2001 From: oioitff Date: Fri, 26 Apr 2013 22:24:18 +0800 Subject: [PATCH] Fix the channel volume. --- Core/HLE/__sceAudio.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index 7d58fc0489..c2cf868c7d 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -180,6 +180,14 @@ u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) return ret; } +static inline s16 clamp_s16(int i) { + if (i > 32767) + return 32767; + if (i < -32768) + return -32768; + return i; +} + // Mix samples from the various audio channels into a single sample queue. // This single sample queue is where __AudioMix should read from. If the sample queue is full, we should // just sleep the main emulator thread a little. @@ -207,8 +215,9 @@ void __AudioUpdate() { s16 sampleL = chans[i].sampleQueue.pop_front(); s16 sampleR = chans[i].sampleQueue.pop_front(); - mixBuffer[s * 2 + 0] += sampleL; - mixBuffer[s * 2 + 1] += sampleR; + // The channel volume should be done here? + mixBuffer[s * 2 + 0] += sampleL * (s32)chans[i].leftVolume >> 14; + mixBuffer[s * 2 + 1] += sampleR * (s32)chans[i].rightVolume >> 14; } else { @@ -234,8 +243,8 @@ void __AudioUpdate() if (outAudioQueue.room() >= hwBlockSize * 2) { // Push the mixed samples onto the output audio queue. for (int i = 0; i < hwBlockSize; i++) { - s32 sampleL = mixBuffer[i * 2 + 0] >> 2; // TODO - what factor? - s32 sampleR = mixBuffer[i * 2 + 1] >> 2; + s16 sampleL = clamp_s16(mixBuffer[i * 2 + 0]); + s16 sampleR = clamp_s16(mixBuffer[i * 2 + 1]); outAudioQueue.push((s16)sampleL); outAudioQueue.push((s16)sampleR);