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

View File

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