From 7a4934980aa114c3d040f5e84173304cbbd05baf Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 5 Mar 2003 02:31:22 +0000 Subject: [PATCH] Fix SetPositionSamples() when we have a rate. This should fix the editor problems. There's a major restriction of rate changing: you can't change the rate while the song is playing. That's because RageSound keeps track of the number of samples actually *output to the sound driver*; it determines the position within the sound by dividing by the rate. (It might be possible to adjust position dynamically within SetPlaybackRate to make this work, but this isn't done right now.) --- stepmania/src/RageSound.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 44181ea4f3..68f4d83d55 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -709,6 +709,15 @@ bool RageSound::SetPositionSamples( int samples ) if(!playing) L.Unlock(); + /* If we're seeking to sample 10, and the playback rate is 0.5, we really + * want to seek to sample 20; it'll be multiplied back out in GetPosition. + * (The reason for this is to keep "position" in 44100 samples/second, so + * sound drivers don't have to know about the playback rate.) Think of + * it this way: if we seek to sample 10 in the input file, and we're playing + * it half speed, we would have actually played 20 samples, not 10, and + * it's the number of real speaker samples that "position" represents. */ + samples = int(samples / GetPlaybackRate()); + /* If we're already there, don't do anything. */ if(position == samples) return true;