Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Help with FDN reverb design
Avatar
Chris_1
New Member
Members
September 29, 2019 - 10:05 pm
Member Since: September 29, 2019
Forum Posts: 2
sp_UserOfflineSmall Offline

I am having some trouble with an FDN reverb I am starting to design.  My plugin will compile, but whenever I run the plugin in rack AFX it crashes.  When I load it with the debugger it tells me that it cannot access memory when reading/writing from a circular buffer. 

Here is the relevant code in various section of the plugin:

Header Variables: 

float fdnCoef[24][24] = { 0 }; //Matrix of Coefiecents [current][target]
float globalRC= 0.9; //Global Reflections
float inputMatrix[2][24] = { 0 }; //[inch, node]
float outputMatrix[24][2] = { 0 }; //[node, outch]
double thisInput[24];
double thisOutput[24];
double delayTime[24];
double outputs[2] = { 0 };

ZVAFilter fdnFilters[24]; //Filters at the end of each delay line
SimpleDelay fdnDelay[24]; //Delay lines

/*
Basic model
nodes will always write into their assigned delay line. They will read from delay lines based on the coeficent matrix

inputMatrix[i][n] x thisInput[n] (according to input matrix)

fdnDelay[x] x fdnCoef[n][x] =+> thisInput[n] => fdnFilter[n] => globalRC => fndDelay[n]

thisOutput[n] x outputMatrix[n][i]

*/

added to reset function:

for (int n = 0; n < 24; n += 3) {

//Ahead
fdnCoef[n][n + 1] = 1.0;
fdnCoef[n + 1][n + 2] = 1.0;
//To the Left
fdnCoef[n][n + 3] = 0.9;
fdnCoef[n + 1][n + 4] = 0.9;
fdnCoef[n + 2][n + 5] = 0.9;
//To the Right
fdnCoef[n][n - 3] = 0.9;
fdnCoef[n + 1][n - 2] = 0.9;
fdnCoef[n + 2][n - 1] = 0.9;
//Initalize delay lines
fdnDelay[n].reset(resetInfo.sampleRate);
fdnDelay[n].createDelayBuffer(resetInfo.sampleRate, 100.0);

}
for (int n = 0; n < 25; n++) {
delayTime[n] = 10.0;
}

Stereo plug-in processor:

double inL = processFrameInfo.audioInputFrame[0];
double inR = processFrameInfo.audioInputFrame[1];

outputs[0] = 0;
outputs[1] = 0;

for (int n = 0; n < 24; n++) {
thisInput[n] = inL * inputMatrix[0][n];
thisInput[n] += inR * inputMatrix[1][n];
thisOutput[n] = 0;
for (int x = 0; x < 24; x++) {
float thisCoef = fdnCoef[n][x];
if (thisCoef != 0.0) {
thisOutput[n] += fdnDelay[x].readDelayAtTime_mSec(delayTime[x])*thisCoef;
}
}
thisOutput[n] += thisInput[n];
//Filter will go here

outputs[0] += thisOutput[n] * outputMatrix[n][0];
outputs[1] += thisOutput[n] * outputMatrix[n][1];

fdnDelay[n].writeDelay(thisOutput[n]);
}

processFrameInfo.audioOutputFrame[0] = outputs[0];
processFrameInfo.audioOutputFrame[1] = outputs[1];

return true; /// processed

Avatar
Tom
Admin
September 30, 2019 - 8:07 am
Member Since: April 3, 2014
Forum Posts: 71
sp_UserOfflineSmall Offline

Hi Chris,

 When I load it with the debugger it tells me that it cannot access memory when reading/writing from a circular buffer. 

Can you give the exact output of the debugger? Is this buffer part of your plugin or RackAFX?

Here is the relevant code in various section of the plugin:

Header Variables: 

I assume these are members of your class? Or are they "free"/global variables?

float fdnCoef[24][24] = { 0 }; //Matrix of Coefiecents [current][target]
float globalRC= 0.9; //Global Reflections
float inputMatrix[2][24] = { 0 }; //[inch, node]
float outputMatrix[24][2] = { 0 }; //[node, outch]
double thisInput[24];
double thisOutput[24];
double delayTime[24];
double outputs[2] = { 0 };

