From 8f9885c22913ddf7a022b3b805531a9f3a6f48ad Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 27 Dec 2006 07:46:10 +0000 Subject: [PATCH] Both the pitch changer and the resampler quantize the supplied ratio, making aligning their speeds very difficult. The resampler is more limited, and it's easier to remove this restriction from the speed changer, so reverse this logic, basing the ratio on the resampler instead of the speed changer. (also simpler) --- stepmania/src/RageSoundReader_PitchChange.cpp | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/stepmania/src/RageSoundReader_PitchChange.cpp b/stepmania/src/RageSoundReader_PitchChange.cpp index ca03824faa..0d9c151612 100644 --- a/stepmania/src/RageSoundReader_PitchChange.cpp +++ b/stepmania/src/RageSoundReader_PitchChange.cpp @@ -46,30 +46,16 @@ int RageSoundReader_PitchChange::Read( char *pBuf, int iFrames ) if( m_pSpeedChange->NextReadWillStep() ) { /* This is the simple way: */ - // float fRequestedSpeedRatio = m_fSpeedRatio / m_fPitchRatio; - // m_pSpeedChange->SetSpeedRatio( fRequestedSpeedRatio ); // m_pResample->SetRate( m_fPitchRatio ); + // m_pSpeedChange->SetSpeedRatio( m_fSpeedRatio / m_fPitchRatio ); - /* - * However, the speed changer has a granularity due to internal fixed- + /* However, the resampler has a limited granularity due to internal fixed- * point math, and the actual ratio will be slightly different than what - * we tell it to use. The actual ratio used is fActualSpeedChangeRatio. - * Given - * - * fRequestedSpeedRatio = m_fSpeedRatio / m_fPitchRatio - * - * solve for m_fPitchRatio: - * - * fRequestedPitchRatio = m_fSpeedRatio / fRequestedSpeedRatio - * - * and compute the pitch ratio based on the actual speed ratio, rather than - * the requested speed ratio. This avoids excessive rounding error between - * the ratios of m_pSpeedChange and m_pResample. - */ - m_pSpeedChange->SetSpeedRatio( m_fSpeedRatio / m_fPitchRatio ); - float fActualSpeedRatio = m_pSpeedChange->GetRatio(); - float fRequestedPitchRatio = m_fSpeedRatio / fActualSpeedRatio; - m_pResample->SetRate( fRequestedPitchRatio ); + * we tell it to use. The actual ratio used is fActualPitchRatio. */ + m_pResample->SetRate( m_fPitchRatio ); + float fActualPitchRatio = m_pResample->GetRate(); + float fRequestedSpeedRatio = m_fSpeedRatio / fActualPitchRatio; + m_pSpeedChange->SetSpeedRatio( fRequestedSpeedRatio ); } /* If we just applied a new speed and it caused the ratio to change, return