|
03-12-2015, 11:47 AM
|
#1
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
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
|
|
|
03-13-2015, 12:41 AM
|
#2
|
Human being with feelings
Join Date: Jan 2012
Posts: 104
|
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.
|
|
|
03-13-2015, 01:16 AM
|
#3
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
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?
|
|
|
03-13-2015, 02:07 AM
|
#4
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
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
|
|
|
03-13-2015, 02:13 AM
|
#5
|
Human being with feelings
Join Date: Jan 2012
Posts: 104
|
it's is the scientific notation of the number 0.0424553603 -> 4.24553603e-002f
so 0.1187110617756844 -> 1.187111e-1
|
|
|
03-14-2015, 01:55 AM
|
#6
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
good to know, thanks tronic !
|
|
|
03-15-2015, 01:38 AM
|
#7
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
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"
}
};
|
|
|
03-17-2015, 12:24 PM
|
#8
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
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;
}
|
|
|
03-17-2015, 01:31 PM
|
#9
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
Quote:
Originally Posted by alex_
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).
|
|
|
03-17-2015, 02:53 PM
|
#10
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
Ok, that makes sense
Nice piece of code, thanks for that!
|
|
|
01-26-2018, 07:01 AM
|
#11
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
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
|
|
|
02-17-2018, 10:32 AM
|
#12
|
Human being with feelings
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
|
very useful thanks Tale!
|
|
|
02-17-2018, 11:10 AM
|
#13
|
Human being with feelings
Join Date: May 2015
Location: Serbia
Posts: 654
|
That is awesome. Thanks tale!
|
|
|
01-05-2019, 11:13 PM
|
#14
|
Human being with feelings
Join Date: Sep 2018
Posts: 2
|
"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?
|
|
|
01-06-2019, 04:05 AM
|
#15
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
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 };
|
|
|
01-06-2019, 09:48 AM
|
#16
|
Human being with feelings
Join Date: Sep 2018
Posts: 2
|
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?
|
|
|
01-06-2019, 11:37 PM
|
#17
|
Human being with feelings
Join Date: Apr 2018
Posts: 396
|
Quote:
Originally Posted by e-zero
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.
|
|
|
03-20-2021, 09:18 AM
|
#18
|
Human being with feelings
Join Date: Mar 2021
Location: Germany
Posts: 4
|
Quote:
Originally Posted by Tale
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?
|
|
|
03-21-2021, 03:06 AM
|
#19
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
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.
|
|
|
03-22-2021, 01:28 AM
|
#20
|
Human being with feelings
Join Date: Mar 2021
Location: Germany
Posts: 4
|
Quote:
Originally Posted by Tale
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... )
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:20 AM.
|