Paula (Amiga) inspired audio driver [0.95 - envelopes]
First working alpha (0.08) 0.95 beta attached.
Not optimal for time or memory use - optimization is TODO for next versions. There is also an unsolved problem which can make this driver to stop working after about 1000 seconds due to the internal counter overflow. This is solved now
Paula is an Amiga 4-channel sample based audio chip. Every channel can have its own sample rate. This means:
- no resampling. No interpolating, filtering and aliases added to resampled sound. Instead, every sample is outputted "as is"
- if the sample is one period type (for chiptunes) or has exactly integer number of wave periods, aliases introduced by Paula (using low sample rate) are harmonics. This means they rather adds to the sound instead of to be annoying, alien, non-harmonic noise
So, the goal was to make a synthesizer which can do exactly that, and exactly at original Paula sample rate so it can be easily used for Amiga modules.
The problem was of course computation time. At about 3.5 MHz sample rate the program has to determine if the new sample from every channel needs to be outputted, and if, the driver has to retrieve the sample from the hub memory. At 320 MHz I have only 90 clocks for this. It is simply not possible, one RDxxx can take 17 cycles and if it happens that all 4 channels have to be updated at the same time, there has to be much more than 90 clocks to compute this.
And the P2 cog has only 1 streamer and 1 FIFO
The solution is: the Amiga uses low sample rates. Even at 35 kHz there is a hundred Paula cycles, 9000 P2 clocks between samples. This means I have a lot of time to compute them. The 3.5 MHz procedure has only to output the sample at the proper time.
So the main sample outputting procedure uses interrupts from a DAC channel. It reads the next sample to output and its time from LUT circular buffer. In the meantime the synthesizer computes the sample values and times to output and places them in the buffer.
This allowed me to write enhanced version of a "Paula like thing". It can play 8 and 16 bit samples (sample type selectable for the channel) and stereo pan them - in 8 channels.
The driver with a test sine wave sample attached below.