2

I am currently creating a convolution reverb plugin for university, and I have downloaded an already made convolver library for use with in the plugin. I have some code that generates an impulse response however I am not quite sure how to load an actual audio file in to the process.

Here is the convolver class:

class FFTConvolver
{  
public:
  FFTConvolver();  
  virtual ~FFTConvolver();

  /**
  * @brief Initializes the convolver
  * @param blockSize Block size internally used by the convolver (partition size)
  * @param ir The impulse response
  * @param irLen Length of the impulse response
  * @return true: Success - false: Failed
  */
  bool init(size_t blockSize, const Sample* ir, size_t irLen);

  /**
  * @brief Convolves the the given input samples and immediately outputs the result
  * @param input The input samples
  * @param output The convolution result
  * @param len Number of input/output samples
  */
  void process(const Sample* input, Sample* output, size_t len);

  /**
  * @brief Resets the convolver and discards the set impulse response
  */
  void reset();

private:
  size_t _blockSize;
  size_t _segSize;
  size_t _segCount;
  size_t _fftComplexSize;
  std::vector<SplitComplex*> _segments;
  std::vector<SplitComplex*> _segmentsIR;
  SampleBuffer _fftBuffer;
  audiofft::AudioFFT _fft;
  SplitComplex _preMultiplied;
  SplitComplex _conv;
  SampleBuffer _overlap;
  size_t _current;
  SampleBuffer _inputBuffer;
  size_t _inputBufferFill;

  // Prevent uncontrolled usage
  FFTConvolver(const FFTConvolver&);
  FFTConvolver& operator=(const FFTConvolver&);
};

And here is the code I have used to implement an impulse response (but not an audio file):

//convolver
    ir.ensureStorageAllocated (512);
    zeromem (ir.getRawDataPointer(), 512 * sizeof(float));
    ir.set (0, 1.0f);


    for (int i = 0; i < 10; ++i)
    {
        ir.set (Random::getSystemRandom().nextInt (512),
                Random::getSystemRandom().nextFloat() * 2.f - 1.f);
    }

    convolver.init (128, ir.getRawDataPointer(), 512);

and in the process block...

convolver.process (inputData, channelData, buffer.getNumSamples());

Can anyone tell me how I can use an actual audio file of an impulse response?

willfo
  • 241
  • 1
  • 2
  • 12

2 Answers2

1

JUCE can help you here, the most relevant parts of the documentation appear to be:

OMGtechy
  • 7,935
  • 8
  • 48
  • 83
  • I have added an edit of an attempt at reading an audio file but I am still receiving errors, am I on the right lines? – willfo Oct 22 '15 at 14:37
  • @willfo if you've solve your initial problem (which it looks like you have), please mark this as accepted, revert your edit, and make a new question regarding the new problems with the JUCE components. I'll be happy to help there! It makes it easier for other users searching for answers to their problems if each question asks exactly one thing. – OMGtechy Oct 22 '15 at 14:54
0

The easiest solution is to read an uncompressed .WAV file. That's a trivial file format, you can parse it easily. Since it's uncompressed, you can access the samples using a int16_t*

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Are you implying that every sample has 16 bit? Even Wav is not that simple. – deviantfan Oct 22 '15 at 11:58
  • Could you possibly give an example of how i could load the .wav file in to the function? – willfo Oct 22 '15 at 12:19
  • @deviantfan: **Uncompressed** single-channel WAV files are in fact that simple. We've got several gigabytes of those. @ willfo: Wouldn't fit in a comment and is copyrighted by my employer, but writing your own .WAV parser isn't hard. Wikipedia has the right format. – MSalters Oct 22 '15 at 14:27