Made _sampleRate constant again in Audio::MixerImpl. (And Committing "common/timer.h" that should have been included in r50095)

svn-id: r50097
This commit is contained in:
Alejandro Marzini 2010-06-20 20:19:53 +00:00
parent 4a850209d7
commit e0fe48032d
5 changed files with 34 additions and 48 deletions

View File

@ -39,7 +39,33 @@ SdlMixerImpl::SdlMixerImpl(OSystem *system)
_soundMutex(0), _soundCond(0), _soundThread(0),
_soundThreadIsRunning(false), _soundThreadShouldQuit(false),
#endif
MixerImpl(system, SAMPLES_PER_SEC) {
MixerImpl(system, getSamplesPerSec()) {
if (_openAudio) {
setReady(true);
#if MIXER_DOUBLE_BUFFERING
initThreadedMixer(_obtainedRate.samples * 4);
#endif
// start the sound system
SDL_PauseAudio(0);
}
else {
setReady(false);
}
}
SdlMixerImpl::~SdlMixerImpl() {
setReady(false);
SDL_CloseAudio();
#if MIXER_DOUBLE_BUFFERING
deinitThreadedMixer();
#endif
}
uint SdlMixerImpl::getSamplesPerSec() {
SDL_AudioSpec desired;
// Determine the desired output sampling frequency.
@ -67,38 +93,16 @@ SdlMixerImpl::SdlMixerImpl(OSystem *system)
if (SDL_OpenAudio(&desired, &_obtainedRate) != 0) {
warning("Could not open audio device: %s", SDL_GetError());
setSampleRate(samplesPerSec);
setReady(false);
_openAudio = false;
} else {
// Note: This should be the obtained output rate, but it seems that at
// least on some platforms SDL will lie and claim it did get the rate
// even if it didn't. Probably only happens for "weird" rates, though.
samplesPerSec = _obtainedRate.freq;
debug(1, "Output sample rate: %d Hz", samplesPerSec);
setSampleRate(samplesPerSec);
setReady(true);
#if MIXER_DOUBLE_BUFFERING
initThreadedMixer(_obtainedRate.samples * 4);
#endif
// start the sound system
SDL_PauseAudio(0);
_openAudio = true;
}
}
SdlMixerImpl::~SdlMixerImpl() {
setReady(false);
SDL_CloseAudio();
#if MIXER_DOUBLE_BUFFERING
deinitThreadedMixer();
#endif
return samplesPerSec;
}
#if MIXER_DOUBLE_BUFFERING

View File

@ -51,6 +51,9 @@ public:
protected:
SDL_AudioSpec _obtainedRate;
bool _openAudio;
uint getSamplesPerSec();
static void mixSdlCallback(void *s, byte *samples, int len);

View File

@ -56,21 +56,6 @@ public:
* and no instance of this callback will be running anymore.
*/
virtual void removeTimerProc(TimerProc proc) = 0;
/**
* Get the number of milliseconds since the program was started.
*/
virtual uint32 getMillis() = 0;
/**
* Delay for a specified amount of milliseconds
*/
virtual void delayMillis(uint msecs) = 0;
/**
* Get the current time and date
*/
virtual void getTimeAndDate(TimeDate &t) const = 0;
};
} // End of namespace Common

View File

@ -431,10 +431,6 @@ int MixerImpl::getVolumeForSoundType(SoundType type) const {
return _volumeForSoundType[type];
}
void MixerImpl::setSampleRate(uint sampleRate) {
_sampleRate = sampleRate;
}
#pragma mark -
#pragma mark --- Channel implementations ---
#pragma mark -

View File

@ -60,7 +60,7 @@ private:
OSystem *_syst;
Common::Mutex _mutex;
uint _sampleRate;
const uint _sampleRate;
bool _mixerReady;
uint32 _handleSeed;
@ -127,8 +127,6 @@ public:
* their audio system has been completed.
*/
void setReady(bool ready);
void setSampleRate(uint sampleRate);
};