- Home /
Recording audio from another audio source
If I were to open up any audio recording program, the basic function is that I can click record, speak into a microphone, and then click stop, and that portion of audio is recorded to a file. How would that principle work if instead of audio coming into a microphone as the input, the input audio to capture would be audio playing from another audio file?
I know there is convenient method calls like Microphone.start() and Microphone.stop(), but I doubt that can be used without a microphone. If this is something I will need to use GetOutputData(), then I have no idea how to use that call.
I appreciate any help.
It looks like you're going to need to use GetOutputData(), which clearly isn't very well documented. I would suggest doing some tests with GetOutputData() to see exactly how it behaves. $$anonymous$$y guess is that there's some standard audio block size.
You could set up a script that samples the audio listener occasionally, uses GetOutputData() to put that in a buffer, and use SetData() on an audio clip to hear exactly what was recorded, just to see what's going on.
I'm doing that now, I'm just struggling to figure out what exactly the data that GetOutputData is returning. It seems to be an array of sorts. I have no idea what to do with it. I guess I'm not really sure how to do what you say just yet.
The data is likely just pure sample data from the master audio. So as a guess, floats normalized between 0 and 1. If you want to record it, you're going to need to save all of that data to disk/memory on the fly as new blocks come in. The biggest issue will be deter$$anonymous$$ing when you hit the next block, and not missing any.
based on it's definition
function GetOutputData (samples : float[], channel : int) : void
isn't samples defining the size of the block?
Yes, you must allocate the samples array with the necessary size, and GetOutputData fills it with audio samples (floats between -1 and 1). Use AudioSettings.outputSampleRate to define how big the array must be: if you want to sample 10 seconds, for instance, allocate the array like this:
var samples = new float[10 * AudioSettings.outputSampleRate];
If you want to save the sound as a file, take a look at this question.