add balance (panning) support

This commit is contained in:
Glenn Maynard
2004-02-27 23:26:55 +00:00
parent 7236339bb6
commit 8b149bd832
2 changed files with 20 additions and 0 deletions
+16
View File
@@ -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;
+4
View File
@@ -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