Newbie trying to play with audio


#1

Hello all.

I’m new to this forum.
I played a little with juce during the last year.
But was only on midi.
So first : big congrats for this lib as it’s what helped me started c++.

Now i’m starting to play with the audio.
I’m just trying to open a wav file, fill an AudioSampleBufferfrom a reader, and then write a new wave File.
Of course the idea will be to play with the samples in the buffer.

Anyway, the code below is what i did.
the file “seems” to be opened fine and written, but i can’t open it in any audio editor. Except in vlc.
I believe i don’t use the metadata correctly.
Plus the sizes are different.

Anyone can tell me what’s wrong in it ?

Thanks a lot.

h

[code]#include “juce.h”

class CoreEngine : public Thread
{
public :
CoreEngine ();
~CoreEngine ();

public:

TextEditor* text;
ComboBox *projet;

String outFileName;
FileInputStream *fileInputStream;
FileOutputStream *fileOutputStream;
WavAudioFormat *format;
AudioFormatReader *reader;
AudioFormatWriter *writer;
AudioSampleBuffer *buffer;

void run();

juce_UseDebuggingNewOperator

};[/code]

cpp

[code]
void CoreEngine::run()
{
outFileName = “outwave.wav”;
text->setText(T(“Opening File”));
wait(1000);
fileInputStream = new FileInputStream(projet->getText());
fileOutputStream = new FileOutputStream(outFileName);
format= new WavAudioFormat;

text->setText(T("Creating Input"));
wait(1000);
reader = format->createReaderFor(fileInputStream,false);	

text->setText(T("Creating Output"));
wait(1000);
writer = format->createWriterFor(fileOutputStream,reader->sampleRate,reader->numChannels,reader->bitsPerSample,&reader->metadataValues,0);

text->setText(T("Creating Processor"));
wait(1000);
buffer = new AudioSampleBuffer(reader->numChannels,reader->lengthInSamples);

text->setText(T("Processing File"));
wait(1000);
buffer->readFromAudioReader(reader,0,reader->lengthInSamples,0,true,true);	

text->setText(T("Writing to Output"));
wait(1000);
buffer->writeToAudioWriter(writer,0,buffer->getNumSamples());

text->setText(T("Finished !!!"));
wait(1000);

}[/code]


#2

Nowadays, as soon as I see the phrases “newbie” and “files not being written properly” there’s no need to read any further to know the problem - delete your output stream when you’re finished with it!!


#3

Sorry but I didn’t write the file correctly.
i’m sure I just didn’t do it properly. That’s why i’m here.
Thanks for your answer.
I can open it actually, but as a raw wave, not as a .wav.
So I’ll try what you’re telling me and play more with it.


#4

[quote=“portscan”]Sorry but I didn’t write the file correctly.
i’m sure I just didn’t do it properly. That’s why i’m here.
Thanks for your answer.
I can open it actually, but as a raw wave, not as a .wav.
So I’ll try what you’re telling me and play more with it.[/quote]

Er, you sound a bit pissed-off there? Sorry, my answer was supposed to be friendly and jokey, not to be taken as a criticism. Loads of people seem to keep making this same mistake, but I can’t think of a good way to trigger an assertion or something to let them know about it.


#5

hum ok. :wink: just had a hard day.
i did what you told me to.
but i still can’t open it as a .wav
can you tell me where my mistake is ?
thanks.


#6

Just remember to delete the output stream object (and all your other memory leaks too, of course).