Writing WAV (not bwav)


#1

This is for another user on KVR (jupiter8) who’s slow to register here!

He’s having trouble writing a WAV file that can be read by audacity, as it always writes a BWAV. He doesn’t know how to make it write a standard wave file. Here’s his post:


#2

That’s pathetic if audacity can’t parse a WAV properly. A BWAV is just a WAV with extra stuff in the header, so any parser that correctly reads RIFF files should just ignore the extra bits and skip straight to the audio, without even needing to understand the BWAV format at all.

Anyway, looking at my WavAudioFormatWriter code, it does write an ordinary wav file if you pass it an empty StringPairArray. It’s easy enough to step through that code in the debugger and see what’s happening, so he should try that and let me know if there’s a real bug here, or if it’s just him making newbie mistakes.


#3

[quote]While you’re at it,i can’t even make a new directory.
How sad is that ? Just create one single new directory on my harddrive should’nt be that hard but i’m struggling. [/quote]

…erm, File::createDirectory() isn’t too hard to understand, is it??


#4

Hi everybody. For some strange reason the wav works just fine now.
No crashes in Audacity. I can even play it in Windows Media Player which came as a surprise as it is a 32 bit float and i can’t play 24 bit files in media player. It still registers length as zero seconds and minutes though but it’s no biggie for me for the moment.

And the directory thing works as a charm as well. Thank you very much.
I’m not even going to say what i did wrong but it is one of the noobiest noobie mistakes you can make. :smiley:


#5

I just discovered something strange right now.
When i create a new wav file in my program and open it in Audacity or Media Player the file is empty. So i opened it in Cubase and it works fine there. When i shut down Cubase for some strange reason it works again in media player and Audacity.


#6

Could cubase be tampering with the file at all?

(And welcome to juce land)


#7

Cubase should leave the file alone but apparently it does’nt. Have some new dicoveries. It crashed the Audacity 1.3 beta. It opens as an empty file in Audacity 1.2. When i tried to open the file in QT it complained that the movie (sic) had the wrong duration. So there is definitly something funky with it reporting 0:00 sec length.

Anyways here’s what i’ve done so far, codewise:[code]
test = new WavAudioFormat();
theDate = new Time(2004, 12, 21, 10, 12, 0, 0);

	directory  = new File("c:\\Wav Export");
	if (!directory->exists()){
		directory->createDirectory();
	}
	outputFile = new File("c:\\Wav Export\\test.wav");
	outputTo = outputFile->createOutputStream(); 
	StringPairArray stringPair(true); 
	stringPair = test->createBWAVMetadata("wave file", "test1", "test2", *theDate, 44100, "test3"); 
	writer = test->createWriterFor(outputTo, 44100, 1, 32,stringPair, 0); 
	buffer2->writeToAudioWriter(writer,0,buffer2->getNumSamples());[/code]

#8

Looking at your code, my first thought is “have you closed the file properly?” Obviously you have to delete the audiofilewriter object or it won’t flush its data, which would leave a half-written file on disk.


#9

That’s it,thanks.
I’ve been programming Java for 18 months now so i kinda forgot you have to clean up after yourself in C++. :oops:


#10

Always check the program’s output for the leaked object report when your app quits - you should never have anything in there.


#11

I am guessing that “directory” is a pointer (obviously)? To make it so you do not have to cleanup, don’t use a pointer for such things…

[code]
theDate = Time(2004, 12, 21, 10, 12, 0, 0);

  directory = File("c:\\Wav Export");
  if (!directory.exists()){
     directory.createDirectory();
  }
  outputFile = File("c:\\Wav Export\\test.wav");
  outputTo = outputFile.createOutputStream();[/code]

Etc… He put operator=()'s in his classes for a reason. :slight_smile:
Not to mention you will get a speed boost thanks to not needing to dereference pointers on use and all such as well.


#12