Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #666 from booto/audio-dma-sampling
AudioCommon/Mixer: Allow input sample rate changes
  • Loading branch information
delroth committed Jul 26, 2014
2 parents f343f41 + 7d920bb commit 6bd5fb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Source/Core/AudioCommon/Mixer.cpp
Expand Up @@ -181,11 +181,26 @@ void CMixer::PushStreamingSamples(const short *samples, unsigned int num_samples
m_streaming_mixer.PushSamples(samples, num_samples);
}

void CMixer::SetDMAInputSampleRate(unsigned int rate)
{
m_dma_mixer.SetInputSampleRate(rate);
}

void CMixer::SetStreamInputSampleRate(unsigned int rate)
{
m_streaming_mixer.SetInputSampleRate(rate);
}

void CMixer::SetStreamingVolume(unsigned int lvolume, unsigned int rvolume)
{
m_streaming_mixer.SetVolume(lvolume, rvolume);
}

void CMixer::MixerFifo::SetInputSampleRate(unsigned int rate)
{
m_input_sample_rate = rate;
}

void CMixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume)
{
m_LVolume = lvolume + (lvolume >> 7);
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/AudioCommon/Mixer.h
Expand Up @@ -41,6 +41,9 @@ class CMixer {
virtual void PushSamples(const short* samples, unsigned int num_samples);
virtual void PushStreamingSamples(const short* samples, unsigned int num_samples);
unsigned int GetSampleRate() const { return m_sampleRate; }

void SetDMAInputSampleRate(unsigned int rate);
void SetStreamInputSampleRate(unsigned int rate);
void SetStreamingVolume(unsigned int lvolume, unsigned int rvolume);

void SetThrottle(bool use) { m_throttle = use;}
Expand Down Expand Up @@ -97,6 +100,7 @@ class CMixer {
}
void PushSamples(const short* samples, unsigned int num_samples);
unsigned int Mix(short* samples, unsigned int numSamples, bool consider_framelimit = true);
void SetInputSampleRate(unsigned int rate);
void SetVolume(unsigned int lvolume, unsigned int rvolume);
private:
CMixer *m_mixer;
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/Core/HW/AudioInterface.cpp
Expand Up @@ -183,20 +183,22 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
// Set frequency of streaming audio
if (tmpAICtrl.AISFR != m_Control.AISFR)
{
// AISFR rates below are intentionally inverted wrt yagcd
DEBUG_LOG(AUDIO_INTERFACE, "Change AISFR to %s", tmpAICtrl.AISFR ? "48khz":"32khz");
m_Control.AISFR = tmpAICtrl.AISFR;
g_AISSampleRate = tmpAICtrl.AISFR ? 48000 : 32000;
soundStream->GetMixer()->SetStreamInputSampleRate(g_AISSampleRate);
g_CPUCyclesPerSample = SystemTimers::GetTicksPerSecond() / g_AISSampleRate;
}
// Set frequency of DMA
if (tmpAICtrl.AIDFR != m_Control.AIDFR)
{
DEBUG_LOG(AUDIO_INTERFACE, "Change AIDFR to %s", tmpAICtrl.AIDFR ? "32khz":"48khz");
m_Control.AIDFR = tmpAICtrl.AIDFR;
g_AIDSampleRate = tmpAICtrl.AIDFR ? 32000 : 48000;
soundStream->GetMixer()->SetDMAInputSampleRate(g_AIDSampleRate);
}

g_AISSampleRate = tmpAICtrl.AISFR ? 48000 : 32000;
g_AIDSampleRate = tmpAICtrl.AIDFR ? 32000 : 48000;

g_CPUCyclesPerSample = SystemTimers::GetTicksPerSecond() / g_AISSampleRate;

// Streaming counter
if (tmpAICtrl.PSTAT != m_Control.PSTAT)
Expand Down

0 comments on commit 6bd5fb3

Please sign in to comment.