PDA

View Full Version : Help with Brute force Convo


RRokkenAudio
03-05-2010, 08:25 PM
I can't quite figure this out, and I REALLY need it...



int GetLength() { return impulses[0].GetSize(); }
int SetLength(int samples); // resizes/clears all channels accordingly, returns actual size set (can be 0 if error)
void SetNumChannels(int usench); // handles allocating/converting/etc
int GetNumChannels() { return m_nch; }

Then theres this:


int SetImpulse(WDL_ImpulseBuffer *impulse, int fft_size=-1, int impulse_sample_offset=0, int max_imp_size=0);

int GetFFTSize() { return m_fft_size; }
int GetLatency() { return m_fft_size/2; }

void Reset(); // clears out any latent samples

void Add(WDL_FFT_REAL **bufs, int len, int nch);

int Avail(int wantSamples);
WDL_FFT_REAL **Get(); // returns length valid
void Advance(int len);



So, I imagine to get this going, I would do something like:

int SetImpulse(WDL_ImpulseBuffer *impulse, int fft_size=-1, int impulse_sample_offset=0, int max_imp_size=0);



Where am I actually supposed to POINT to the wave file? seems like WDL-ImpulseBuffer * impulse would be the area, but I have no clue how to do it, I just can't understand it without documentation :(

EDIT: Just seen this too! argh void Add(WDL_FFT_REAL **bufs, int len, int nch);

I'm almost ready to pay to have someone get this going ;)

~Rob.

RRokkenAudio
03-07-2010, 02:48 AM
guess i'll have to write one on my own.. ughhh

Tale
03-13-2010, 09:32 AM
Perhaps this will help: I've made a (very basic) example plug-in using the convolution engine. The example doesn't load an impulse response file, but instead creates an impulse response on the spot (much like the Echo Generator of ReaVerb). But it does show you how to setup the convolution engine, feed it samples, and use its output.

http://www.taletn.com/wdl/IPlugConvo.zip

junioreq
05-08-2010, 08:08 AM
BTW: I ended up doing something like this:

const int kNumPrograms = 1;


enum EParams
{
koutputtrans = 0, kpeakFreq = 1, kpregain = 2, koutgain = 3,kNumParams
};

