From 6d65216dd6014ff1b06d3bc9d8d605ac3f16b248 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 15 May 2016 16:41:11 -1000 Subject: [PATCH] Fix pitch-ratio set --- lib/audiodev/AudioVoice.cpp | 12 +++++++++--- lib/audiodev/AudioVoice.hpp | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/audiodev/AudioVoice.cpp b/lib/audiodev/AudioVoice.cpp index 420712c..aa46030 100644 --- a/lib/audiodev/AudioVoice.cpp +++ b/lib/audiodev/AudioVoice.cpp @@ -20,7 +20,7 @@ void AudioVoice::_setPitchRatio(double ratio) { if (m_dynamicRate) { - soxr_error_t err = soxr_set_io_ratio(m_src, ratio, m_parent.mixInfo().m_periodFrames); + soxr_error_t err = soxr_set_io_ratio(m_src, ratio * m_sampleRateIn / m_sampleRateOut, 0 /*m_parent.mixInfo().m_periodFrames*/); if (err) { Log.report(logvisor::Fatal, "unable to set resampler rate: %s", soxr_strerror(err)); @@ -81,11 +81,12 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate) { soxr_delete(m_src); + double rateOut = m_parent.mixInfo().m_sampleRate; soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, m_parent.mixInfo().m_sampleFormat); soxr_quality_spec_t qSpec = soxr_quality_spec(SOXR_20_BITQ, m_dynamicRate ? SOXR_VR : 0); soxr_error_t err; - m_src = soxr_create(sampleRate, m_parent.mixInfo().m_sampleRate, 1, + m_src = soxr_create(sampleRate, rateOut, 1, &err, &ioSpec, &qSpec, nullptr); if (err) @@ -95,6 +96,8 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate) return; } + m_sampleRateIn = sampleRate; + m_sampleRateOut = rateOut; soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0); _setPitchRatio(m_pitchRatio); m_resetSampleRate = false; @@ -221,11 +224,12 @@ void AudioVoiceStereo::_resetSampleRate(double sampleRate) { soxr_delete(m_src); + double rateOut = m_parent.mixInfo().m_sampleRate; soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, m_parent.mixInfo().m_sampleFormat); soxr_quality_spec_t qSpec = soxr_quality_spec(SOXR_20_BITQ, m_dynamicRate ? SOXR_VR : 0); soxr_error_t err; - m_src = soxr_create(sampleRate, m_parent.mixInfo().m_sampleRate, 2, + m_src = soxr_create(sampleRate, rateOut, 2, &err, &ioSpec, &qSpec, nullptr); if (!m_src) @@ -235,6 +239,8 @@ void AudioVoiceStereo::_resetSampleRate(double sampleRate) return; } + m_sampleRateIn = sampleRate; + m_sampleRateOut = rateOut; soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0); _setPitchRatio(m_pitchRatio); m_resetSampleRate = false; diff --git a/lib/audiodev/AudioVoice.hpp b/lib/audiodev/AudioVoice.hpp index d5da08f..18667ce 100644 --- a/lib/audiodev/AudioVoice.hpp +++ b/lib/audiodev/AudioVoice.hpp @@ -34,6 +34,8 @@ protected: /* Sample-rate converter */ soxr_t m_src = nullptr; + double m_sampleRateIn; + double m_sampleRateOut; bool m_dynamicRate; /* Running bool */