Reputation: 249
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?
Upvotes: 2
Views: 2061
Reputation: 8220
JUCE can help you here, the most relevant parts of the documentation appear to be:
Upvotes: 1
Reputation: 179789
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*
Upvotes: 0