@Jules & friends - I have made quite a bit of progress over the last few days with the recorder application you have kindly helped me with in another thread (writing multitrack audio to disk). The audio portion (which although can use a few changes) is working well for now, and so I’ve spent the last couple days working on implementing and extending the JUCE style serial classes from http://www.anticore.org/juce/ for recording the sensor data as audio.
Basically, right now I am trying to get serial-data from sensors (via an Arduino) writing to disk in .wav format, synchronously with incoming audio, so that I can analyze the audio/sensor data for machine learning and other research projects I am working on as part of my PhD.
I just got a non-sexy, first effort try working pretty quickly, but wanted to ask if besides some of the larger structural changes I will make to fully implement this, if you guys for see any issues with the way I am currently doing things, in particular, either in synchronicity of the outputted audio/sensor recording, or with any problems that might arise from read/write access to a single array from two asynchronous sources. Heres how I have it set up.
My SerialRecorder class has a changeListenerCallback which gets called whenever my arduino has new data from the sensor (right now for testing, just a single potentiometer, connected at 9600baud, and sending data with a 10::ms sampling delay in between messages)-- it then fills an array (the same size as my audio buffer) with this one number (sort of a brute sample and hold method).
My SerialRecorder also registers an AudioIODeviceCallback with the same audio manager as my audio recorders. In here, just like my audio recorders, is where I add the samples to a circularbuffer (the same way as my AudioRecorders, and derived from the audio recording demo and Jules’ help). The difference is, instead of passing in one of the channels from my AudioIODevice / inputChannelData, I pass in the array with I’m continuous refilling with the newest sensor data in my sensor callback.
In this way, I was hoping to asynchronously have my sensor callback fill the array with the newest sensor sample data, as fast as it samples the sensor, and then have it actually pass to circularbuffer and write to disk synchronously with the incoming audio / audio recorders.
Do you see any issues with this approach? Particularly if the AudioIODeviceCallback is trying to access the sample array as the serial callback is trying to rewrite the array with the newest data?
Thanks for your help!


and working in C++ in general. I have a question about how “kosher” something I am doing is-- I suspect it may not be very safe. Perhaps you (or another community member) can shed some light?