Real-Time Convolution with FFT within a Plug-In
DSP, Plugin and Host development discussion.
Moderator: KVR Moderators (Main)
Real-Time Convolution with FFT within a Plug-In
2012-05-24T18:18:20+00:00
Hey folks!
I try to program a little audio unit plug-in that convolves the audio track with an impulse response given by the plug-in. i know that i need an fft algorithm that transfers the audio file's real signals to their spectra,multiplies the two spectra of the audio files and then returns them to their real signals. studying the "Audio Programming Book" i found an fft-based convolution algorithm that covers this operation.
unfortunately this algorithm does not cover REAL-TIME convolution, which is of course absolutely necessary for a plug-in (is it?). nevertheless the book says:
"This function will not serve for real-time purposes. However, it can be modified for this kind of application, by processing one FFT block at a time and leaving the overlapp-add to be performed by the invoking code ."
(i'll post the code at the end of my post!)
alright..concerning this i have a couple of questions that i just can't figure out myself, since i'm pretty new to this programming-audio-units-thing.
1. what exactly do i need to change within the code in order to make this function work within a real-time plug-in? maybe somebody can rewrite it or add the stuff needed if it isn't much work, because now i'm not making any progress. if not, maybe someone can show me the place in the code that needs to be changed and tell me how it needs to be changed.
2. how and at which location within the audio unit code do i load the impulse response? i couldn't figure that out, because i didn't find any examples that showed how to load a sound and where to load it within the code.
3. is there someone that knows audio units well or at least has some basic knowledge of them that can answer me further questions concerning that topic? that would help me A LOT! i read all i could find about them but some little things still aren't clear to me and i don't want to post a list of 20 lil questions in here. (maybe via email or personal message? would be just AWESOME)
since this is concerning my bachelor thesis, any help would be marvellous :)
tl;dr
anyone familiar with real-time convolution and/or audio units? holla at me :)
thank you guys very much in advance and greetings from germany!
patrick
void convol(float* impulse, float* input, float* output,
int impulse_size, int input_size){
float *impspec, *inspec, *outspec; // spectral vectors
float *insig, *outsig, *overlap; // time-domain vectors
int fftsize=1, convsize; // transform and convolution sizes
int overlap_size; // overlap size
int count, i, j; // counter and loop variables
overlap_size= impulse_size - 1;
convsize = impulse_size + overlap_size;
while(fftsize < convsize) fftsize *= 2;
impspec = new float[fftsize]; // allocate memory for
inspec = new float[fftsize]; // spectral vectors
outspec = new float[fftsize];
insig = new float[fftsize];
outsig = new float[fftsize];
overlap = new float[overlap_size];
// get the impulse into the FFT input vector
// pad with zeros
for(i = 0; i < fftsize; i++){
if(i < impulse_size) insig[i] = impulse[i];
else insig[i] = 0.f;
}
// Take the DFT of impulse
fft(insig, impspec, fftsize);
// processing loop
for(i = count = 0; i < input_size+convsize; i++, count++){
// if an input block is ready
if(count == impulse_size && i < (input_size+impulse_size)){
// copy overlapping block
for(j = 0; j < overlap_size ; j++)
overlap[j] = outsig[j+impulse_size];
// pad input signal with zeros
for(j = impulse_size; j < fftsize; j++)
insig[j] = 0.f;
// Take the DFT of input signal block
fft(insig, inspec, fftsize);
// complex multiplication
// first pair is re[0Hz] and re[Nyquist]
outspec[0] = inspec[0]*impspec[0];
outspec[1] = inspec[1]*impspec[1];
// (a+ib)*(c+id) = (ac - bd) + (ad + bc)i
for(j = 2; j < fftsize; j+=2){
outspec[j] = inspec[j]*impspec[j]
- inspec[j+1]*impspec[j+1];
outspec[j+1] = inspec[j]*impspec[j+1]
+ inspec[j+1]*impspec[j];
}
// IDFT of the spectral product
ifft(outspec, outsig, fftsize);
// zero the sample counter
count = 0;
}
// get the input signal
// stop when the input is finished
if(i < input_size)
insig[count] = input[i];
else insig[count] = 0.f;
// overlap-add output starts only
// after the first convolution operation
if(i >= impulse_size)
output[i-impulse_size] = outsig[count] +
(count < overlap_size ? overlap[count] : 0.f);
}
// de-allocate memory
delete[] overlap;
delete[] outsig;
delete[] insig;
delete[] outspec;
delete[] inspec;
delete[] impspec;
}
[/code]
bountyhunter2010
https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=279730
-
- Banned
- 12367 posts since 30 Apr, 2002 from i might peeramid
Return to “DSP and Plugin Development”
Jump to
- The Main Forums
- ↳ KVR Studio Manager
- ↳ Getting Started (AKA What is the best...?)
- ↳ Instruments
- ↳ Effects
- ↳ Hosts & Applications (Sequencers, DAWs, Audio Editors, etc.)
- ↳ Guitars
- ↳ Mobile Apps and Hardware
- ↳ Soundware
- ↳ Samplers, Sampling & Sample Libraries
- ↳ Hardware (Instruments and Effects)
- ↳ Modular Synthesis
- ↳ Sound Design
- ↳ Production Techniques
- ↳ Music Theory
- ↳ Computer Setup and System Configuration
- ↳ DSP and Plugin Development
- ↳ DIY: Build it and they will come
- ↳ Music Cafe
- ↳ Sell & Buy (+Special Offers, Deals & Promos)
- ↳ KVR Experts
- ↳ KVR Developer Challenge 2026
- ↳ Everything Else (Music related)
- ↳ Off Topic
- ↳ Off Topic Classics
- ↳ Machine Learning and AI for Music Creation
- Official Company Forums
- ↳ 2getheraudio
- ↳ accSone
- ↳ Acon Digital
- ↳ AcousticsampleS
- ↳ AcousModules
- ↳ Agitated State
- ↳ AIR Music Technology
- ↳ AMG
- ↳ Ample Sound
- ↳ Antares Audio Technologies
- ↳ Apisonic Labs
- ↳ APU Software
- ↳ apulSoft
- ↳ AriesCode
- ↳ Arts Acoustic
- ↳ Arturia
- ↳ Audjoo
- ↳ AudioSpillage
- ↳ Audiority
- ↳ Best Service
- ↳ Big Tick
- ↳ Bitwig
- ↳ Controller Scripting
- ↳ Blue Cat Audio
- ↳ Cherry Audio
- ↳ CWITEC
- ↳ Embertone
- ↳ energyXT
- ↳ Eventide
- ↳ Expert Sleepers
- ↳ forward audio
- ↳ Future Audio Workshop
- ↳ FXpansion
- ↳ g200kg
- ↳ Harrison Mixbus
- ↳ HG Fortune
- ↳ Homegrown Sounds
- ↳ HoRNet Plugins
- ↳ Ilya Efimov Production
- ↳ Image Line
- ↳ Impact Soundworks
- ↳ Indiginus
- ↳ Insert Piz Here
- ↳ Ju-X
- ↳ Kirk Hunter Studios
- ↳ Kirnu
- ↳ Kong Audio
- ↳ Krotos
- ↳ Kuassa
- ↳ KV331 Audio
- ↳ LennarDigital
- ↳ Les Productions Zvon
- ↳ Liqube Audio
- ↳ Loomer
- ↳ LVC-Audio
- ↳ Maizesoft
- ↳ Manytone Music
- ↳ Media Overkill (MOK)
- ↳ MeldaProduction
- ↳ Mellowmuse
- ↳ MIDIMood
- ↳ moForte
- ↳ Mozaic Beats
- ↳ mucoder
- ↳ MusicDevelopments
- ↳ Tips & Tricks
- ↳ MusicLab
- ↳ MuTools
- ↳ New Sonic Arts
- ↳ NUSofting
- ↳ Oli Larkin Plugins
- ↳ Orange Tree Samples
- ↳ patchpool
- ↳ Photosounder
- ↳ PlugInGuru
- ↳ Polyverse Music
- ↳ Precisionsound
- ↳ Premier Sound Factory
- ↳ Psychic Modulation
- ↳ Realitone
- ↳ Resonance-Sound
- ↳ Reveal Sound
- ↳ Roger Linn Design
- ↳ rs-met
- ↳ S3A: Spatial Audio
- ↳ SaschArt
- ↳ Smart Electronix
- ↳ sonible
- ↳ SonicBirth
- ↳ Sonic Reality / eSoundz.com
- ↳ Soundiron
- ↳ SPC Plugins
- ↳ Sugar Bytes
- ↳ TAL Software
- ↳ Tokyo Dawn Labs
- ↳ Tracktion
- ↳ Tweakbench
- ↳ u-he
- ↳ u-he Linux support
- ↳ UJAM
- ↳ United Plugins
- ↳ VAZ Synths
- ↳ Virharmonic
- ↳ xoxos
- ↳ XSRDO - SynthCraft
- ↳ ZynAddSubFX
- Site Stuff
- ↳ Site Stuff
- Archived Forums
- ↳ AlgoMusic
- ↳ easytoolz
- ↳ Elevayta
- ↳ Hollow Sun
- ↳ LinPlug
- ↳ Muse Research and Development
- ↳ Shuriken
- ↳ SoHa Sound Design
- ↳ Soniccouture
- ↳ Topten Software
- ↳ Valhalla DSP
- ↳ CK Modules & VST
- ↳ Sennheiser AMBEO
- ↳ Muon Software
- ↳ Westgatesounds.net
- ↳ Squaredheads
- ↳ Sonigen
- ↳ CFA-Sound
- ↳ Back In Time Records
- ↳ Livelab.dk
- ↳ Skytopia
- ↳ audioD3CK
- ↳ Inspire Audio
- ↳ Krakli
- ↳ Drumdrops
- ↳ Futucraft
- ↳ OverTone DSP
- ↳ RaXnTraX
- ↳ solar3d-software
- ↳ Signaldust
- ↳ Soundemote
- ↳ ReleaseLab (Powered by Artist Expansion)
- ↳ Wolfgang Palm
- KVR Forum index
- All times are UTC
- Delete cookies
