diff options
| author | Lioncash <mathew1800@gmail.com> | 2015-05-09 23:50:45 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2015-05-11 01:55:50 -0400 |
| commit | 7b376abd3bd59eeeeddb3cdb6f0000e8c901ba1e (patch) | |
| tree | 5a505f6918542b28038b8319858353832ecf451a /Source/Core/AudioCommon/Mixer.cpp | |
| parent | 4920dbed13b0bef0e17fe0ad9d73b9f702a5e523 (diff) | |
Mixer: Convert volatile variables to atomics.
Diffstat (limited to 'Source/Core/AudioCommon/Mixer.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/Mixer.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp index 90f771d3fa..90fcbd06ae 100644 --- a/Source/Core/AudioCommon/Mixer.cpp +++ b/Source/Core/AudioCommon/Mixer.cpp @@ -4,7 +4,6 @@ #include "AudioCommon/AudioCommon.h" #include "AudioCommon/Mixer.h" -#include "Common/Atomic.h" #include "Common/CPUDetect.h" #include "Common/MathUtil.h" #include "Core/ConfigManager.h" @@ -31,8 +30,8 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo // so we will just ignore new written data while interpolating. // Without this cache, the compiler wouldn't be allowed to optimize the // interpolation loop. - u32 indexR = Common::AtomicLoad(m_indexR); - u32 indexW = Common::AtomicLoad(m_indexW); + u32 indexR = m_indexR.load(); + u32 indexW = m_indexW.load(); float numLeft = (float)(((indexW - indexR) & INDEX_MASK) / 2); m_numLeftI = (numLeft + m_numLeftI*(CONTROL_AVG-1)) / CONTROL_AVG; @@ -53,8 +52,8 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo const u32 ratio = (u32)(65536.0f * aid_sample_rate / (float)m_mixer->m_sampleRate); - s32 lvolume = m_LVolume; - s32 rvolume = m_RVolume; + s32 lvolume = m_LVolume.load(); + s32 rvolume = m_RVolume.load(); // TODO: consider a higher-quality resampling algorithm. for (; currentSample < numSamples * 2 && ((indexW-indexR) & INDEX_MASK) > 2; currentSample += 2) @@ -99,7 +98,7 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo } // Flush cached variable - Common::AtomicStore(m_indexR, indexR); + m_indexR.store(indexR); return numSamples; } @@ -130,11 +129,11 @@ void CMixer::MixerFifo::PushSamples(const short *samples, unsigned int num_sampl // Cache access in non-volatile variable // indexR isn't allowed to cache in the audio throttling loop as it // needs to get updates to not deadlock. - u32 indexW = Common::AtomicLoad(m_indexW); + u32 indexW = m_indexW.load(); // Check if we have enough free space // indexW == m_indexR results in empty buffer, so indexR must always be smaller than indexW - if (num_samples * 2 + ((indexW - Common::AtomicLoad(m_indexR)) & INDEX_MASK) >= MAX_SAMPLES * 2) + if (num_samples * 2 + ((indexW - m_indexR.load()) & INDEX_MASK) >= MAX_SAMPLES * 2) return; // AyuanX: Actual re-sampling work has been moved to sound thread @@ -151,9 +150,7 @@ void CMixer::MixerFifo::PushSamples(const short *samples, unsigned int num_sampl memcpy(&m_buffer[indexW & INDEX_MASK], samples, num_samples * 4); } - Common::AtomicAdd(m_indexW, num_samples * 2); - - return; + m_indexW.fetch_add(num_samples * 2); } void CMixer::PushSamples(const short *samples, unsigned int num_samples) @@ -215,6 +212,6 @@ void CMixer::MixerFifo::SetInputSampleRate(unsigned int rate) void CMixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume) { - m_LVolume = lvolume + (lvolume >> 7); - m_RVolume = rvolume + (rvolume >> 7); + m_LVolume.store(lvolume + (lvolume >> 7)); + m_RVolume.store(rvolume + (rvolume >> 7)); } |
