|
It seems like it would be tricky. I'm in the area of making NSF players... not full emus... so I don't have to deal with as precise of timing as you might have to.
All I can say is you definatly -SHOULDN'T- round off to the nearest whole number... as that will throw notes off key (especially notes with lower wavelengths)
Anyway... how I have my player running... is I keep track of how many cycles are needed per sample (as a floating point variable). Then I keep another floating point var as a sort of counter. The counter is decreased by the number of CPU cycles executed... when the counter goes under 0, a new sample is generated, and the counter is incrimented by the CyclesPerSample variable.
Hard to explain... so here's sample code as a description... hope you know C/C++
---------------------------
float fTicksPerSample; //number of cpu cycles between generated samples (40.5844) float fSampleCounter = fTicksPerSample; //the counter
void DoAPUTicks( int ticks ) //ticks is the number of cycles to do { int doticks;
while(ticks > 0) { // make it so we only do one sample at a time doticks = (int)fSampleCounter + 1; if(doticks > ticks) doticks = ticks;
// in my player, I clock other stuff here, like the frame counter
// here... clock all the sound channels 'doticks' cycles
fSampleCounter -= ticks; if(fSampleCounter <= 0) { fSampleCounter += fTicksPerSample; //add another sample to the sound buffer } } }
---------------------------
hope that kind of makes sense. That's similar to how I do it and it's peachy. If you round off though, it WILL go off key... I tried it before.
|