Snial
Well-known member
As @MIST says, it'd be really helpful to look at the published code and read the previous postings. Firstly, I think the 'tick' or 'ticking' terminology is a bit unhelpful, because it appears to refer to an interrupt period, but in fact there's only ever one interrupt and it's the VBL one, which is at 60.15Hz.Yup, was thinking that one could have a VBL interrupt routine solely used for counting tick samples, ticking the replayer after N samples (for supporting MOD BPM), mixing audio, and transferring the block to the correct location in the hardware audio buffer.
The VBL interrupt always needs to copy the whole of a pre-prepared 370 byte buffer containing the mix-down of the 4 channels; to the Hardware audio buffer, because Hardware audio buffer samples are synchronous with the video scan line (1 sample per scan line, i.e. per 45µs). So, unlike an Amiga, it isn't possible to copy into the "right place" in the Hardware buffer, because you'd have to copy into the right place within the right time too. It's much like 'racing the beam' on an Atari 2600, because you are racing the beam, except to generate audio samples and not video as on the Atari 2600. Instead, the VBL copies the next 370 bytes of Generated samples (the pre-prepared buffer) to the hardware audio buffer and then calculates the mix-down of the next 370 samples and it needs to do that faster than the beam, because otherwise there's no CPU left. The way it does it is to calculate 370 samples for the first two channels, then mix-in 370 samples for the last two channels as that's the optimum given the number of registers on the 68000.
What is possible is to have an algorithm that schedules the Replayer which looks like this:
C:
uint16_t GenFrameSamples(uint16_t aStepSamples)
{
uint16_t tickSamples=370;
while(tickSamples>=0) {
uint16_t clipSamples;
if(aStepSamples>tickSamples) {
clipSamples=tickSamples;
} else {
clipSamples=aStepSamples;
}
GenSamples(clipSamples); // actually vectors into an unrolled loop to gen clipSamples samples.
tickSamples-=clipSamples; // play up to 370 samples this tick.
aStepSamples-=clipSamples; // and recalc after aStepSamples
if(aStepSamples==0) { // no more Step Samples, so
aStepSamples=Replayer(); // calc next pattern step.
}
}
return aStepSamples;
}
So, Replayer() is scheduled within a tick for the right number of samples in a given step. Effectively, this is what @MIST 's code does now, except aStepSamples is always 444.
Last edited: