Now I have a very noisy output, because I am sending the 4 channels to the DAC as it would be only a stereo. So channel 3&4 is interleaved with channel 1&2. I did some modifications, to at least hear one of the two stereo streams.
For now I defined another buffer for the audio samples of Deck1 and one for Deck2. The size is half of the main audio buffer size. In each Data_out phase, I have 384 bytes of data. This amount is made of 2 byte samples of 1,2,3,4 channels interleaved, and I have 48 of this packets in each frame (each 1ms). I have to split it into two with tha samples of 1,2,1,2,1,2… and 3,4,3,4,3,4.
I could do it with a memory-to-memory DMA. I need to transfer the first samples (4 bytes or 32bits) of channel 1&2 to the separate Deck1 buffer. Than increase the base addres, copy channel 3&4 to Deck2 and do the same for 48 times with some global variables and with the transfer complete callback after each sample. I will do it maybe later. For now I only separated the channels in the Data_out callback with a simple for cycle. I can select which stereo stream I would like to hear with a simple offset of 4 bytes.
This was just a slight modification to hear the correct sound for testing. I don’t really know how much time it takes to copy the buffer into the separate Deck1 and Deck2 buffers. I can hear some crackling if I do the byte copy for both decks. So for now I did it only for Deck1, and tha crackling dissapeared. Maybe copying bytes takes too long in the Data_out interrupt callback. I will optimize this part later, or try the DMA. But for now single deck is OK for development.
The next step will be to implement a more or less complete MIDI stack and to start the input stage. I’m going to figure out the input stage in the next few posts. How to use the ADC of STM32 to capture 4 channels. How to calculate the frequency. I have to reckon with the latency of this measurement, signal amplitude for some normalization and things like that. I have less experience in these kind of things than in the USB part, so maybe it will be more difficult for me.