enum eLayout
{
bgW = 220,
bgH = 122,
};
// /* Impulse response, Sample accurate */
double cabIR1441[N] = {0.006317138672,0.010101318359,-0.003875732422,-0.008697509766,-0.031341552734,-0.067779541016,-0.096008300781,-0.146942138672,-0.192901611328,-0.240020751953,-0.287994384766,-0.329467773438,-0.354522705078,-0.353729248047,-0.354431152344,-0.333099365234,-0.310333251953,-0.298492431641,-0.286560058594,-0.302917480469,-0.312194824219,-0.334197998047,-0.351715087891,-0.350250244141,-0.342742919922,-0.323455810547,-0.283813476562,-0.255523681641,-0.202026367188,-0.153259277344,-0.097747802734,-0.020507812500,0.059082031250,0.160003662109,0.259 429931641,0.382537841797,0.507354736328,0.63119506 8359,0.759674072266,0.862548828125,0.946533203125, 0.999938964844,0.999023437500,0.968872070312,0.870 056152344,0.728240966797,0.549530029297,0.32946777 3438,0.095550537109,-0.104644775391,-0.270996093750,-0.328002929688,-0.276733398438,-0.103302001953,0.153686523438,0.462646484375,0.694 793701172,0.843475341797,0.848175048828,0.73107910 1562,0.553039550781,0.373748779297,0.230773925781, 0.187377929688,0.194793701172,0.249633789062,0.292 999267578,0.315612792969,0.289306640625,0.23699951 1719,0.195312500000,0.161682128906,0.160858154297, 0.182922363281,0.213623046875,0.235931396484,0.250 579833984,0.263854980469,0.283477783203,0.30734252 9297,0.326843261719,0.349151611328,0.365234375000, 0.367126464844,0.375274658203,0.386291503906,0.389 709472656,0.399902343750,0.409301757812,0.41610717 7734,0.409454345703,0.394226074219,0.377441406250, 0.361816406250,0.346435546875,0.329223632812,0.318 267822266,0.319732666016,0.309631347656,0.29571533 2031,0.287628173828,0.269805908203,0.250946044922, 0.237030029297,0.218414306641,0.204956054688,0.203 643798828,0.197998046875,0.197723388672,0.20538330 0781};
double cabIR1882[N] = {0.239224553108,0.425848841667,0.612473130226,0.74 4270563126,0.876067996025,0.938033938408,0.9999998 80791,0.988494277000,0.976988673210,0.858135342598 ,0.739281892776,0.527599334717,0.315916776657,0.15 2759194374,-0.010398387909,-0.090391874313,-0.170385360718,-0.214513301849,-0.258641123772,-0.261281132698,-0.263921260834,-0.210482001305,-0.157042741776,-0.094288349152,-0.031534075737,0.028345584869,0.088225245476,0.126 647710800,0.165070176125,0.174688816071,0.18430757 5226,0.181078672409,0.177849769592,0.170783758163, 0.163717865944,0.142272710800,0.120827674866,0.089 543342590,0.058258891106,0.043447494507,0.02863597 8699,0.034528136253,0.040420293808,0.062619447708, 0.084818601608,0.108926296234,0.133033990860,0.137 068986893,0.141103982925,0.136117219925,0.13113033 7715,0.128700494766,0.126270532608,0.114141345024, 0.102012038231,0.078212022781,0.054412007332,0.036 924362183,0.019436836243,0.007948040962,-0.003540754318,-0.035814285278,-0.068087935448,-0.080427527428,-0.092767238617,-0.070707201958,-0.048647165298,-0.018744587898,0.011157870293,0.032631278038,0.054 104685783,0.057996511459,0.061888337135,0.06583523 7503,0.069782018661,0.064870715141,0.059959292412, 0.050762295723,0.041565179825,0.037420988083,0.033 276796341,0.030679821968,0.028082847595,0.03309452 5337,0.038106083870,0.032862544060,0.027618885040, 0.035804748535,0.043990731239,0.060090780258,0.076 190829277,0.076755166054,0.077319622040,0.06979274 7498,0.062265872955,0.047003388405,0.031740903854, 0.008093237877,-0.015554308891,-0.039595246315,-0.063636064529,-0.076691865921,-0.089747667313,-0.085386514664,-0.081025362015,-0.060412049294,-0.039798736572,-0.008977651596,0.021843433380,0.047752141953,0.073 660850525,0.083233714104,0.092806577682,0.09493315 2199,0.097059607506,0.089966535568,0.082873344421, 0.062366843224,0.041860342026,0.021566867828,0.001 273512840,-0.017221331596,-0.035716176033,-0.052138328552,-0.068560600281,-0.073027729988,-0.077494978905,-0.074152588844};
double cabIR1960[N] = {0.239224553108,0.410685658455,0.582146644592,0.71 2144970894,0.833233833313,0.912860274315,0.9697915 31563,0.995038151741,0.984467387199,0.945046901703 ,0.835850358009,0.716790676117,0.522307276726,0.32 7823996544,0.175193428993,0.025292396545,-0.066393852234,-0.139887809753,-0.194104075432,-0.234646558762,-0.259631156921,-0.262056708336,-0.252565383911,-0.203468084335,-0.153905034065,-0.096249461174,-0.038593888283,0.016743898392,0.071758270264,0.112 959742546,0.148260354996,0.169699192047,0.17853629 5891,0.183278322220,0.180311799049,0.176745653152, 0.170253872871,0.163761973381,0.144149184227,0.124 446511269,0.097364425659,0.068621873856,0.04955720 9015,0.035949110985,0.031140208244,0.036553621292, 0.046247601509,0.066642999649,0.087229371071,0.109 378337860,0.131527304649,0.136488914490,0.14019608 4976,0.137644410133,0.133062720299,0.129839539528, 0.127606987953,0.121797919273,0.110654115677,0.097 103357315,0.075237035751,0.053646922112,0.03758013 2484,0.021513462067,0.010245800018,-0.000309467316,-0.024115085602,-0.053766489029,-0.073949217796,-0.085286259651,-0.085873484612,-0.065605759621,-0.044161677361,-0.016688823700,0.010784149170,0.030618190765,0.050 346851349,0.056999206543,0.060574889183,0.06418251 9913,0.067808628082,0.067725419998,0.063213109970, 0.057602524757,0.049152731895,0.041176676750,0.037 369132042,0.033561706543,0.031069397926,0.02868342 3996,0.031528353691,0.036132812500,0.035353183746, 0.030535578728,0.030586242676,0.038107037544,0.047 210693359,0.062002658844,0.076212048531,0.07673048 9731,0.077249050140,0.071345090866,0.064429759979, 0.052631378174,0.038609027863,0.020655989647,-0.001070141792,-0.022916913033,-0.045004487038,-0.065512895584,-0.077507853508,-0.089502930641,-0.085822701454,-0.081815838814,-0.065823078156,-0.046884536743,-0.022076606750,0.006240248680,0.032530784607,0.056 334376335,0.076054096222,0.084849119186,0.09299266 3383,0.094946384430,0.096900105476,0.091074824333, 0.084558010101,0.068903326988};
//
///
//


SimpleDelay::SimpleDelay(IPlugInstanceInfo instanceInfo): IPLUG_CTOR(kNumParams, 6, instanceInfo) {
TRACE;


/* Set bounds */
GetParam(kpeakFreq)->InitDouble("Character", 3200.5,100.0, 7600.0, 0.1, "");
GetParam(kpregain)->InitDouble("Preamp", 0.0,-65.0, 65.0, 0.1, "");
GetParam(koutgain)->InitDouble("Output Gain", 0.0,-15.0, 15.0, 0.1, "");
GetParam(koutputtrans)->InitInt("ot", 1, 0,3);

/* Attatch graphics */
IGraphics* pGraphics = MakeGraphics(this, bgW, bgH);
pGraphics->AttachBackground(BG_ID, BG_FN);
AttachGraphics(pGraphics);
}

void SimpleDelay::OnParamChange(int ParamIdx){

fs = this->GetSampleRate();
tempo = this->GetTempo();
pregain = GetParam(kpregain)->DBToAmp();
outgain = GetParam(koutgain)->DBToAmp();

if(fs < 46000){cabIR1 = cabIR1441;}
else if(fs < 72000) {cabIR1 = cabIR1882;}
else if(fs < 92000) {cabIR1 = cabIR1960;}
cabIR = cabIR1;

}

void SimpleDelay::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
int oldest = 0;

double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];

for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2) {

/* Sum audio */
double input = signal.sum(*in1,*in2);

y = 0;

///* Apply cabinet impulse */

oldest = (oldest + 1) % N;
for (k = 0; k < N; k++)
{
y += cabIR[k] * x[(oldest + k) % N];
}
x[oldest] = input;
*out1 = y;
*out2 = y;

}




}


That runs about 10% cpu, so its really not Useful for much, but does work.

~Rob.

junioreq
07-06-2011, 08:22 PM
BTW, will WDL_FFT_REAL* be able to read in the following format:


buf[nSamples] = {0.006317138672,0.010101318359,-0.003875732422,-0.008697509766,-0.031341552734,-0.067779541016}


I tried it but it expects an expression. Would like to hardcode IRS right into this and the structure of Tales version is more line by line:

buf[int(0.1 * (double)nSamples)] = 0.5;
buf[int(0.2 * (double)nSamples)] = 0.46875;


Which for bigger irs, isn't going to work lol

Tale
07-06-2011, 11:22 PM
You could declare a static array, and then copy its contents:

static const float mIR[6];

...

const float mIR[6] = { 0.006317138672, 0.010101318359, -0.003875732422, -0.008697509766, -0.031341552734, -0.067779541016 };

...

memcpy(buf, mIR, sizeof(mIR));

Usually you would read the IR from file. However, this means you may need to convert the sample rate, which is a little advanced for a simple example (and for me). BTW, if you hardcode the IR, I think you still need to worry about the sample rate.

Tale
05-12-2012, 04:59 PM
Resurrecting this old thread... I have enhanced my IPlug convolution example by including an actual impulse response (a wave file converted to a C header file; convertor code included), and by resampling on the fly when necessary. I am using the resample code from WDL/pcmfmtcvt.h, which according to the official documentation is "shite" :D, but it's not that bad actually (for this purpose anyway). The new example is on the next branch of my WDL repository, in WDL/IPlug/Example/Convo.