From: Fredrik Tolf Date: Mon, 29 Sep 2008 20:34:38 +0000 (+0200) Subject: Fixed audio playing X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;p=kvidha.git Fixed audio playing SDL seems to have stopped being able to handle U8 PCM, so convert Kvidha's sound buffer to S16 when filling. --- diff --git a/sb.c b/sb.c index 75293c8..7bc8484 100644 --- a/sb.c +++ b/sb.c @@ -12,11 +12,13 @@ void StartPlayBack(void) return; } -static void SBCallback(void *uudata, unsigned char *Buffer, int Length) +static void SBCallback(void *uudata, signed short *Buffer, int Length) { + int i; unsigned short Pos, Cur, Left; Pos = 0; + Length /= 2; while(Length > 0) { if(SoundBufferPos >= (SB_SIZE >> 1)) @@ -26,7 +28,8 @@ static void SBCallback(void *uudata, unsigned char *Buffer, int Length) } Left = (SB_SIZE >> 1) - SoundBufferPos; Cur = (Length > Left)?Left:Length; - memcpy(Buffer + Pos, SoundBuffer + SoundBufferPos, Cur); + for(i = 0; i < Cur; i++) + Buffer[Pos + i] = (((signed char)SoundBuffer[SoundBufferPos + i]) - 128) * 255; Pos += Cur; SoundBufferPos += Cur; Length -= Cur; @@ -39,17 +42,17 @@ unsigned char SBReset(void) SoundBufferPos = SB_SIZE; my.freq = 44100; - my.format = AUDIO_U8; + my.format = AUDIO_S16; my.channels = 1; my.samples = SB_SIZE >> 1; - my.callback = SBCallback; + my.callback = (void (*)(void *, unsigned char *, int))SBCallback; if(SDL_OpenAudio(&my, &got) < 0) { printf("Could not open SDL audio: %s\n", SDL_GetError()); return(1); } if((got.freq != 44100) || - (got.format != AUDIO_U8) || + (got.format != AUDIO_S16) || (got.channels != 1)) { printf("Audio format mismatch(%i %i %i)!\n", got.freq, got.format, got.channels);