From cd578b0e73a3091156ded6a64e734324e74fc87b Mon Sep 17 00:00:00 2001 From: n-a-c-h <> Date: Sat, 26 Nov 2005 17:24:40 +0000 Subject: [PATCH] Make sound processing use less CPU cycles. --- zsnes/src/linux/sdllink.c | 65 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/zsnes/src/linux/sdllink.c b/zsnes/src/linux/sdllink.c index a6f03ebf..d3a23b22 100644 --- a/zsnes/src/linux/sdllink.c +++ b/zsnes/src/linux/sdllink.c @@ -1048,46 +1048,43 @@ void sem_sleep_die(void) void UpdateVFrame(void) { - const int SPCSize = 256; - int i; + //Quick fix for GUI CPU usage + if (GUIOn || GUIOn2 || EMUPause) { usleep(6000); } - //Quick fix for GUI CPU usage - if (GUIOn || GUIOn2 || EMUPause) usleep(6000); + CheckTimers(); + Main_Proc(); - CheckTimers(); - Main_Proc(); + /* Process sound */ - /* Process sound */ + /* take care of the things we left behind last time */ + SDL_LockAudio(); + while (Buffer_fill < Buffer_len) + { + short *ptr = (short*)&Buffer[Buffer_tail]; - /* take care of the things we left behind last time */ - SDL_LockAudio(); - while (Buffer_fill < Buffer_len) { - short *ptr = (short*)&Buffer[Buffer_tail]; + SoundProcess(); - SoundProcess(); + if (T36HZEnabled) + { + memset(ptr, 0, 256*sizeof(short)); + } + else + { + int *d = DSPBuffer; + int *end_d = DSPBuffer+256; + for (; d < end_d; d++, ptr++) + { + if (*d > 32767) { *ptr = 32767; } + else if (*d < -32767) { *ptr = -32767; } + else { *ptr = *d; } + } + } - for (i = 0; i < SPCSize; i++, ptr++) - { - if (T36HZEnabled) - { - *ptr = 0; - } - else - { - if (DSPBuffer[i] > 32767) - *ptr = 32767; - else if (DSPBuffer[i] < -32767) - *ptr = -32767; - else - *ptr = DSPBuffer[i]; - } - } - - Buffer_fill += SPCSize * 2; - Buffer_tail += SPCSize * 2; - if (Buffer_tail >= Buffer_len) Buffer_tail = 0; - } - SDL_UnlockAudio(); + Buffer_fill += 512; + Buffer_tail += 512; + if (Buffer_tail >= Buffer_len) { Buffer_tail = 0; } + } + SDL_UnlockAudio(); } void clearwin()