Trying to create a wav file?

EDIT: NVM im a dunce, was overwriting my path :stuck_out_tongue: cheers from quarantine

I have a file dialog which gets created but then after I hit save, no file is created? All examples i see in other posts use AudioSampleBuffer::writeToAudioWriter but this method doesn’t seem to exist anymore?

How else can I create a wav file from an AudioSampleBuffer?

    String strPath = File::getCurrentWorkingDirectory().getFullPathName();
    strPath.append(m_poSampleData->m_strName, m_poSampleData->m_strName.length());
    File oFile(strPath);

    FileOutputStream* outputTo = oFile.createOutputStream();

    WavAudioFormat format;
    AudioFormatWriter* writer = format.createWriterFor(outputTo,
        44100,
        2,
        16,
        {},
        0);
    writer->writeFromAudioSampleBuffer(m_poSampleData->m_oAudioBuffer, 0, m_poSampleData->m_oAudioBuffer.getNumSamples());

    FileChooser oFileChooser("Save sample", oFile, ".wav");
    oFileChooser.browseForFileToSave(true);

    delete writer;
1 Like

But please change

AudioFormatWriter* writer = format.createWriterFor(...);

to

std::unique_ptr<AudioFormatWriter> writer (format.createWriterFor(...));

and get rid of the delete… :slight_smile:
See RAII