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: 28
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: 28
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: 28
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: 28
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: The Netherlands
Posts: 3,256
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: 28
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: The Netherlands
Posts: 3,256
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: 28
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: The Netherlands
Posts: 3,256
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
 
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,243
Default

very useful thanks Tale!
__________________
VirtualCZ | Endless Series | iPlug2 | Linkedin | Facebook
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: 652
Default

That is awesome. Thanks tale!
__________________
Website | Facebook Page | IPlug-Youlean
Youlean is offline   Reply With Quote
Old 01-05-2019, 11:13 PM   #14
e-zero
Human being with feelings
 
Join Date: Sep 2018
Posts: 2
Default "too many initializers" in ir.h file that is produced

I am using the TALE converter and when I try to build my iPlug project with the new ir.h the file seems to be too big. I don't know how to avoid my ir.h file being too large. Any suggestions?
e-zero is offline   Reply With Quote
Old 01-06-2019, 04:05 AM   #15
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,256
Default

Actually "too many initializers" usually means that your doing something like:

Code:
// tbl can hold only 2 items, not 3.
float tbl[2] = { 1.0f, 2.0f, 3.0f };
The solution usually is:

Code:
float tbl[] = { 1.0f, 2.0f, 3.0f };
Tale is offline   Reply With Quote
Old 01-06-2019, 09:48 AM   #16
e-zero
Human being with feelings
 
Join Date: Sep 2018
Posts: 2
Default

Ok, so what I noticed is that the original iPlug code has 'mIR' declared as:

static const float mIR[512];

When analyzing my new converted IR it had 49468 values to process, so I changed 'mIR' to:

static const double mIR[49468];

My program builds now! Is it normal for an IR file to have that many values?
e-zero is offline   Reply With Quote
Old 01-06-2019, 11:37 PM   #17
Nonlinear
Human being with feelings
 
Join Date: Apr 2018
Posts: 391
Default

Quote:
Originally Posted by e-zero View Post
Is it normal for an IR file to have that many values?
If the sample rate is 44.1kHz that impulse would be only slightly more than a second long. Some reverbs are 10 seconds long or more, so yes, that can be a realistic number for an impulse response.
Nonlinear is offline   Reply With Quote
Old 03-20-2021, 09:18 AM   #18
rob81
Human being with feelings
 
Join Date: Mar 2021
Location: Germany
Posts: 3
Default

Quote:
Originally Posted by Tale View Post
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
Hey... Trying to build it with "nmake /f Makefile.msvc" but I always get this error:

Microsoft (R) Program Maintenance Utility, Version 14.28.29337.0
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

cl /O2 /fp:fast /D NDEBUG /W3 /D _CRT_SECURE_NO_WARNINGS /nologo ir2h.cpp
ir2h.cpp
ir2h.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_fopenUTF8" in Funktion ""public: int __thiscall WaveReader::Open(char const *)" (?Open@WaveReader@@QAEHPBD@Z)".
ir2h.exe : fatal error LNK1120: 1 nicht aufgelöste Externe
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bi n\HostX86\x86\cl.EXE"": Rückgabe-Code "0x2"
Stop.

What am I doing wrong? Or maybe could someone send me the exe?
rob81 is offline   Reply With Quote
Old 03-21-2021, 03:06 AM   #19
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,256
Default

Oops, you're right! I've just pushed a fix to GitHub, which simply #defines the WDL_NO_SUPPORT_UTF8 macro. I guess I could have included win32_utf8.c to actually add UTF-8 filename support, but meh.
Tale is offline   Reply With Quote
Old 03-22-2021, 01:28 AM   #20
rob81
Human being with feelings
 
Join Date: Mar 2021
Location: Germany
Posts: 3
Default

Quote:
Originally Posted by Tale View Post
Oops, you're right! I've just pushed a fix to GitHub, which simply #defines the WDL_NO_SUPPORT_UTF8 macro. I guess I could have included win32_utf8.c to actually add UTF-8 filename support, but meh.
Coool, thanks a lot!! works now!

(Soccer-skills mostly mediocre but you guys seem to play in the upper class when it comes to programming-stuff... Ups, I have an urgent appointment... )
rob81 is offline   Reply With Quote
Old 11-22-2021, 03:21 AM   #21
KeroLine
Banned
 
Join Date: Nov 2021
Posts: 10
Default

Quote:
Originally Posted by Tale View Post
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"
	}
};
good answer!
KeroLine 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 04:50 PM.


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