diff options
| author | ayuanx <ayuanx@gmail.com> | 2009-12-25 11:59:04 +0000 |
|---|---|---|
| committer | ayuanx <ayuanx@gmail.com> | 2009-12-25 11:59:04 +0000 |
| commit | 06218e9ebb2c4b7e6c4122a497fecba4e0e1d049 (patch) | |
| tree | c61c58c919e646e81c6a4f3ccc159bb5b423cddc /Source/Core/AudioCommon | |
| parent | eddafd450eb9b97c96499c490142062fe6b8b17d (diff) | |
Sound System Rework: Phase 2 (cont'ed)
. Fixed super fast refresh rate issue
. Recovered <TAB> shortcut key for ThrottleSkipping
. Removed redundant "soundstream->Update()" in DSPLLE
(Thanks to LordMark)
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4728 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/AudioCommon')
| -rw-r--r-- | Source/Core/AudioCommon/Src/DSoundStream.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/Mixer.cpp | 62 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/Mixer.h | 20 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/NullSoundStream.h | 2 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/OpenALStream.h | 4 |
5 files changed, 28 insertions, 62 deletions
diff --git a/Source/Core/AudioCommon/Src/DSoundStream.cpp b/Source/Core/AudioCommon/Src/DSoundStream.cpp index dc451eddb7..2e6cd69146 100644 --- a/Source/Core/AudioCommon/Src/DSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/DSoundStream.cpp @@ -111,7 +111,7 @@ void DSound::SoundLoop() int numBytesToRender = FIX128(ModBufferSize(currentPos - lastPos)); if (numBytesToRender >= 256) { - if (numBytesToRender > sizeof(realtimeBuffer) * sizeof(short)) + if (numBytesToRender > sizeof(realtimeBuffer)) PanicAlert("soundThread: too big render call"); m_mixer->Mix(realtimeBuffer, numBytesToRender / 4); WriteDataToBuffer(lastPos, (char*)realtimeBuffer, numBytesToRender); diff --git a/Source/Core/AudioCommon/Src/Mixer.cpp b/Source/Core/AudioCommon/Src/Mixer.cpp index 00b3a2587b..13ccb4b48a 100644 --- a/Source/Core/AudioCommon/Src/Mixer.cpp +++ b/Source/Core/AudioCommon/Src/Mixer.cpp @@ -17,7 +17,6 @@ #include "Atomic.h" - #include "Mixer.h" #include "AudioCommon.h" @@ -41,37 +40,13 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) numLeft = (numLeft > numSamples) ? numSamples : numLeft; // Do re-sampling if needed - if (m_sampleRate == m_dspSampleRate) + if (m_sampleRate == 32000) { for (unsigned int i = 0; i < numLeft * 2; i++) samples[i] = Common::swap16(m_buffer[(m_indexR + i) & INDEX_MASK]); m_indexR += numLeft * 2; } - else if (m_sampleRate < m_dspSampleRate) // If down-sampling needed - { - _dbg_assert_msg_(DSPHLE, !(numSamples % 2), "Number of Samples: %i must be even!", numSamples); - - short *pDest = samples; - int last_l, last_r, cur_l, cur_r; - - for (unsigned int i = 0; i < numLeft * 3 / 2; i++) - { - cur_l = Common::swap16(m_buffer[(m_indexR + i * 2) & INDEX_MASK]); - cur_r = Common::swap16(m_buffer[(m_indexR + i * 2 + 1) & INDEX_MASK]); - - if (i % 3) - { - *pDest++ = (last_l + cur_r) / 2; - *pDest++ = (last_r + cur_r) / 2; - } - - last_l = cur_l; - last_r = cur_r; - } - - m_indexR += numLeft * 2 * 3 / 2; - } - else if (m_sampleRate > m_dspSampleRate) + else { // AyuanX: Up-sampling is not implemented yet PanicAlert("Mixer: Up-sampling is not implemented yet!"); @@ -143,16 +118,8 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) if (numSamples > numLeft) memset(&samples[numLeft * 2], 0, (numSamples - numLeft) * 4); - // Add the HLE sound - if (m_sampleRate < m_dspSampleRate) - { - PanicAlert("Mixer: DSPHLE down-sampling is not implemented yet!\n" - "Usually no game should require this, please report!"); - } - else - { - Premix(samples, numSamples, m_sampleRate); - } + // Add the DSPHLE sound, re-sampling is done inside + Premix(samples, numSamples); // Add the DTK Music if (m_EnableDTKMusic) @@ -161,19 +128,17 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) g_dspInitialize.pGetAudioStreaming(samples, numSamples, m_sampleRate); } - Common::AtomicAdd(m_numSamples, -(int)numLeft); + Common::AtomicAdd(m_numSamples, -(s32)numLeft); return numSamples; } -void CMixer::PushSamples(short *samples, unsigned int num_samples, unsigned int sample_rate) +void CMixer::PushSamples(short *samples, unsigned int num_samples) { // The auto throttle function. This loop will put a ceiling on the CPU MHz. if (m_throttle) { - // AyuanX: Remember to reserve "num_samples * 1.5" free sample space at least! - // Becuse we may do re-sampling later while (Common::AtomicLoad(m_numSamples) >= MAX_SAMPLES - RESERVED_SAMPLES) { if (g_dspInitialize.pEmulatorState) @@ -181,8 +146,12 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples, unsigned int if (*g_dspInitialize.pEmulatorState != 0) break; } - soundStream->Update(); + // Shortcut key for Throttle Skipping + #ifdef _WIN32 + if (GetAsyncKeyState(VK_TAB)) break;; + #endif SLEEP(1); + soundStream->Update(); } } @@ -191,7 +160,7 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples, unsigned int return; // AyuanX: Actual re-sampling work has been moved to sound thread - // to alleviates the workload on main thread + // to alleviate the workload on main thread // and we simply store raw data here to make fast mem copy int over_bytes = num_samples * 4 - (MAX_SAMPLES * 2 - (m_indexW & INDEX_MASK)) * sizeof(short); if (over_bytes > 0) @@ -206,12 +175,7 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples, unsigned int m_indexW += num_samples * 2; - if (m_sampleRate < m_dspSampleRate) - { - // This is kind of tricky :P - num_samples = num_samples * 2 / 3; - } - else if (m_sampleRate > m_dspSampleRate) + if (m_sampleRate != 32000) { PanicAlert("Mixer: Up-sampling is not implemented yet!"); } diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index c6e50c4839..a3ebf94185 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -19,16 +19,16 @@ #define _MIXER_H_ // 16 bit Stereo -#define MAX_SAMPLES (1024 * 4) +#define MAX_SAMPLES (1024 * 8) #define INDEX_MASK (MAX_SAMPLES * 2 - 1) -#define RESERVED_SAMPLES (MAX_SAMPLES / 8) +#define RESERVED_SAMPLES (256) class CMixer { public: - CMixer(unsigned int AISampleRate = 48000, unsigned int DSPSampleRate = 48000) + CMixer(unsigned int AISampleRate = 48000, unsigned int DACSampleRate = 48000) : m_aiSampleRate(AISampleRate) - , m_dspSampleRate(DSPSampleRate) + , m_dacSampleRate(DACSampleRate) , m_bits(16) , m_channels(2) , m_HLEready(false) @@ -36,19 +36,21 @@ public: , m_indexW(0) , m_indexR(0) { - // AyuanX: When sample rate differs, we have to do re-sampling + // AyuanX: The internal (Core & DSP) sample rate is fixed at 32KHz + // So when AI/DAC sample rate differs than 32KHz, we have to do re-sampling // I perfer speed so let's do down-sampling instead of up-sampling // If you like better sound than speed, feel free to implement the up-sampling code - m_sampleRate = (m_aiSampleRate < m_dspSampleRate) ? m_aiSampleRate : m_dspSampleRate; + m_sampleRate = 32000; + NOTICE_LOG(AUDIO_INTERFACE, "Mixer is initialized (AISampleRate:%i, DACSampleRate:%i)", AISampleRate, DACSampleRate); } // Called from audio threads virtual unsigned int Mix(short* samples, unsigned int numSamples); - virtual void Premix(short *samples, unsigned int numSamples, unsigned int sampleRate) {} + virtual void Premix(short *samples, unsigned int numSamples) {} unsigned int GetNumSamples(); // Called from main thread - virtual void PushSamples(short* samples, unsigned int num_samples, unsigned int sample_rate); + virtual void PushSamples(short* samples, unsigned int num_samples); unsigned int GetSampleRate() {return m_sampleRate;} void SetThrottle(bool use) { m_throttle = use;} @@ -62,7 +64,7 @@ public: protected: unsigned int m_sampleRate; unsigned int m_aiSampleRate; - unsigned int m_dspSampleRate; + unsigned int m_dacSampleRate; int m_bits; int m_channels; diff --git a/Source/Core/AudioCommon/Src/NullSoundStream.h b/Source/Core/AudioCommon/Src/NullSoundStream.h index 7fc6aecd88..d5533d0d30 100644 --- a/Source/Core/AudioCommon/Src/NullSoundStream.h +++ b/Source/Core/AudioCommon/Src/NullSoundStream.h @@ -25,7 +25,7 @@ class NullMixer : public CMixer { public: virtual unsigned int Mix(short *samples, unsigned int numSamples) { return 0; } - virtual void PushSamples(short* samples, unsigned int num_samples, unsigned int sample_rate) {} + virtual void PushSamples(short* samples, unsigned int num_samples) {} }; class NullSound : public SoundStream diff --git a/Source/Core/AudioCommon/Src/OpenALStream.h b/Source/Core/AudioCommon/Src/OpenALStream.h index 9a469511b8..57bf2e34b7 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.h +++ b/Source/Core/AudioCommon/Src/OpenALStream.h @@ -35,9 +35,9 @@ #endif // WIN32 // 16 bit Stereo #define SFX_MAX_SOURCE 1 -#define OAL_NUM_BUFFERS 8 +#define OAL_NUM_BUFFERS 16 #define OAL_MAX_SAMPLES 512 // AyuanX: Don't make it too large, as larger buffer means longer delay -#define OAL_THRESHOLD 128 +#define OAL_THRESHOLD 128 // Some games are quite sensitive to delay #endif class OpenALStream: public SoundStream |
