mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
Linux: Slow down audio playback when emulation speed is set to less than 100%
This commit is contained in:
parent
fb9fba041a
commit
94d88ecbe2
3 changed files with 15 additions and 6 deletions
|
@ -18,6 +18,7 @@ SoundMixer::SoundMixer(Emulator* emu)
|
|||
_audioDevice = nullptr;
|
||||
_resampler.reset(new SoundResampler(emu));
|
||||
_sampleBuffer = new int16_t[0x10000];
|
||||
_pitchAdjustBuffer = new int16_t[0x10000];
|
||||
_reverbFilter.reset(new ReverbFilter());
|
||||
_crossFeedFilter.reset(new CrossFeedFilter());
|
||||
}
|
||||
|
@ -25,6 +26,7 @@ SoundMixer::SoundMixer(Emulator* emu)
|
|||
SoundMixer::~SoundMixer()
|
||||
{
|
||||
delete[] _sampleBuffer;
|
||||
delete[] _pitchAdjustBuffer;
|
||||
}
|
||||
|
||||
void SoundMixer::RegisterAudioDevice(IAudioDevice *audioDevice)
|
||||
|
@ -141,6 +143,14 @@ void SoundMixer::PlayAudioBuffer(int16_t* samples, uint32_t sampleCount, uint32_
|
|||
//(this is to prevent playing an audio blip when loading a save state)
|
||||
if(!_emu->IsPaused() && _audioDevice) {
|
||||
if(cfg.EnableAudio) {
|
||||
uint32_t emulationSpeed = _emu->GetSettings()->GetEmulationSpeed();
|
||||
if(emulationSpeed > 0 && emulationSpeed < 100) {
|
||||
//Slow down playback when playing at less than 100% speed
|
||||
_pitchAdjust.SetSampleRates(targetRate, targetRate * 100.0 / emulationSpeed);
|
||||
count = _pitchAdjust.Resample<false>(_sampleBuffer, count, _pitchAdjustBuffer, 0x10000);
|
||||
out = _pitchAdjustBuffer;
|
||||
}
|
||||
|
||||
_audioDevice->PlayBuffer(out, count, cfg.SampleRate, true);
|
||||
_audioDevice->ProcessEndOfFrame();
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "pch.h"
|
||||
#include "Core/Shared/Interfaces/IAudioDevice.h"
|
||||
#include "Utilities/safe_ptr.h"
|
||||
#include "Utilities/Audio/HermiteResampler.h"
|
||||
|
||||
class Emulator;
|
||||
class Equalizer;
|
||||
|
@ -22,6 +23,9 @@ private:
|
|||
safe_ptr<WaveRecorder> _waveRecorder;
|
||||
int16_t *_sampleBuffer = nullptr;
|
||||
|
||||
HermiteResampler _pitchAdjust;
|
||||
int16_t* _pitchAdjustBuffer = nullptr;
|
||||
|
||||
int16_t _leftSample = 0;
|
||||
int16_t _rightSample = 0;
|
||||
|
||||
|
|
|
@ -274,12 +274,7 @@ void SoundManager::ProcessEndOfFrame()
|
|||
ValidateWriteCursor(safeWriteCursor);
|
||||
|
||||
uint32_t emulationSpeed = _emu->GetSettings()->GetEmulationSpeed();
|
||||
uint32_t targetRate = _sampleRate;
|
||||
if(emulationSpeed > 0 && emulationSpeed < 100) {
|
||||
//Slow down playback when playing at less than 100%
|
||||
targetRate = (uint32_t)(targetRate * ((double)emulationSpeed / 100.0));
|
||||
}
|
||||
_secondaryBuffer->SetFrequency((DWORD)(targetRate));
|
||||
_secondaryBuffer->SetFrequency((DWORD)(_sampleRate));
|
||||
|
||||
ProcessLatency(currentPlayCursor, _lastWriteOffset);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue