Today.. I'll tell you a little bit of buffer size and CPU resources
In Degenerator is much expected as real-time calculation of two oscillators, sampling, 3 LFO's, 2 Envelopes, Modulation Matrix, Graphical User Interface, Oscilloscope function and more. The processor resources from my "fast" ATMEL MCU (32MHz Xmega128A1) are unfortunately very scarce and I had to search for intelligent solutions to make everything work quickly and shorter. For later development we may need more CPU power, the replacement of the CPU board is designed for a board with a powerful ARM processor or similar.
The calculation routine for the oscillators (Pic 2 violet) requires 41% of the entire computing power in Xmega MCU. All 25 usec are two oscillator values (yellow) sent from a buffer to the two DAC outputs on Xmega. This will take about 1 usec and corresponds to a sample rate of 40KHz. Since it would be not efficient the oscillator values all 25usec recalculate (I did it before). Now.. I use a doublebuffer function to calculate and save values for the oscillator. In a 25usec timer interrupt read oscillator values from buffer and sent to the DAC. Theory is simple but it is a bit complicated to program. The buffer is actually two double buffer with 80 bytes for both oscillators. I illustrate the operation of the doublebuffer function for one oscillator.
Image 1: Doublebuffer
Function mode of doublebuffer
Image 1: The closed circuit illustrates the sequence, as in a constant repetition after the second buffer again, the first follows. Each buffer holds here 40 samples, corresponding to a latency of 1 ms. As this 1ms arise is easy to understand. When starting playback, the cursor is at the point marked. 0 Since the start of the reproduction of the first buffer has been playing the software copies the data first into the second buffer. Imagine (in slow motion), as the pointer moves clockwise. At a sample rate of 40 kHz, 40 samples are processed in only 1 ms. When the pointer reaches the boundary between the buffers (position 1) an interrupt is triggered, and the software calculates the next 40 samples and stores them in the (now processed) first buffer. The second buffer will be played at the end (position 0) an interrupt is triggered, Sampels be calculated again and copied into the second buffer .. The whole buffer repeats itself endlessly.
Figure 2: Time interval of the buffer function
Yellow: 25 microseconds interval for sample output to the DAC (approximately 1usec)
Violet: 1 ms interval for the calculation of 80 samples (approximately 412usec)
In the next post the topic buffer and Midi goes latency
Best wishes from Germany. Rolf