Make sound processing use less CPU cycles.

This commit is contained in:
n-a-c-h
2005-11-26 17:24:40 +00:00
parent b80ce23ef6
commit cd578b0e73

View File

@@ -1048,11 +1048,8 @@ void sem_sleep_die(void)
void UpdateVFrame(void) void UpdateVFrame(void)
{ {
const int SPCSize = 256;
int i;
//Quick fix for GUI CPU usage //Quick fix for GUI CPU usage
if (GUIOn || GUIOn2 || EMUPause) usleep(6000); if (GUIOn || GUIOn2 || EMUPause) { usleep(6000); }
CheckTimers(); CheckTimers();
Main_Proc(); Main_Proc();
@@ -1061,31 +1058,31 @@ void UpdateVFrame(void)
/* take care of the things we left behind last time */ /* take care of the things we left behind last time */
SDL_LockAudio(); SDL_LockAudio();
while (Buffer_fill < Buffer_len) { while (Buffer_fill < Buffer_len)
{
short *ptr = (short*)&Buffer[Buffer_tail]; short *ptr = (short*)&Buffer[Buffer_tail];
SoundProcess(); SoundProcess();
for (i = 0; i < SPCSize; i++, ptr++)
{
if (T36HZEnabled) if (T36HZEnabled)
{ {
*ptr = 0; memset(ptr, 0, 256*sizeof(short));
} }
else else
{ {
if (DSPBuffer[i] > 32767) int *d = DSPBuffer;
*ptr = 32767; int *end_d = DSPBuffer+256;
else if (DSPBuffer[i] < -32767) for (; d < end_d; d++, ptr++)
*ptr = -32767; {
else if (*d > 32767) { *ptr = 32767; }
*ptr = DSPBuffer[i]; else if (*d < -32767) { *ptr = -32767; }
else { *ptr = *d; }
} }
} }
Buffer_fill += SPCSize * 2; Buffer_fill += 512;
Buffer_tail += SPCSize * 2; Buffer_tail += 512;
if (Buffer_tail >= Buffer_len) Buffer_tail = 0; if (Buffer_tail >= Buffer_len) { Buffer_tail = 0; }
} }
SDL_UnlockAudio(); SDL_UnlockAudio();
} }