Unverified Commit 7e998de9 authored by Brad Smith's avatar Brad Smith Committed by GitHub
Browse files

sound.c restore original whitespace from the copied code (see audio.c Audio_CallBack)

parent 305b122d
...@@ -1441,67 +1441,74 @@ void Sound_Update(bool FillFrame) ...@@ -1441,67 +1441,74 @@ void Sound_Update(bool FillFrame)
extern short signed int SNDBUF[1024*2]; extern short signed int SNDBUF[1024*2];
static void Retro_Audio_CallBack(int len) static void Retro_Audio_CallBack(int len)
{ {
Sint16 *pBuffer; Sint16 *pBuffer;
int i, window, nSamplesPerFrame; int i, window, nSamplesPerFrame;
pBuffer = (Sint16 *)&SNDBUF[0];
len = len / 4; // Use length in samples (16 bit stereo), not in bytes pBuffer = (Sint16 *)&SNDBUF[0];
/* Adjust emulation rate within +/- 0.58% (10 cents) occasionally, len = len / 4; // Use length in samples (16 bit stereo), not in bytes
* to synchronize sound. Note that an octave (frequency doubling)
* has 12 semitones (12th root of two for a semitone), and that /* Adjust emulation rate within +/- 0.58% (10 cents) occasionally,
* one semitone has 100 cents (1200th root of two for one cent). * to synchronize sound. Note that an octave (frequency doubling)
* Ten cents are desired, thus, the 120th root of two minus one is * has 12 semitones (12th root of two for a semitone), and that
* multiplied by 1,000,000 to convert to microseconds, and divided * one semitone has 100 cents (1200th root of two for one cent).
* by nScreenRefreshRate=60 to get a 96 microseconds swallow size. * Ten cents are desired, thus, the 120th root of two minus one is
* (2^(10cents/(12semitones*100cents)) - 1) * 10^6 / nScreenRefreshRate * multiplied by 1,000,000 to convert to microseconds, and divided
* See: main.c - Main_WaitOnVbl() * by nScreenRefreshRate=60 to get a 96 microseconds swallow size.
*/ * (2^(10cents/(12semitones*100cents)) - 1) * 10^6 / nScreenRefreshRate
pulse_swallowing_count = 0; /* 0 = Unaltered emulation rate */ * See: main.c - Main_WaitOnVbl()
if (ConfigureParams.Sound.bEnableSoundSync) */
{
/* Sound synchronized emulation */ pulse_swallowing_count = 0; /* 0 = Unaltered emulation rate */
nSamplesPerFrame = nAudioFrequency/nScreenRefreshRate;
window = (nSamplesPerFrame > SoundBufferSize) ? nSamplesPerFrame : SoundBufferSize; if (ConfigureParams.Sound.bEnableSoundSync)
/* Window Comparator for SoundBufferSize */ {
if (nGeneratedSamples < window + (window >> 1)) /* Sound synchronized emulation */
/* Increase emulation rate to maintain sound synchronization */ nSamplesPerFrame = nAudioFrequency/nScreenRefreshRate;
pulse_swallowing_count = -5793 / nScreenRefreshRate; window = (nSamplesPerFrame > SoundBufferSize) ? nSamplesPerFrame : SoundBufferSize;
else
if (nGeneratedSamples > (window << 1) + (window >> 2)) /* Window Comparator for SoundBufferSize */
/* Decrease emulation rate to maintain sound synchronization */ if (nGeneratedSamples < window + (window >> 1))
pulse_swallowing_count = 5793 / nScreenRefreshRate; /* Increase emulation rate to maintain sound synchronization */
/* Otherwise emulation rate is unaltered. */ pulse_swallowing_count = -5793 / nScreenRefreshRate;
} else
if (nGeneratedSamples >= len) if (nGeneratedSamples > (window << 1) + (window >> 2))
{ /* Decrease emulation rate to maintain sound synchronization */
/* Enough samples available: Pass completed buffer to audio system pulse_swallowing_count = 5793 / nScreenRefreshRate;
* by write samples into sound buffer and by converting them from
* 'signed' to 'unsigned' */ /* Otherwise emulation rate is unaltered. */
for (i = 0; i < len; i++) }
{ if (nGeneratedSamples >= len)
*pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][0]; {
*pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][1]; /* Enough samples available: Pass completed buffer to audio system
} * by write samples into sound buffer and by converting them from
CompleteSndBufIdx += len; * 'signed' to 'unsigned' */
nGeneratedSamples -= len; for (i = 0; i < len; i++)
} {
else /* Not enough samples available: */ *pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][0];
{ *pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][1];
for (i = 0; i < nGeneratedSamples; i++) }
{ CompleteSndBufIdx += len;
*pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][0]; nGeneratedSamples -= len;
*pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][1]; }
} else /* Not enough samples available: */
/* If the buffer is filled more than 50%, mirror sample buffer to fake the {
* missing samples */ for (i = 0; i < nGeneratedSamples; i++)
if (nGeneratedSamples >= len/2) {
{ *pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][0];
int remaining = len - nGeneratedSamples; *pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][1];
memcpy(pBuffer, ((Uint8*)SNDBUF)+(nGeneratedSamples-remaining)*4, remaining*4); }
} /* If the buffer is filled more than 50%, mirror sample buffer to fake the
CompleteSndBufIdx += nGeneratedSamples; * missing samples */
nGeneratedSamples = 0; if (nGeneratedSamples >= len/2)
} {
CompleteSndBufIdx = CompleteSndBufIdx % MIXBUFFER_SIZE; int remaining = len - nGeneratedSamples;
memcpy(pBuffer, ((Uint8*)SNDBUF)+(nGeneratedSamples-remaining)*4, remaining*4);
}
CompleteSndBufIdx += nGeneratedSamples;
nGeneratedSamples = 0;
}
CompleteSndBufIdx = CompleteSndBufIdx % MIXBUFFER_SIZE;
} }
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment