[hatari-devel] Higher precision when generating samples -> use nanosleep
David Savinkoff
dsavnkff at telus.net
Wed Jan 26 22:19:53 CET 2011
>
> But that's what my latest committed patch does : it really computes the
> exact number of samples, adjusting it by +1 when needed to take care of
> the rouding errors.
>
> Uncomment line 1147 in sound.c and you will see the number of generated
> samples ; doing the sum on 1 second should give the same number of
> samples as the current replay frequency.
>
> I understand what your patch does, and I agree with the method, but now
> that my latest fix computes the right number of samples, we should only
> have to modify Main_WaitOnVbl().
> For example, to emulate a nearly correct 60 Hz VBL, we would alternate
> between 16.66 ms and 16.67 ms using nanosleep(). No need to modify
> sound.c or audio.c.
>
>Nicolas
>
Yes. sound.c may not have to be touched by my code.
Integrate the following into main.c Main_WaitOnVbl():
/* Increase emulation rate to maintain sound synchronization */
if (nSamplesToGenerate + nGeneratedSamples < SoundBufferSize + nSamplesPerFrame)
/* Shorten emulated VBL time by given number of ms/FRAME_TICK_FACTOR */
nFrameTickSkew = -20;
else
{
if (nSamplesToGenerate + nGeneratedSamples > SoundBufferSize + nSamplesPerFrame*2)
/* Decrease emulation rate to maintain sound synchronization */
nFrameTickSkew = 20;
else
nFrameTickSkew = 0;
}
And remove it from sound.c Sound_SetSamplesPassed()
David
More information about the hatari-devel
mailing list