On Oct 15, 2007, at 11:47 AM, MacArthur, Ian (SELEX) (UK) wrote:

>
>> The NES actually runs at a somewhat
>> awkward 60.1 Hz... and produces a fixed amount of audio
>> samples each frame.
>
> 60.1? Really? That is weird...

The best way to write an emulator with sound support is to use the  
sound as a timebase for everything. The oscillator on the sound board  
mayeven be much more stable than whatever generates timer interrupts  
on your OS.

I recommend that you write your main loop in standard FLTK using  
Fl::run(). Then write an emulator running in a second thread for all  
functions that fills an RGB buffer with video data and an audio  
buffer whit sound data.

Whenever you reach the end of your 60 Hz emulation cycle, call  
something like this:

for(;;) {
emulate();
waitForInt();
Fl::lock()
myNESScreen->redraw();
Fl::unlock();
Fl::awake();
sendSoundAndInt();
}

Now the main FLTK lopp wll kick in and bring your RGB buffer onto the  
screen.

sendSoundAndInt() is your function that sends just enough samples to  
fill the 60th of a second and when done creates an interrupt to let  
you know that the sound buffer is empty (and a 60th of a second is  
over). Of course you will need to double-buffer the sound.

That way, your GUI runs in the main thread without ever interfering  
with your emulator, and all your emulator has to do is fill the RGB  
buffer, not having to care about the deatails of the true screen  
buffer etc.



----
http://robowerk.com/


_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to