diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 6221c5ced6..934b902b83 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -78,6 +78,7 @@ RageSound::RageSound(): m_StartSample = 0; m_LengthSamples = -1; m_Volume = -1.0f; // use SOUNDMAN->GetMixVolume() + m_Balance = 0; // center AccurateSync = false; fade_length = 0; /* Register ourselves, so we receive Update()s. */ @@ -504,6 +505,21 @@ int RageSound::GetPCM( char *buffer, int size, int64_t frameno ) } } + if( m_Balance != 0 ) + { + Sint16 *p = (Sint16 *) buffer; + const float fLeft = SCALE( m_Balance, -1, 1, 1, 0 ); + const float fRight = SCALE( m_Balance, -1, 1, 0, 1 ); + const int iLeft = int(fLeft*256); + const int iRight = int(fRight*256); + RAGE_ASSERT_M( channels == 2, ssprintf("%i", channels) ); + for( int samp = 0; samp < got_frames; ++samp ) + { + *(p++) = short( (*p * iLeft) >> 8 ); + *(p++) = short( (*p * iRight) >> 8 ); + } + } + bytes_stored += got; position += got_frames; size -= got; diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index c25c4c82db..9f8a4fde53 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -83,6 +83,7 @@ public: CString GetLoadedFilePath() const { return m_sFilePath; } void SetStartTime( const RageTimer &tm ) { StartTime = tm; } RageTimer GetStartTime() const { return StartTime; } + void SetBalance( float f ) { m_Balance = f; } private: /* If we were copied from another RageSound, this will point to it; otherwise @@ -125,6 +126,9 @@ private: float m_Volume; + /* Pan: -1, left; 1, right */ + float m_Balance; + /* Hack: When we stop a playing sound, we can't ask the driver the position * (we're not playing); and we can't seek back to the current playing position * when we stop (too slow), but we want to be able to report the position we