Can someone please explain to me where I am going wrong in my understanding? I am using the audio expander caplet and would like to use the first four analog inputs as audio inputs. In the render function I have used the included examples to create the most minimal possible code to see if I can understand what is going on:
for(unsigned int n = 0; n < context->analogFrames; ++n)
for(unsigned int ch = 0; ch < context->audioOutChannels; ++ch)
audioWrite(context, n, ch, analogRead(context, n, ch));
So the first
for loop acts a a kind of scanner, right? It scans through all the frames in one block and executing its code for each frame. The rest of the functions that follow use the
n varaible to syncronize themselves with the frame?
Am I then right in thinking that:
for loop worksout how many audio outputs there are and then uses that number as the amount of times the code is excuted.
The excuted code runs an audioWrite function which in turn writes the values returned from the analogRead function to the audio buffer.
The audioWrite function uses the
ch variable to cycle through its corresponding outputs.
The analogRead function uses the
ch variable to cycle through its corresponding analog inputs.
When running the following code with four audio sources plugged in to the first four audio inputs on the audio caplet and using the jumper cables to connect them to the first four analog inputs. Then enabling the audio caplet in the IDE and toggling the first four audio caplet inputs. I am only hearing the first piezo input on the first audio output and the second audio input on the second output. This unexpected, I assume that I need to increase the amount of channels that the analogRead function cycles through to hear all four inputs, but I though that I might hear both the inputs on both audio outputs.
With all that said, I would have thought that I could hard code the values for the audioOutChannels variable and the audioWrite
ch variable like so:
for(unsigned int ch = 0; ch < 4; ++ch)
audioWrite(context, n, 0, analogRead(context, n, ch));
Using the above logic, I would have thought that this (ugly) test would read four analog inputs and write them all to the first audio output. However, the result is that only the fourth analog input is read.
I cant understand why this does not work, if I hard-code the analogRead
ch variable I hear the corresponding analog input as expected.
If someone has the time to explain this embarrassingly rudimentary problem to me I would be very grateful.