I’m currently writing an application in which it should be possible to record and play back audio as well as MIDI. This seems to be harder than I thought.
Let’s start with audio recording:
In the JUCE demo this is done by streaming directly to a file. My idea was to stream the samples to a vector (for each channel) in the main memory. Since I’ll be using no more than 2 channels, it seems to me that space won’t be an issue. Since a vector doubles in size when it’s underlying array is full, streaming to a vector is prone to glitches.
I’m struggling to get the samples from the callback to my main thread so I can get them into these vectors. Since I can’t seem to find any examples on how to accomplish this, I was wondering if this was bad practice?
If not, does JUCE provide classes to aid this operation? And again, if not, does anyone have any suggestions on how to tacke this problem?
As far as MIDI recording is concerned:
I would like to record incoming MIDI messages to a MIDIMessageSequence in memory. Since the rate of incoming MIDI messages is much lower than the samplerate of digital audio, it seems that this task is less tedious than recording audio. MIDI and audio can be recorded together, so it would be nice if the timestamps of the MIDI messages are synchronised with the audio samples. Though what if I record MIDI without recording audio, do I use some sort of timer class to timestamp the messages, and how do I transfer them from the callback to the main thread?
Do I use a timer, passing MIDI messages to the callback whenever the timer exceeds their timestamp?
As you can see I’m new to audio programming and I’m still trying to find out what the good and bad practices are, so every word of advice is very much welcome!
Maybe I’m not the only one with these questions and we can make this into a general recording thread in which all JUCE classes concerning recording are discussed.
(Or maybe the answers to these questions are trivial, which would explain why nobody has asked them yet :oops: )