[hatari-devel] Higher precision when generating samples

Nicolas Pomarède npomarede at corp.free.fr
Tue Jan 25 21:08:07 CET 2011


Le 24/01/2011 05:03, David Savinkoff a écrit :
> Hi,
>
> With tos206uk.img (50Hz) I do not notice problems with delay or otherwise
> at 44100 Hz or 11025 Hz sampling rates.
>
> The rounding is probably working.
>
>
>
> With tos206us.img (60Hz) the delay increases with at both 44100 Hz and
> 11025 Hz sampling rates. I patched Audio_CallBack() in audio.c to see
> what was going on.
>
> /* display excess samples count (+/-) */
> fprintf ( stderr, "%d\n", nGeneratedSamples-len);
>
> This patch displays numbers that are usually in the 1000 to 2000 range.
> If sound samples are being made too fast, the number gets bigger until
> MIXBUFFER_SIZE is reached. Something causes a buffer overflow!
> I get numbers that eventually exceed 16384. The sound gets bad at this
> point also.
>
> My best guess is that maybe the buffer doesn't wrap completely to the
> start, and spirals upward when too many samples are made.
>
> David

Hello,

the sync problem you have can come from 2 causes :
  - either you sound card doesn't output sound at the requested rate 
(although it says it does)

  - Main_WaitOnVbl doesn't (in your case) correctly emulates a 50Hz or 
60 Hz VBL

Either way, one of those 2 components would generate/play samples at a 
wrong rate, which explain the drift problem you have.

It would seem quite surprising that the sound card/driver can't output 
at the correct rate. One possible way to test this could to build a 
samples file with all 0 and a few ~100 consecutive 0xff bytes at the 
end. Build a 110250 bytes file and play this as 8 bit mono 11025 Hz.

If things go well, you should heard nothing, except a brief sound after 
exactly 10 seconds. If that's not the case, then the driver/card would 
be at fault.


Regarding Main_WaitOnVbl and the use of SDL_Delay / SDL_GetTicks, it's 
quite possible your kernel is built with a value of HZ set to 100, which 
means a maximum precision of 10 ms.

Can you run "hatari --log-level debug" and see if you have a line like :

Host system has accurate delays (1)


Is the delay always constant ? In my case, I sometimes get a delay at 60 
Hz, but it evolves with time (takes approx 20 sec) : at first there's no 
delay, then delay grows to ~1 sec, then it goes down again. Is this the 
same for you ?


Nicolas



More information about the hatari-devel mailing list