# Audio Writing Questions

**URL:** <https://forum.juce.com/t/audio-writing-questions/148>\
**Category:** General JUCE discussion\
**Created:** [December 22, 2004, 12:28am UTC](https://forum.juce.com/t/audio-writing-questions/148 "2004-12-22T00:28:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dialogue](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Dialogue](https://forum.juce.com/u/Dialogue)\
**Post date:** [December 22, 2004, 12:28am UTC](https://forum.juce.com/t/audio-writing-questions/148/1 "2004-12-22T00:28:06Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 28, 2004, 10:38pm UTC](https://forum.juce.com/t/audio-writing-questions/148/2 "2004-12-28T22:38:22Z")

</div>

…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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:50am UTC](https://forum.juce.com/t/audio-writing-questions/148/3 "2017-05-12T09:50:55Z")

</div>

Closed on May 12, 2017, 9:50am UTC


