Minor audio optimization

This commit is contained in:
Henrik Rydgard 2013-07-06 22:21:29 +02:00
parent c71ae64454
commit acf94a35f8
3 changed files with 10 additions and 5 deletions

View file

@ -629,11 +629,13 @@ u32 _AtracDecodeData(int atracID, u8* outbuf, u32 *SamplesNum, u32* finish, int
int gotsize = atrac->sampleQueue.pop_front(buf, ATRAC3PLUS_MAX_SAMPLES * sizeof(s16) * atrac->atracChannels);
numSamples = gotsize / sizeof(s16) / atrac->atracChannels;
s16* in = (s16*)buf;
int volumeShift = (MAX_CONFIG_VOLUME - g_Config.iBGMVolume);
if (volumeShift < 0) volumeShift = 0;
for (u32 i = 0; i < numSamples; i++) {
s16 sampleL = *in++ >> (MAX_CONFIG_VOLUME - g_Config.iBGMVolume); // Max = 4 and Min = 0(no shift)
s16 sampleL = *in++ >> volumeShift; // Max = 4 and Min = 0(no shift)
s16 sampleR = sampleL;
if (atrac->atracChannels == 2)
sampleR = *in++ >> (MAX_CONFIG_VOLUME - g_Config.iBGMVolume); // Max = 4 and Min = 0(no shift)
sampleR = *in++ >> volumeShift; // Max = 4 and Min = 0(no shift)
*out++ = sampleL;
if (atrac->atracOutputChannels == 2)
*out++ = sampleR;

View file

@ -413,7 +413,9 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) {
// Resample to the correct pitch, writing exactly "grainSize" samples.
u32 sampleFrac = voice.sampleFrac;
const int MAX_CONFIG_VOLUME = 17;
const int MAX_CONFIG_VOLUME = 17; // 12 + 5
int volumeShift = (MAX_CONFIG_VOLUME - g_Config.iSEVolume);
if (volumeShift < 0) volumeShift = 0;
for (int i = 0; i < grainSize; i++) {
// For now: nearest neighbour, not even using the resample history at all.
int sample = resampleBuffer[sampleFrac / PSP_SAS_PITCH_BASE + 2];
@ -431,8 +433,8 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) {
// We mix into this 32-bit temp buffer and clip in a second loop
// Ideally, the shift right should be there too but for now I'm concerned about
// not overflowing.
mixBuffer[i * 2] += (sample * voice.volumeLeft ) >> (MAX_CONFIG_VOLUME - g_Config.iSEVolume); // Max = 16 and Min = 12(default)
mixBuffer[i * 2 + 1] += (sample * voice.volumeRight) >> (MAX_CONFIG_VOLUME - g_Config.iSEVolume); // Max = 16 and Min = 12(default)
mixBuffer[i * 2] += (sample * voice.volumeLeft ) >> volumeShift; // Max = 16 and Min = 12(default)
mixBuffer[i * 2 + 1] += (sample * voice.volumeRight) >> volumeShift; // Max = 16 and Min = 12(default)
sendBuffer[i * 2] += sample * voice.volumeLeftSend >> 12;
sendBuffer[i * 2 + 1] += sample * voice.volumeRightSend >> 12;
voice.envelope.Step();

View file

@ -820,6 +820,7 @@ void AudioScreen::render() {
if (UIButton(GEN_ID, hlinear2, 50, 0, a->T("+1"), ALIGN_LEFT))
if (g_Config.iSEVolume < 5)
g_Config.iSEVolume += 1;
y+=10;
} else