COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 03-12-2015, 11:47 AM   #1
alex_
Human being with feelings
 
Join Date: Mar 2015
Posts: 10
Default C++ array variables from impulse response

Hey people!

So I´m kind of a IPlug beginner having troubles.
i want to implement a impulse response into my plugin, by using Tales convolution example - the one in which he converted a IR.wav into C++ array variables.
Now i see the conversion code and i understand it writes array variables into a header file, but i have no clue how to actually use it to get those filter coefficients of my impulse response.

Or is there a simpler way to get filter coefficients of an IR.wav?

greets
alex_ is offline   Reply With Quote
Old 03-13-2015, 12:41 AM   #2
Tronic
Human being with feelings
 
Join Date: Jan 2012
Posts: 91
Default

If your filter is an FIR filter, then the filter coefficients are the values of the impulse response.

If you have an IIR filter, then the filter coefficients are not the same as the impulse response.
Tronic is offline   Reply With Quote
Old 03-13-2015, 01:16 AM   #3
alex_
Human being with feelings
 
Join Date: Mar 2015
Posts: 10
Default

Ok, i found a way to extract the values of my IR.wav.
not with the code provided by Tale, but with Will Pirkles Rackafx Impulse Convolver Module.
Talking about an FIR filter here.
The thing is, when I export h(n) values to text i get something like this:

"m_h_Left[0] = 0.1187110617756844;"

but for the IPlug Convo Example I need values like that:

"4.24553603e-002f,"

I suppose this two formats are not interchangeable, or are they?
alex_ is offline   Reply With Quote
Old 03-13-2015, 02:07 AM   #4
alex_
Human being with feelings
 
Join Date: Mar 2015
Posts: 10
Default

Ok, just figured it out - the values in ir.h of tales convo example can be changed to Rackafx h(n) values.

replaced them, and testet it - works like a charm
alex_ is offline   Reply With Quote
Old 03-13-2015, 02:13 AM   #5
Tronic
Human being with feelings
 
Join Date: Jan 2012
Posts: 91
Default

it's is the scientific notation of the number 0.0424553603 -> 4.24553603e-002f
so 0.1187110617756844 -> 1.187111e-1
Tronic is offline   Reply With Quote
Old 03-14-2015, 01:55 AM   #6
alex_
Human being with feelings
 
Join Date: Mar 2015
Posts: 10
Default

good to know, thanks tronic !
alex_ is offline   Reply With Quote
Old 03-15-2015, 01:38 AM   #7
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: Holland
Posts: 2,904
Default

Just for the record, here is how to insert the converted IR header file into an array:

Code:
static const int ir_len = 1024;
float m_h_Left[ir_len] =
{
	#include "ir.h"
};
Or if you have two IRs, e.g. for left and right, then you could insert them into a single array:

Code:
float m_h[2][ir_len] =
{
	{
		#include "ir_left.h"
	},
	{
		#include "ir_right.h"
	}
};
Tale is offline   Reply With Quote
Old 03-17-2015, 12:24 PM   #8
alex_
Human being with feelings
 
Join Date: Mar 2015
Posts: 10
Default

actually i meant the convertor code, which i don´t know how to use to extract the IR from an IR.wav file.

Code:
// Impulse response (extracted from ir.wav using the convertor code below)

const float IPlugConvoEngine::mIR[] =
{
	#include "ir.h"
};



#include <stdio.h>
#include "../../../wdlendian.h"

int main(int argc, char* argv[])
{
	FILE* f = fopen(argv[1], "rb");
	fseek(f, 12, SEEK_SET);

	unsigned int i, n;
	for (;;)
	{
		fread(&i, 1, 4, f);
		fread(&n, 1, 4, f);
		n = WDL_bswap32_if_be(n);
		if (i == WDL_bswap32_if_le('data')) break;
		fseek(f, n, SEEK_CUR);
	}

	while (n > 0)
	{
		n -= fread(&i, 1, 4, f);
		printf("%.8ef,\n", (float)WDL_bswapf_if_be(i));
	}

	fclose(f);
	return 0;
}
alex_ is offline   Reply With Quote
Old 03-17-2015, 01:31 PM   #9
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: Holland
Posts: 2,904
Default

Quote:
Originally Posted by alex_ View Post
actually i meant the convertor code, which i don´t know how to use to extract the IR from an IR.wav file.
Ah OK... You have to copy-paste the the extractor code in a temporary CPP source file (e.g. extract.cpp), compile it, and then run it from the command line, and redirect its output to ir.h (i.e. extract ir.wav > ir.h).
Tale is offline   Reply With Quote
Old 03-17-2015, 02:53 PM   #10
alex_
Human being with feelings
 
Join Date: Mar 2015
Posts: 10
Default

Ok, that makes sense

Nice piece of code, thanks for that!
alex_ is offline   Reply With Quote
Old 01-26-2018, 07:01 AM   #11
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: Holland
Posts: 2,904
Default

Reviving old thread, but I have just uploaded an improved convertor, supporting not just 32-bit floating-point WAV files, but also 8/16/24-bit integer, and 64-bit float. It does require my WaverReader class now.

https://github.com/TaleTN/ir2h
Tale is offline   Reply With Quote
Old 02-17-2018, 10:32 AM   #12
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: Huddersfield, UK
Posts: 1,112
Default

very useful thanks Tale!
__________________
VirtualCZ | pMix | Endless Series | WDL-OL | Linkedin | Facebook
Available for Audio Dev tuition via Skype (IPlug/JUCE/C++)
olilarkin is offline   Reply With Quote
Old 02-17-2018, 11:10 AM   #13
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 649
Default

That is awesome. Thanks tale!
__________________
Website | Facebook Page | IPlug-Youlean
Youlean is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.