Fixed SDL sound thread/shutdown issue for good now

Updated makefile
This commit is contained in:
mudlord 2007-12-14 22:38:32 +00:00
parent be5a6182cc
commit c92a8025ac
2 changed files with 25 additions and 26 deletions

View File

@ -61,7 +61,6 @@ ${DMGDIR}/gbSound${OE}
SDLOBJ=${SDLDIR}/debugger${OE} ${SDLDIR}/SDL${OE} ${SDLDIR}/dummy${OE}
OBJECTS=${MAINOBJ} ${DMGOBJ} ${SDLOBJ} ${GBAPUOBJ}
LIB=
ifeq ($(USEASM),yes)
OBJECTS+=${ASMOBJ}
@ -83,9 +82,9 @@ endif
ALL: ${OUT}
${OUT}: ${OBJECTS} ${LIB}
$(CPPC) -o $@ ${OBJECTS} ${LIB} ${LFLAGS}
${OUT}: ${OBJECTS}
$(CPPC) -o $@ ${OBJECTS} ${LFLAGS}
$(STRIP) $@
clean:
$(DEL) ${OUT} ${OBJECTS} ${LIB}
$(DEL) ${OUT} ${OBJECTS}

View File

@ -37,7 +37,7 @@
#include "../RTC.h"
#include "../Sound.h"
#include "../Text.h"
#include "../unzip.h"
#include "zlib.h"
#include "../Util.h"
#include "../gb/gb.h"
#include "../gb/gbGlobals.h"
@ -285,7 +285,7 @@ char screenMessageBuffer[21];
u32 screenMessageTime = 0;
// Patch #1382692 by deathpudding.
const int sdlSoundSamples = 2048;
const int sdlSoundSamples = 4096;
const int sdlSoundAlign = 4;
const int sdlSoundCapacity = sdlSoundSamples * 2;
const int sdlSoundTotalLen = sdlSoundCapacity + sdlSoundAlign;
@ -3171,7 +3171,7 @@ SDL_mutexP(sdlSoundMutex);
const int nAvail = soundBufferUsed();
if (len > nAvail)
len = nAvail;
const int nAvail2 = ((sdlSoundTotalLen - sdlSoundRPos) + sdlSoundTotalLen) % sdlSoundTotalLen;
const int nAvail2 = sdlSoundTotalLen - sdlSoundRPos;
if (len >= nAvail2) {
memcpy(stream, &sdlSoundBuffer[sdlSoundRPos], nAvail2);
sdlSoundRPos = 0;
@ -3186,34 +3186,35 @@ SDL_mutexP(sdlSoundMutex);
SDL_CondSignal(sdlSoundCond);
SDL_mutexV(sdlSoundMutex);
}
void systemWriteDataToSoundBuffer()
{
if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)
{
SDL_PauseAudio(0);
}
int remain = soundBufferLen;
const u8 *wave = reinterpret_cast<const u8 *>(soundFinalWave);
if (remain <= 0)
return;
SDL_mutexP(sdlSoundMutex);
int n;
while (remain >= (n = soundBufferFree())) {
const int nAvail = ((sdlSoundTotalLen - sdlSoundWPos) + sdlSoundTotalLen) % sdlSoundTotalLen;
if (n >= nAvail) {
const int nAvail = (sdlSoundTotalLen - sdlSoundWPos) < n ? (sdlSoundTotalLen - sdlSoundWPos) : n;
memcpy(&sdlSoundBuffer[sdlSoundWPos], wave, nAvail);
sdlSoundWPos = 0;
sdlSoundWPos = (sdlSoundWPos + nAvail) % sdlSoundTotalLen;
wave += nAvail;
remain -= nAvail;
n -= nAvail;
}
if (!emulating || speedup || throttle) {
SDL_mutexV(sdlSoundMutex);
return;
}
SDL_CondWait(sdlSoundCond, sdlSoundMutex);
}
const int nAvail = ((sdlSoundTotalLen - sdlSoundWPos) + sdlSoundTotalLen) % sdlSoundTotalLen;
}
const int nAvail = sdlSoundTotalLen - sdlSoundWPos;
if (remain >= nAvail) {
memcpy(&sdlSoundBuffer[sdlSoundWPos], wave, nAvail);
sdlSoundWPos = 0;
@ -3225,8 +3226,7 @@ void systemWriteDataToSoundBuffer()
sdlSoundWPos = (sdlSoundWPos + remain) % sdlSoundTotalLen;
}
SDL_mutexV(sdlSoundMutex);
}
}
bool systemSoundInit()
{