Audio Writing Questions


#1

JUCE newbie here trying to record some audio. Currently, the program throws an exception when I call write. I think this is probably due to the fact that I have no idea what to toss the createBWAVMetadata function.

What exactly are these parameters?

Here’s the two main functions that are actually doing anything in my audioStuff class… Does this all seem right?

[code]

WavAudioFormat test;
Time
theDate;
File* outputFile;
FileOutputStream* outputTo;
AudioFormatWriter* writer;

//////////////////////////////////////////////////////////////

test = new WavAudioFormat();
theDate = new Time(2004, 12, 21, 10, 12, 0, 0);
outputFile = new File(“c:\test.wav”);
outputTo = outputFile->createOutputStream(32768);

bool audioStuff::StartAudio(ASIOAudioIODevice *tempaudio)
{
audio = tempaudio;

audio->open(Inputs, Outputs, audio->getSampleRate(0), audio->getBufferSizeSamples(0));

isStreaming = true;


StringPairArray stringPair(true);
stringPair = test->createBWAVMetadata("wave file", "test1", "test2", *theDate, 44100, "test3");

audio->start(this);
writer = test->createWriterFor(outputTo, audio->getCurrentSampleRate(), 1, audio->getCurrentBitDepth(), stringPair, 0);

return true;

}

void audioStuff::audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)
{
int i, j, l;

if((totalNumOutputChannels == 0)||(totalNumInputChannels == 0))
{
	return;
}

l = 0;
for(j=0;j<NumChannels;j++)
{
	if(Inputs[j])
	{
		while(!Outputs[l]&&(l<NumChannels))
		{
			l++;
		}
		if(!Outputs[l])
		{
			break;
		}
		for(i=0;i<audio->getCurrentBufferSizeSamples();i++)
		{
			outputChannelData[l][i]=inputChannelData[j][i];
			writer->write((const int**)outputChannelData, numSamples);
		}
		l++;
	}
}

}[/code]


#2

…no, it’s throwing an exception because you’re passing a duff pointer into write(), and doing it once for every sample. There’s loads of help about the parameters to write() - have a read.


#3