SDL sound driver : renamed some variables

This commit is contained in:
bgk 2008-12-26 15:35:28 +00:00
parent e2e749245e
commit 9ab357571a
2 changed files with 55 additions and 55 deletions

View File

@ -6,25 +6,25 @@
extern int emulating; extern int emulating;
u8 SoundSDL::sdlSoundBuffer[sdlSoundTotalLen]; u8 SoundSDL::_buffer[_bufferTotalLen];
int SoundSDL::sdlSoundRPos; int SoundSDL::_readPosition;
int SoundSDL::sdlSoundWPos; int SoundSDL::_writePosition;
SDL_cond * SoundSDL::sdlSoundCond; SDL_cond * SoundSDL::_cond;
SDL_mutex * SoundSDL::sdlSoundMutex; SDL_mutex * SoundSDL::_mutex;
inline int SoundSDL::soundBufferFree() inline int SoundSDL::getBufferFree()
{ {
int ret = sdlSoundRPos - sdlSoundWPos - sdlSoundAlign; int ret = _readPosition - _writePosition - _bufferAlign;
if (ret < 0) if (ret < 0)
ret += sdlSoundTotalLen; ret += _bufferTotalLen;
return ret; return ret;
} }
inline int SoundSDL::soundBufferUsed() inline int SoundSDL::getBufferUsed()
{ {
int ret = sdlSoundWPos - sdlSoundRPos; int ret = _writePosition - _readPosition;
if (ret < 0) if (ret < 0)
ret += sdlSoundTotalLen; ret += _bufferTotalLen;
return ret; return ret;
} }
@ -33,24 +33,24 @@ void SoundSDL::soundCallback(void *,u8 *stream,int len)
if (len <= 0 || !emulating) if (len <= 0 || !emulating)
return; return;
SDL_mutexP(sdlSoundMutex); SDL_mutexP(_mutex);
const int nAvail = soundBufferUsed(); const int nAvail = getBufferUsed();
if (len > nAvail) if (len > nAvail)
len = nAvail; len = nAvail;
const int nAvail2 = sdlSoundTotalLen - sdlSoundRPos; const int nAvail2 = _bufferTotalLen - _readPosition;
if (len >= nAvail2) { if (len >= nAvail2) {
memcpy(stream, &sdlSoundBuffer[sdlSoundRPos], nAvail2); memcpy(stream, &_buffer[_readPosition], nAvail2);
sdlSoundRPos = 0; _readPosition = 0;
stream += nAvail2; stream += nAvail2;
len -= nAvail2; len -= nAvail2;
} }
if (len > 0) { if (len > 0) {
memcpy(stream, &sdlSoundBuffer[sdlSoundRPos], len); memcpy(stream, &_buffer[_readPosition], len);
sdlSoundRPos = (sdlSoundRPos + len) % sdlSoundTotalLen; _readPosition = (_readPosition + len) % _bufferTotalLen;
stream += len; stream += len;
} }
SDL_CondSignal(sdlSoundCond); SDL_CondSignal(_cond);
SDL_mutexV(sdlSoundMutex); SDL_mutexV(_mutex);
} }
void SoundSDL::write(const u16 * finalWave, int length) void SoundSDL::write(const u16 * finalWave, int length)
@ -63,35 +63,35 @@ void SoundSDL::write(const u16 * finalWave, int length)
int remain = length; int remain = length;
const u8 *wave = reinterpret_cast<const u8 *>(finalWave); const u8 *wave = reinterpret_cast<const u8 *>(finalWave);
SDL_mutexP(sdlSoundMutex); SDL_mutexP(_mutex);
int n; int n;
while (remain >= (n = soundBufferFree())) { while (remain >= (n = getBufferFree())) {
const int nAvail = (sdlSoundTotalLen - sdlSoundWPos) < n ? (sdlSoundTotalLen - sdlSoundWPos) : n; const int nAvail = (_bufferTotalLen - _writePosition) < n ? (_bufferTotalLen - _writePosition) : n;
memcpy(&sdlSoundBuffer[sdlSoundWPos], wave, nAvail); memcpy(&_buffer[_writePosition], wave, nAvail);
sdlSoundWPos = (sdlSoundWPos + nAvail) % sdlSoundTotalLen; _writePosition = (_writePosition + nAvail) % _bufferTotalLen;
wave += nAvail; wave += nAvail;
remain -= nAvail; remain -= nAvail;
if (!emulating || speedup || systemThrottle) { if (!emulating || speedup || systemThrottle) {
SDL_mutexV(sdlSoundMutex); SDL_mutexV(_mutex);
return; return;
} }
SDL_CondWait(sdlSoundCond, sdlSoundMutex); SDL_CondWait(_cond, _mutex);
} }
const int nAvail = sdlSoundTotalLen - sdlSoundWPos; const int nAvail = _bufferTotalLen - _writePosition;
if (remain >= nAvail) { if (remain >= nAvail) {
memcpy(&sdlSoundBuffer[sdlSoundWPos], wave, nAvail); memcpy(&_buffer[_writePosition], wave, nAvail);
sdlSoundWPos = 0; _writePosition = 0;
wave += nAvail; wave += nAvail;
remain -= nAvail; remain -= nAvail;
} }
if (remain > 0) { if (remain > 0) {
memcpy(&sdlSoundBuffer[sdlSoundWPos], wave, remain); memcpy(&_buffer[_writePosition], wave, remain);
sdlSoundWPos = (sdlSoundWPos + remain) % sdlSoundTotalLen; _writePosition = (_writePosition + remain) % _bufferTotalLen;
} }
SDL_mutexV(sdlSoundMutex); SDL_mutexV(_mutex);
} }
bool SoundSDL::init(int quality) bool SoundSDL::init(int quality)
@ -123,27 +123,27 @@ bool SoundSDL::init(int quality)
return false; return false;
} }
sdlSoundCond = SDL_CreateCond(); _cond = SDL_CreateCond();
sdlSoundMutex = SDL_CreateMutex(); _mutex = SDL_CreateMutex();
sdlSoundRPos = sdlSoundWPos = 0; _readPosition = _writePosition = 0;
return true; return true;
} }
SoundSDL::~SoundSDL() SoundSDL::~SoundSDL()
{ {
SDL_mutexP(sdlSoundMutex); SDL_mutexP(_mutex);
int iSave = emulating; int iSave = emulating;
emulating = 0; emulating = 0;
SDL_CondSignal(sdlSoundCond); SDL_CondSignal(_cond);
SDL_mutexV(sdlSoundMutex); SDL_mutexV(_mutex);
SDL_DestroyCond(sdlSoundCond); SDL_DestroyCond(_cond);
sdlSoundCond = NULL; _cond = NULL;
SDL_DestroyMutex(sdlSoundMutex); SDL_DestroyMutex(_mutex);
sdlSoundMutex = NULL; _mutex = NULL;
SDL_CloseAudio(); SDL_CloseAudio();

View File

@ -33,20 +33,20 @@ public:
virtual int getBufferLength(); virtual int getBufferLength();
private: private:
static const int sdlSoundSamples = 4096; static const int _sampleCount = 4096;
static const int sdlSoundAlign = 4; static const int _bufferAlign = 4;
static const int sdlSoundCapacity = sdlSoundSamples * 2; static const int _bufferCapacity = _sampleCount * 2;
static const int sdlSoundTotalLen = sdlSoundCapacity + sdlSoundAlign; static const int _bufferTotalLen = _bufferCapacity + _bufferAlign;
static u8 sdlSoundBuffer[sdlSoundTotalLen]; static u8 _buffer[_bufferTotalLen];
static int sdlSoundRPos; static int _readPosition;
static int sdlSoundWPos; static int _writePosition;
static SDL_cond * sdlSoundCond; static SDL_cond * _cond;
static SDL_mutex * sdlSoundMutex; static SDL_mutex * _mutex;
int _bufferLen; int _bufferLen;
static int soundBufferFree(); static int getBufferFree();
static int soundBufferUsed(); static int getBufferUsed();
static void soundCallback(void *, u8 *stream, int len); static void soundCallback(void *, u8 *stream, int len);
}; };