summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authormylek4 <mylek4@gmail.com>2010-11-12 03:39:07 +0000
committermylek4 <mylek4@gmail.com>2010-11-12 03:39:07 +0000
commit67f850dd37893de6ef1544b024ea298033047dfd (patch)
treec722013098f6b982b06a7f7a422541a36ea5cc13 /Source/Core
parentc6d95c90876ed03768092a0385821b7d47135fea (diff)
DSPHLE: Added an option for 48khz output and supporting upsampling code.
Games that have higher frequency sounds and music should sound a bit better using 48k. I don't have any games that use DTKMusic so that upsampling code untested. If you get strange sounds only at 48k try toggling dtk music to see if that isolates the problem and let me know. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6383 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/AudioCommon/Src/AudioCommonConfig.cpp6
-rw-r--r--Source/Core/AudioCommon/Src/AudioCommonConfig.h2
-rw-r--r--Source/Core/AudioCommon/Src/Mixer.cpp111
-rw-r--r--Source/Core/AudioCommon/Src/Mixer.h7
-rw-r--r--Source/Core/Core/Src/HW/AudioInterface.cpp81
5 files changed, 105 insertions, 102 deletions
diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp b/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp
index ebec56e41d..f97b0ba75d 100644
--- a/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp
+++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp
@@ -26,14 +26,19 @@ void AudioCommonConfig::Load(IniFile &file) {
file.Get("Config", "Volume", &m_Volume, 75);
#ifdef _WIN32
file.Get("Config", "Backend", &sBackend, BACKEND_DIRECTSOUND);
+ file.Get("Config", "Frequency", &sFrequency, "32,000 Hz");
#elif defined __APPLE__
std::string temp;
file.Get("Config", "Backend", &temp, BACKEND_COREAUDIO);
strncpy(sBackend, temp.c_str(), 128);
+ file.Get("Config", "Frequency", &temp, "32,000 Hz");
+ strncpy(sFrequency, temp.c_str(), 128);
#elif defined __linux__
file.Get("Config", "Backend", &sBackend, BACKEND_ALSA);
+ file.Get("Config", "Frequency", &sFrequency, "32,000 Hz");
#else
file.Get("Config", "Backend", &sBackend, BACKEND_OPENAL);
+ file.Get("Config", "Frequency", &sFrequency, "32,000 Hz");
#endif
}
@@ -43,6 +48,7 @@ void AudioCommonConfig::Set(IniFile &file) {
file.Set("Config", "EnableThrottle", m_EnableThrottle);
file.Set("Config", "EnableJIT", m_EnableJIT);
file.Set("Config", "Backend", sBackend);
+ file.Set("Config", "Frequency", sFrequency);
file.Set("Config", "Volume", m_Volume);
}
diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.h b/Source/Core/AudioCommon/Src/AudioCommonConfig.h
index 1267b320b8..524251bb86 100644
--- a/Source/Core/AudioCommon/Src/AudioCommonConfig.h
+++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.h
@@ -39,8 +39,10 @@ struct AudioCommonConfig
int m_Volume;
#ifdef __APPLE__
char sBackend[128];
+ char sFrequency[128];
#else
std::string sBackend;
+ std::string sFrequency;
#endif
// Load from given file
diff --git a/Source/Core/AudioCommon/Src/Mixer.cpp b/Source/Core/AudioCommon/Src/Mixer.cpp
index b4f1be935d..d914f634c5 100644
--- a/Source/Core/AudioCommon/Src/Mixer.cpp
+++ b/Source/Core/AudioCommon/Src/Mixer.cpp
@@ -57,74 +57,39 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples)
samples[i] = Common::swap16(m_buffer[(m_indexR + i) & INDEX_MASK]);
m_indexR += numLeft * 2;
}
- else
+ else //linear interpolation
{
- // AyuanX: Up-sampling is not implemented yet
- PanicAlert("Mixer: Up-sampling is not implemented yet!");
-/*
- static int PV1l=0,PV2l=0,PV3l=0,PV4l=0;
- static int PV1r=0,PV2r=0,PV3r=0,PV4r=0;
- static int acc=0;
-
- while (num_stereo_samples) {
- acc += core_sample_rate;
- while (num_stereo_samples && (acc >= 48000)) {
- PV4l=PV3l;
- PV3l=PV2l;
- PV2l=PV1l;
- PV1l=*(samples++); //32bit processing
- PV4r=PV3r;
- PV3r=PV2r;
- PV2r=PV1r;
- PV1r=*(samples++); //32bit processing
- num_stereo_samples--;
- acc-=48000;
- }
-
- // defaults to nearest
- s32 DataL = PV1l;
- s32 DataR = PV1r;
-
- if (m_mode == 1) { //linear
-
- DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
- DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
- }
- else if (m_mode == 2) {//cubic
- s32 a0l = PV1l - PV2l - PV4l + PV3l;
- s32 a0r = PV1r - PV2r - PV4r + PV3r;
- s32 a1l = PV4l - PV3l - a0l;
- s32 a1r = PV4r - PV3r - a0r;
- s32 a2l = PV1l - PV4l;
- s32 a2r = PV1r - PV4r;
- s32 a3l = PV2l;
- s32 a3r = PV2r;
-
- s32 t0l = ((a0l )*acc)/48000;
- s32 t0r = ((a0r )*acc)/48000;
- s32 t1l = ((t0l+a1l)*acc)/48000;
- s32 t1r = ((t0r+a1r)*acc)/48000;
- s32 t2l = ((t1l+a2l)*acc)/48000;
- s32 t2r = ((t1r+a2r)*acc)/48000;
- s32 t3l = ((t2l+a3l));
- s32 t3r = ((t2r+a3r));
-
- DataL = t3l;
- DataR = t3r;
- }
-
- int l = DataL, r = DataR;
- if (l < -32767) l = -32767;
- if (r < -32767) r = -32767;
- if (l > 32767) l = 32767;
- if (r > 32767) r = 32767;
- sample_queue.push(l);
- sample_queue.push(r);
- m_queueSize += 2;
- }
-*/
+ //render numleft sample pairs to samples[]
+ //advance m_indexR with sample position
+ //remember fractional offset
+
+ static u32 frac = 0;
+ const u32 ratio = (u32)( 65536.0f * 32000.0f / (float)m_sampleRate );
+
+ for (u32 i = 0; i < numLeft * 2; i+=2) {
+ u32 m_indexR2 = m_indexR + 2; //next sample
+ if ((m_indexR2 & INDEX_MASK) == (m_indexW & INDEX_MASK)) //..if it exists
+ m_indexR2 = m_indexR;
+
+
+ s16 l1 = Common::swap16(m_buffer[m_indexR & INDEX_MASK]); //current
+ s16 l2 = Common::swap16(m_buffer[m_indexR2 & INDEX_MASK]); //next
+ int sampleL = (l1 << 16) + (l2 - l1) * (u16)frac >> 16;
+ samples[i] = sampleL;
+
+ s16 r1 = Common::swap16(m_buffer[(m_indexR + 1) & INDEX_MASK]); //current
+ s16 r2 = Common::swap16(m_buffer[(m_indexR2 + 1) & INDEX_MASK]); //next
+ int sampleR = (r1 << 16) + (r2 - r1) * (u16)frac >> 16;
+ samples[i+1] = sampleR;
+
+ frac += ratio;
+ m_indexR += 2 * (u16)(frac >> 16);
+ frac &= 0xffff;
+ }
}
+
+
} else {
numLeft = 0;
}
@@ -154,7 +119,7 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples)
if (m_throttle)
{
// The auto throttle function. This loop will put a ceiling on the CPU MHz.
- while (Common::AtomicLoad(m_numSamples) >= MAX_SAMPLES - RESERVED_SAMPLES)
+ while (Common::AtomicLoad(m_numSamples) + RESERVED_SAMPLES >= MAX_SAMPLES)
{
if (g_dspInitialize.pEmulatorState)
{
@@ -171,7 +136,7 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples)
}
// Check if we have enough free space
- if (num_samples > MAX_SAMPLES - Common::AtomicLoad(m_numSamples))
+ if (num_samples + Common::AtomicLoad(m_numSamples) > MAX_SAMPLES)
return;
// AyuanX: Actual re-sampling work has been moved to sound thread
@@ -190,12 +155,12 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples)
m_indexW += num_samples * 2;
- if (m_sampleRate != 32000)
- {
- PanicAlert("Mixer: Up-sampling is not implemented yet!");
- }
-
- Common::AtomicAdd(m_numSamples, num_samples);
+ if (m_sampleRate == 32000)
+ Common::AtomicAdd(m_numSamples, num_samples);
+ else if (m_sampleRate == 48000)
+ Common::AtomicAdd(m_numSamples, num_samples * 1.5);
+ else
+ PanicAlert("Mixer: Unsupported sample rate.");
return;
}
diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h
index dfa4d41828..984ec1c211 100644
--- a/Source/Core/AudioCommon/Src/Mixer.h
+++ b/Source/Core/AudioCommon/Src/Mixer.h
@@ -26,7 +26,7 @@
class CMixer {
public:
- CMixer(unsigned int AISampleRate = 48000, unsigned int DACSampleRate = 48000)
+ CMixer(unsigned int AISampleRate = 48000, unsigned int DACSampleRate = 48000, unsigned int BackendSampleRate = 32000)
: m_aiSampleRate(AISampleRate)
, m_dacSampleRate(DACSampleRate)
, m_bits(16)
@@ -39,9 +39,8 @@ public:
{
// 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 prefer 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 = 32000;
+ m_sampleRate = BackendSampleRate;
+
INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized (AISampleRate:%i, DACSampleRate:%i)", AISampleRate, DACSampleRate);
}
diff --git a/Source/Core/Core/Src/HW/AudioInterface.cpp b/Source/Core/Core/Src/HW/AudioInterface.cpp
index 2a3bfdfcdd..1aceee6653 100644
--- a/Source/Core/Core/Src/HW/AudioInterface.cpp
+++ b/Source/Core/Core/Src/HW/AudioInterface.cpp
@@ -281,17 +281,11 @@ unsigned int Callback_GetStreaming(short* _pDestBuffer, unsigned int _numSamples
const int lvolume = g_AudioRegister.m_Volume.leftVolume;
const int rvolume = g_AudioRegister.m_Volume.rightVolume;
-
if (g_AISampleRate == 48000 && _sampleRate == 32000)
{
_dbg_assert_msg_(AUDIO_INTERFACE, !(_numSamples & 1), "Number of Samples: %i must be even!", _numSamples);
_numSamples = _numSamples * 3 / 2;
}
- else if (g_AISampleRate == 32000 && _sampleRate == 48000)
- {
- // AyuanX: Up-sampling is not implemented yet
- PanicAlert("AUDIO_INTERFACE: Up-sampling is not implemented yet!");
- }
int pcm_l = 0, pcm_r = 0;
for (unsigned int i = 0; i < _numSamples; i++)
@@ -299,45 +293,82 @@ unsigned int Callback_GetStreaming(short* _pDestBuffer, unsigned int _numSamples
if (pos == 0)
ReadStreamBlock(pcm);
- if (g_AISampleRate == 48000 && _sampleRate == 32000)
+ if (g_AISampleRate == 48000 && _sampleRate == 32000) //downsample 48>32
{
if (i % 3)
{
pcm_l = (((pcm_l + (int)pcm[pos*2]) / 2 * lvolume) >> 8) + (int)(*_pDestBuffer);
- if (pcm_l > 32767)
- pcm_l = 32767;
- else if (pcm_l < -32767)
- pcm_l = -32767;
+ if (pcm_l > 32767) pcm_l = 32767;
+ else if (pcm_l < -32767) pcm_l = -32767;
*_pDestBuffer++ = pcm_l;
pcm_r = (((pcm_r + (int)pcm[pos*2+1]) / 2 * rvolume) >> 8) + (int)(*_pDestBuffer);
- if (pcm_r > 32767)
- pcm_r = 32767;
- else if (pcm_r < -32767)
- pcm_r = -32767;
+ if (pcm_r > 32767) pcm_r = 32767;
+ else if (pcm_r < -32767) pcm_r = -32767;
*_pDestBuffer++ = pcm_r;
}
pcm_l = pcm[pos*2];
pcm_r = pcm[pos*2+1];
+
+ pos++;
}
- else
+ else if (g_AISampleRate == 32000 && _sampleRate == 48000) //upsample 32>48
{
+ //starts with one sample of 0
+ const u32 ratio = (u32)( 65536.0f * 32000.0f / (float)_sampleRate );
+ static u32 frac = 0;
+
+ static s16 l1 = 0;
+ static s16 l2 = 0;
+ static s16 r1 = 0;
+ static s16 r2 = 0;
+
+
+ if ( frac >= 0x10000 || frac == 0)
+ {
+ frac &= 0xffff;
+
+ l1 = l2; //current
+ l2 = pcm[pos * 2]; //next
+
+ r1 = r2; //current
+ r2 = pcm[pos * 2 + 1]; //next
+ }
+
+ pcm_l = (l1 << 16) + (l2 - l1) * (u16)frac >> 16;
+ pcm_r = (l1 << 16) + (l2 - l1) * (u16)frac >> 16;
+
+
+ pcm_l = (pcm_l * lvolume >> 8) + (int)(*_pDestBuffer);
+ if (pcm_l > 32767) pcm_l = 32767;
+ else if (pcm_l < -32767) pcm_l = -32767;
+ *_pDestBuffer++ = pcm_l;
+
+ pcm_r = (pcm_r * lvolume >> 8) + (int)(*_pDestBuffer);
+ if (pcm_r > 32767) pcm_r = 32767;
+ else if (pcm_r < -32767) pcm_r = -32767;
+ *_pDestBuffer++ = pcm_r;
+
+ frac += ratio;
+ pos += frac >> 16;
+
+ }
+ else //1:1 no resampling
+ {
pcm_l = (((int)pcm[pos*2] * lvolume) >> 8) + (int)(*_pDestBuffer);
- if (pcm_l > 32767)
- pcm_l = 32767;
- else if (pcm_l < -32767)
- pcm_l = -32767;
+ if (pcm_l > 32767) pcm_l = 32767;
+ else if (pcm_l < -32767) pcm_l = -32767;
*_pDestBuffer++ = pcm_l;
pcm_r = (((int)pcm[pos*2+1] * rvolume) >> 8) + (int)(*_pDestBuffer);
- if (pcm_r > 32767)
- pcm_r = 32767;
- else if (pcm_r < -32767)
- pcm_r = -32767;
+ if (pcm_r > 32767) pcm_r = 32767;
+ else if (pcm_r < -32767) pcm_r = -32767;
*_pDestBuffer++ = pcm_r;
+
+ pos++;
}
- if (++pos == 28)
+ if (pos == 28)
pos = 0;
}
}