AudioCommon: restore support for DTK volume setting.
This commit is contained in:
parent
1f604e87be
commit
ca0203a1cc
|
@ -54,6 +54,9 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo
|
||||||
static u32 frac = 0;
|
static u32 frac = 0;
|
||||||
const u32 ratio = (u32)( 65536.0f * aid_sample_rate / (float)m_mixer->m_sampleRate );
|
const u32 ratio = (u32)( 65536.0f * aid_sample_rate / (float)m_mixer->m_sampleRate );
|
||||||
|
|
||||||
|
s32 lvolume = m_LVolume;
|
||||||
|
s32 rvolume = m_RVolume;
|
||||||
|
|
||||||
// TODO: consider a higher-quality resampling algorithm.
|
// TODO: consider a higher-quality resampling algorithm.
|
||||||
for (; currentSample < numSamples*2 && ((indexW-indexR) & INDEX_MASK) > 2; currentSample+=2) {
|
for (; currentSample < numSamples*2 && ((indexW-indexR) & INDEX_MASK) > 2; currentSample+=2) {
|
||||||
u32 indexR2 = indexR + 2; //next sample
|
u32 indexR2 = indexR + 2; //next sample
|
||||||
|
@ -61,6 +64,7 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo
|
||||||
s16 l1 = Common::swap16(m_buffer[indexR & INDEX_MASK]); //current
|
s16 l1 = Common::swap16(m_buffer[indexR & INDEX_MASK]); //current
|
||||||
s16 l2 = Common::swap16(m_buffer[indexR2 & INDEX_MASK]); //next
|
s16 l2 = Common::swap16(m_buffer[indexR2 & INDEX_MASK]); //next
|
||||||
int sampleL = ((l1 << 16) + (l2 - l1) * (u16)frac) >> 16;
|
int sampleL = ((l1 << 16) + (l2 - l1) * (u16)frac) >> 16;
|
||||||
|
sampleL = (sampleL * lvolume) >> 8;
|
||||||
sampleL += samples[currentSample + 1];
|
sampleL += samples[currentSample + 1];
|
||||||
MathUtil::Clamp(&sampleL, -32767, 32767);
|
MathUtil::Clamp(&sampleL, -32767, 32767);
|
||||||
samples[currentSample+1] = sampleL;
|
samples[currentSample+1] = sampleL;
|
||||||
|
@ -68,6 +72,7 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo
|
||||||
s16 r1 = Common::swap16(m_buffer[(indexR + 1) & INDEX_MASK]); //current
|
s16 r1 = Common::swap16(m_buffer[(indexR + 1) & INDEX_MASK]); //current
|
||||||
s16 r2 = Common::swap16(m_buffer[(indexR2 + 1) & INDEX_MASK]); //next
|
s16 r2 = Common::swap16(m_buffer[(indexR2 + 1) & INDEX_MASK]); //next
|
||||||
int sampleR = ((r1 << 16) + (r2 - r1) * (u16)frac) >> 16;
|
int sampleR = ((r1 << 16) + (r2 - r1) * (u16)frac) >> 16;
|
||||||
|
sampleR = (sampleR * rvolume) >> 8;
|
||||||
sampleR += samples[currentSample];
|
sampleR += samples[currentSample];
|
||||||
MathUtil::Clamp(&sampleR, -32767, 32767);
|
MathUtil::Clamp(&sampleR, -32767, 32767);
|
||||||
samples[currentSample] = sampleR;
|
samples[currentSample] = sampleR;
|
||||||
|
@ -81,6 +86,8 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo
|
||||||
short s[2];
|
short s[2];
|
||||||
s[0] = Common::swap16(m_buffer[(indexR - 1) & INDEX_MASK]);
|
s[0] = Common::swap16(m_buffer[(indexR - 1) & INDEX_MASK]);
|
||||||
s[1] = Common::swap16(m_buffer[(indexR - 2) & INDEX_MASK]);
|
s[1] = Common::swap16(m_buffer[(indexR - 2) & INDEX_MASK]);
|
||||||
|
s[0] = (s[0] * lvolume) >> 8;
|
||||||
|
s[1] = (s[1] * rvolume) >> 8;
|
||||||
for (; currentSample < numSamples * 2; currentSample += 2)
|
for (; currentSample < numSamples * 2; currentSample += 2)
|
||||||
{
|
{
|
||||||
int sampleR = s[0] + samples[currentSample];
|
int sampleR = s[0] + samples[currentSample];
|
||||||
|
@ -174,3 +181,14 @@ void CMixer::PushStreamingSamples(const short *samples, unsigned int num_samples
|
||||||
{
|
{
|
||||||
m_streaming_mixer.PushSamples(samples, num_samples);
|
m_streaming_mixer.PushSamples(samples, num_samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMixer::SetStreamingVolume(unsigned int lvolume, unsigned int rvolume)
|
||||||
|
{
|
||||||
|
m_streaming_mixer.SetVolume(lvolume, rvolume);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume)
|
||||||
|
{
|
||||||
|
m_LVolume = lvolume + (lvolume >> 7);
|
||||||
|
m_RVolume = rvolume + (rvolume >> 7);
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
virtual void PushSamples(const short* samples, unsigned int num_samples);
|
virtual void PushSamples(const short* samples, unsigned int num_samples);
|
||||||
virtual void PushStreamingSamples(const short* samples, unsigned int num_samples);
|
virtual void PushStreamingSamples(const short* samples, unsigned int num_samples);
|
||||||
unsigned int GetSampleRate() const { return m_sampleRate; }
|
unsigned int GetSampleRate() const { return m_sampleRate; }
|
||||||
|
void SetStreamingVolume(unsigned int lvolume, unsigned int rvolume);
|
||||||
|
|
||||||
void SetThrottle(bool use) { m_throttle = use;}
|
void SetThrottle(bool use) { m_throttle = use;}
|
||||||
|
|
||||||
|
@ -88,17 +89,23 @@ protected:
|
||||||
, m_indexW(0)
|
, m_indexW(0)
|
||||||
, m_indexR(0)
|
, m_indexR(0)
|
||||||
, m_numLeftI(0.0f)
|
, m_numLeftI(0.0f)
|
||||||
|
, m_LVolume(256)
|
||||||
|
, m_RVolume(256)
|
||||||
{
|
{
|
||||||
memset(m_buffer, 0, sizeof(m_buffer));
|
memset(m_buffer, 0, sizeof(m_buffer));
|
||||||
}
|
}
|
||||||
void PushSamples(const short* samples, unsigned int num_samples);
|
void PushSamples(const short* samples, unsigned int num_samples);
|
||||||
unsigned int Mix(short* samples, unsigned int numSamples, bool consider_framelimit = true);
|
unsigned int Mix(short* samples, unsigned int numSamples, bool consider_framelimit = true);
|
||||||
|
void SetVolume(unsigned int lvolume, unsigned int rvolume);
|
||||||
private:
|
private:
|
||||||
CMixer *m_mixer;
|
CMixer *m_mixer;
|
||||||
unsigned m_input_sample_rate;
|
unsigned m_input_sample_rate;
|
||||||
short m_buffer[MAX_SAMPLES * 2];
|
short m_buffer[MAX_SAMPLES * 2];
|
||||||
volatile u32 m_indexW;
|
volatile u32 m_indexW;
|
||||||
volatile u32 m_indexR;
|
volatile u32 m_indexR;
|
||||||
|
// Volume ranges from 0-256
|
||||||
|
volatile s32 m_LVolume;
|
||||||
|
volatile s32 m_RVolume;
|
||||||
float m_numLeftI;
|
float m_numLeftI;
|
||||||
};
|
};
|
||||||
MixerFifo m_dma_mixer;
|
MixerFifo m_dma_mixer;
|
||||||
|
|
|
@ -50,6 +50,8 @@ This file mainly deals with the [Drive I/F], however [AIDFR] controls
|
||||||
TODO maybe the files should be merged?
|
TODO maybe the files should be merged?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "AudioCommon/AudioCommon.h"
|
||||||
|
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
#include "Common/MathUtil.h"
|
#include "Common/MathUtil.h"
|
||||||
|
|
||||||
|
@ -232,7 +234,10 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
|
||||||
|
|
||||||
mmio->Register(base | AI_VOLUME_REGISTER,
|
mmio->Register(base | AI_VOLUME_REGISTER,
|
||||||
MMIO::DirectRead<u32>(&m_Volume.hex),
|
MMIO::DirectRead<u32>(&m_Volume.hex),
|
||||||
MMIO::DirectWrite<u32>(&m_Volume.hex)
|
MMIO::ComplexWrite<u32>([](u32, u32 val) {
|
||||||
|
m_Volume.hex = val;
|
||||||
|
soundStream->GetMixer()->SetStreamingVolume(m_Volume.left, m_Volume.right);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
mmio->Register(base | AI_SAMPLE_COUNTER,
|
mmio->Register(base | AI_SAMPLE_COUNTER,
|
||||||
|
|
Loading…
Reference in New Issue