handle driver-specified sample rates
This commit is contained in:
@@ -47,7 +47,8 @@
|
|||||||
|
|
||||||
const int channels = 2;
|
const int channels = 2;
|
||||||
const int samplesize = 2 * channels; /* 16-bit */
|
const int samplesize = 2 * channels; /* 16-bit */
|
||||||
inline int samplerate() { return SOUNDMAN->GetDriverSampleRate(); }
|
// inline int samplerate() { return SOUNDMAN->GetDriverSampleRate(); }
|
||||||
|
#define samplerate() Sample->GetSampleRate()
|
||||||
|
|
||||||
/* The most data to buffer when streaming. This should generally be at least as large
|
/* The most data to buffer when streaming. This should generally be at least as large
|
||||||
* as the largest hardware buffer. */
|
* as the largest hardware buffer. */
|
||||||
@@ -57,9 +58,8 @@ const int internal_buffer_size = 1024*16;
|
|||||||
const int read_block_size = 1024;
|
const int read_block_size = 1024;
|
||||||
|
|
||||||
/* The number of samples we should keep pos_map data for. This being too high
|
/* The number of samples we should keep pos_map data for. This being too high
|
||||||
* is mostly harmless (the data is small). Let's keep a second; no sane audio
|
* is mostly harmless; the data is small. */
|
||||||
* driver will have that much latency. */
|
const int pos_map_backlog_samples = 100000;
|
||||||
int pos_map_backlog_samples() { return samplerate(); }
|
|
||||||
|
|
||||||
RageSound::RageSound()
|
RageSound::RageSound()
|
||||||
{
|
{
|
||||||
@@ -177,11 +177,12 @@ bool RageSound::Load(CString sSoundFilePath, int precache)
|
|||||||
sSoundFilePath.GetString(), NewSample->GetError().c_str());
|
sSoundFilePath.GetString(), NewSample->GetError().c_str());
|
||||||
Sample = NewSample;
|
Sample = NewSample;
|
||||||
|
|
||||||
if(Sample->GetSampleRate() != samplerate())
|
if(SOUNDMAN->GetDriverSampleRate() != -1 &&
|
||||||
|
Sample->GetSampleRate() != SOUNDMAN->GetDriverSampleRate())
|
||||||
{
|
{
|
||||||
RageSoundReader_Resample *Resample = new RageSoundReader_Resample;
|
RageSoundReader_Resample *Resample = new RageSoundReader_Resample;
|
||||||
Resample->Open(Sample);
|
Resample->Open(Sample);
|
||||||
Resample->SetSampleRate(samplerate());
|
Resample->SetSampleRate(SOUNDMAN->GetDriverSampleRate());
|
||||||
Sample = Resample;
|
Sample = Resample;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +394,7 @@ int RageSound::GetPCM(char *buffer, int size, int sampleno)
|
|||||||
|
|
||||||
ASSERT(playing);
|
ASSERT(playing);
|
||||||
/* Erase old pos_map data. */
|
/* Erase old pos_map data. */
|
||||||
while(pos_map.size() > 1 && pos_map.back().sampleno - pos_map.front().sampleno > pos_map_backlog_samples())
|
while(pos_map.size() > 1 && pos_map.back().sampleno - pos_map.front().sampleno > pos_map_backlog_samples)
|
||||||
pos_map.pop_front();
|
pos_map.pop_front();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -633,6 +634,13 @@ bool RageSound::SetPositionSeconds( float fSeconds )
|
|||||||
return SetPositionSamples( fSeconds == -1? -1: int(fSeconds * samplerate()) );
|
return SetPositionSamples( fSeconds == -1? -1: int(fSeconds * samplerate()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is always the desired sample rate of the current driver. */
|
||||||
|
int RageSound::GetSampleRate() const
|
||||||
|
{
|
||||||
|
return Sample->GetSampleRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RageSound::SetPositionSamples( int samples )
|
bool RageSound::SetPositionSamples( int samples )
|
||||||
{
|
{
|
||||||
if(samples == -1)
|
if(samples == -1)
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
|
|
||||||
float GetLengthSeconds();
|
float GetLengthSeconds();
|
||||||
float GetPositionSeconds() const;
|
float GetPositionSeconds() const;
|
||||||
|
int GetSampleRate() const;
|
||||||
bool SetPositionSeconds( float fSeconds = -1);
|
bool SetPositionSeconds( float fSeconds = -1);
|
||||||
void SetAccurateSync(bool yes=true) { AccurateSync = yes; }
|
void SetAccurateSync(bool yes=true) { AccurateSync = yes; }
|
||||||
void SetPlaybackRate( float fScale );
|
void SetPlaybackRate( float fScale );
|
||||||
|
|||||||
Reference in New Issue
Block a user