Empty .wav file from writeFromAudioSource()

I’m trying to write a file from my AudioSource class implementation, which has an inner AudioTransportSource as its source of data. Here’s my code:


The output file has 0 second of length, but still has a size about 70Mb.
Values of the above variables:
samplePerBlockExpected: 1920
processSpec->sampleRate: 48000
readerSource->getAudioFormatReader()->lengthInSamples: 9482112
readerSource->getAudioFormatReader()->bitsPerSample: 32

Thanks for any help.

The writer returned by format.createWriter is a raw pointer and needs to be deleted after writing the data, which also finalizes the file as a proper wav file. Didn’t you get a Juce memory leak warning about that?

And i get this error:

There must be some deletion order problem happening, I’d need to check what’s the correct way to do it in your code since you deal a bit differently with the file output stream object.

This is how I am doing it :

juce::File outfile(path);
    outfile.deleteFile();
    auto ostream = outfile.createOutputStream();
    WavAudioFormat wav;
    auto writer = wav.createWriterFor(ostream.release(), sr, 2, 32, {}, 0);
    // my processing loop...
    delete writer;

Hey, it works! You’re always my saviour Xenakios

The audio now has the time length of 3:17. But the original audio is 3:35 and it’s silence, i can not hear anything, here’s my getNextAudioBlock():


When performing playback, the transportSource.getNextReadPosition() give incremental numbers. But when writing the audio, it just gave 0 all the times

Difficult to say without seeing all of the code…You might need to start the transport source, seek it to the beginning etc before doing the offline render.

Here’s the rest of it:


It’s a simple code to test writing the same file out by buffer

Yes i did call stop and seek it to 0
Oh so i need to call start again?

Yes it has sound now but it cut like 20 last seconds of the audio,
is the value returned by readerSource->getAudioFormatReader()->lengthInSamples not correct?

P/s: The input is a .mp3 file