Adjust the audio speed on non-60hz Android devices to compensate.

Greatly improves audio stability on Nexus S.

Fixes #6677 .
This commit is contained in:
Henrik Rydgard 2015-01-14 00:45:12 +01:00
parent e349ec2960
commit 8b05e7abf0
6 changed files with 30 additions and 5 deletions

View File

@ -20,6 +20,7 @@
#include <string.h>
#include "base/logging.h"
#include "base/NativeApp.h"
#include "Common/ChunkFile.h"
#include "Common/MathUtil.h"
#include "Common/Atomics.h"
@ -30,6 +31,22 @@
#include <emmintrin.h>
#endif
StereoResampler::StereoResampler()
: m_dma_mixer(this, 44100)
{
// Some Android devices are v-synced to non-60Hz framerates. We simply timestretch audio to fit.
// TODO: should only do this if auto frameskip is off?
float refresh = System_GetPropertyInt(SYSPROP_DISPLAY_REFRESH_RATE) / 1000.0f;
// If framerate is "close"...
if (refresh != 60.0f && refresh > 50.0f && refresh < 70.0f) {
m_dma_mixer.SetInputSampleRate((int)(44100 * (refresh / 60.0f)));
}
}
inline void ClampBufferToS16(s16 *out, const s32 *in, size_t size) {
#ifdef _M_SSE
// Size will always be 16-byte aligned as the hwBlockSize is.

View File

@ -39,10 +39,7 @@
class StereoResampler {
public:
StereoResampler()
: m_dma_mixer(this, 44100)
{
}
StereoResampler();
virtual ~StereoResampler() {}

View File

@ -330,8 +330,15 @@ void SystemInfoScreen::CreateViews() {
deviceSpecs->Add(new InfoItem("Frames per buffer", StringFromFormat("%d", System_GetPropertyInt(SYSPROP_AUDIO_FRAMES_PER_BUFFER))));
deviceSpecs->Add(new InfoItem("Optimal sample rate", StringFromFormat("%d Hz", System_GetPropertyInt(SYSPROP_AUDIO_OPTIMAL_SAMPLE_RATE))));
deviceSpecs->Add(new InfoItem("Optimal frames per buffer", StringFromFormat("%d", System_GetPropertyInt(SYSPROP_AUDIO_OPTIMAL_FRAMES_PER_BUFFER))));
deviceSpecs->Add(new ItemHeader("Display Information"));
deviceSpecs->Add(new InfoItem("Native Resolution", StringFromFormat("%dx%d",
System_GetPropertyInt(SYSPROP_DISPLAY_XRES),
System_GetPropertyInt(SYSPROP_DISPLAY_YRES))));
deviceSpecs->Add(new InfoItem("Refresh rate", StringFromFormat("%0.3f Hz", (float)System_GetPropertyInt(SYSPROP_DISPLAY_REFRESH_RATE) / 1000.0f)));
#endif
deviceSpecs->Add(new ItemHeader("Version Information"));
std::string apiVersion = thin3d->GetInfoString(T3DInfo::APIVERSION);
apiVersion.resize(30);

View File

@ -263,6 +263,8 @@ int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
return winAudioBackend ? winAudioBackend->GetSampleRate() : -1;
case SYSPROP_DISPLAY_REFRESH_RATE:
return 60000;
default:
return -1;
}

View File

@ -26,6 +26,8 @@ int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
return 44100;
case SYSPROP_DISPLAY_REFRESH_RATE:
return 60000;
default:
return -1;
}

2
native

@ -1 +1 @@
Subproject commit 477e0e89f9269b573edbfbc84c22199c4d449203
Subproject commit d2f95b91909418d07cb6cdd3f6b8f7cf5ad4dc09