ZVAFilter fdnFilters[24]; //Filters at the end of each delay line
SimpleDelay fdnDelay[24]; //Delay lines

You are creating a lot of stuff here, and if the class is instantiated on stack, this might cause a stack overflow.

Also, check how you are accessing memory: You are probably leaving your array bounds here in multiple places:

fdnCoef[n][n + 1] = 1.0;
fdnCoef[n + 1][n + 2] = 1.0;
//To the Left
fdnCoef[n][n + 3] = 0.9;
fdnCoef[n + 1][n + 4] = 0.9;
fdnCoef[n + 2][n + 5] = 0.9;
//To the Right
fdnCoef[n][n - 3] = 0.9;
fdnCoef[n + 1][n - 2] = 0.9;
fdnCoef[n + 2][n - 1] = 0.9;
//Initalize delay lines
fdnDelay[n].reset(resetInfo.sampleRate);
fdnDelay[n].createDelayBuffer(resetInfo.sampleRate, 100.0);

}
for (int n = 0; n < 25; n++) {
delayTime[n] = 10.0;
}

Avatar
Chris_1
New Member
Members
September 30, 2019 - 10:05 pm
Member Since: September 29, 2019
Forum Posts: 2
sp_UserOfflineSmall Offline

Hey Tom,

Thank you for the quick reply.  I have it running now which was due to fixing my array bounds issues (I am a C++ novice and am use to higher level languages just wrapping things for me and there was that one "25" typo). 

I am doing all of those as free floating variables for now, but I am planning on making the thing into an fdn class that can create a network of n nodes.  Do you think instantiating too many of this class would create stack overflow and is there a better way of dealing with setting the coefficients than passing a huge array?  This is my first foray into lower level programming so I am sure that I am prone to making some rookie mistakes. 

Avatar
Tom
Admin
October 3, 2019 - 9:36 am
Member Since: April 3, 2014
Forum Posts: 71
sp_UserOfflineSmall Offline

Chris_1 said
Hey Tom,

Thank you for the quick reply.  I have it running now which was due to fixing my array bounds issues (I am a C++ novice and am use to higher level languages just wrapping things for me and there was that one "25" typo). 

You should also take care about the n+1/+2/-2 indices. They go out of bounds at the beginning and the end of your loop, too. C/C++ will allow you to do so - but still you are writing "somewhere" in memory, outside of the array. Probably you are overwriting something else. 

I am doing all of those as free floating variables for now, but I am planning on making the thing into an fdn class that can create a network of n nodes.  Do you think instantiating too many of this class would create stack overflow and is there a better way of dealing with setting the coefficients than passing a huge array?  This is my first foray into lower level programming so I am sure that I am prone to making some rookie mistakes.   

It depends 😉 If you create everything on stack, it will most likely become a problem. You have to consider that arrays in C++ are no separate objects, but they are part of the object's representation in memory (or of "global memory" if you don't use a class). An array of floats as a member variable is (at runtime) same as creating the same number of separate variables:

float data[4];

is equivalent to

float a;
float b;
float c;
float d;

Now, if you create arrays of delays, where each delay has arrays of buffers etc. this will add up really quickly.

The problem is not the amount of memory you need for this, but that you are requesting it as a single block of contiguous memory.

 

Another note: if you place all the variables in "global memory", you won't be able to instantiate more than one plugin!

I hope this helps 😉 If you need more help, maybe we should move the discussion into the "C++ Programming" area.

Forum Timezone: America/New_York

Most Users Ever Online: 55

Currently Online:
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 48

Derek: 46

Frodson: 45

TheSmile: 43

Peter: 41

clau_ste: 39

JimmyM: 33

Gwen: 32

EZB: 24

lppier: 23

Member Stats:

Guest Posters: 1

Members: 571

Moderators: 1

Admins: 4

Forum Stats:

Groups: 12

Forums: 36

Topics: 585

Posts: 2346

Newest Members:

Simple, Chris_1, manyu, AdamR, Stuart, Al Calabrese, frankthetank, dhodgson, Wanderer, mister1234

Moderators: W Pirkle: 351

Administrators: Tom: 71, JD Young: 80, Will Pirkle: 0, W Pirkle: 351