Issue Deleting FileInputStream && Reading Wav File


Hello all,

I'm trying to extract some data from a .wav file using FileInputStream. Here is a code snippet of how I think this should be done with JUCE.

void FilterGraph::importFIRFilter(File filterFile)
    FileInputStream* fileInputStream = filterFile.createInputStream();
    ScopedPointer<AudioFormatReader> wavReader;
    WavAudioFormat wavAF;
    if(fileInputStream != nullptr){
        wavReader = wavAF.createReaderFor(fileInputStream, false);
        ScopedPointer<AudioSampleBuffer> buffer = new AudioSampleBuffer(2, FFT_SIZE);
        CFFT fft; 
            wavReader->read(buffer,0,fftSize,0, true, true);
            float *data = buffer->getArrayOfChannels()[0];
            float outReal[FFT_SIZE], outIm[FFT_SIZE], outMag[FFT_SIZE/2];
        delete fileInputStream;

VS throws an exception here:

    delete input;

By changing the fileInputStream to a ScopedPointer an exception is thrown here. I cannot determine what object is trying to be deleted, but something tells me it's the AudioFormatReader..

struct ContainerDeletePolicy
    static void destroy (ObjectType* object)
        delete object;

I have tried a few variations of the code but am unable to determine why this is happening! I'm still a student, so my experience is limited. Thanks for your help and C++ know-how.



If I let the fileInputStream memory leak the program quits complaining and everything runs smoothly. This leads me to believe something is happening in the destructor that shouldn't. I think this answers my question, but I would like someone to confirm that I indeed do not need to call delete here as the memory has been managed elsewhere. I passed my pointer to AudioSampleBuffer which may have deleted it.


The AudioFormatReader deletes the stream that you give it (it does explain this if you read its comments!)