Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Help needed for a valve gainstaging project

DSP related issues, mathematics, processing and techniques

Help needed for a valve gainstaging project

Postby jotb » Wed Sep 03, 2014 5:10 pm

Hello,

I am trying to build a flowstone project on basis of this article:
http://ses.library.usyd.edu.au/bitstrea ... ew%202.pdf

the principal is like:
input-> filter> gainstage>filter>gainstage and so on
after all stages there is a global mix control.
the formula for the gainstage is:
y= sin(x) + (abs(sin(x)))^8 – z
with y = output and x= input and z = static <= 0.2, which is something like the BIAS.
If I try to build this in flowstone, it often crashes and I get too much gain.
in the project, I had a waveplayer at the input, but with that, the filesize is to big to upload :cry:
Any help is welcome!
Attachments
gainstaging2_w_filters_test.fsm
(38.53 KiB) Downloaded 1280 times
jotb
 
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: Help needed for a valve gainstaging project

Postby MyCo » Wed Sep 03, 2014 9:14 pm

Code: Select all
streamin x;
streamout y;
float z = 0.001;

y=sin1(x) + (abs(sin1(x)))*(abs(sin1(x)))*(abs(sin1(x)))*(abs(sin1(x)))- z;


Jesus... get your math sorted first:
abs(sin(x)) ^ 8 = sin(x) ^ 8

The code above is actually only sin(x)^4 !!!!!!

then: store intermediate values:

tmp = sin(x)
tmp2 = tmp * tmp // <-- sin(x)^2
tmp2 = tmp2 * tmp2 // <-- sin(x)^4
tmp2 = tmp2 * tmp2 // <-- sin(x)^8

so finally:
Code: Select all
streamin x;
streamout y;
float z = 0.001;
float tmp,tmp2;

tmp = sin1(x);
tmp2 = tmp * tmp; // <-- sin(x)^2
tmp2 = tmp2 * tmp2; // <-- sin(x)^4

y=tmp + tmp2 * tmp2 - z;


Then, don't put everything onto one level of the schematic, there are reasons for the existing of modules! You can synchronize modules, so when you change one module all other synchronized ones are updated automatically.

When you use just one mono stream for your project, you can group them and use pack4 to process 4 steps at once. This is a more advanced topic but this allows a CPU reduction down to 1/4 when using 4 gain stages.

Finally: post a full schematic, so that we can test your problem without having to setup a test environment.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Help needed for a valve gainstaging project

Postby MyCo » Wed Sep 03, 2014 9:23 pm

Edit: just noticed that the code modules are different... first one's math line is too long, that's causing the crash
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Help needed for a valve gainstaging project

Postby jotb » Thu Sep 04, 2014 10:16 am

Thanks a lot! I will try to use your hints for a new schematic. I am new to flowstone and a little bit lost...

how did you know the line is too long in code modul is too long?

and tried to upload the full schematic, but the filesize limit of the forum ist only 4MB.
jotb
 
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: Help needed for a valve gainstaging project

Postby KG_is_back » Thu Sep 04, 2014 5:29 pm

jotb wrote:how did you know the line is too long in code modul is too long?
jotb wrote:Thanks a lot! I will try to use your hints for a new schematic. I am new to flowstone and a little bit lost...

how did you know the line is too long in code modul is too long?

and tried to upload the full schematic, but the filesize limit of the forum ist only 4MB.


DSP code is made for maximum performance, so it uses SSE assembly instructions and they operate on XMM registers (registers are small internal memory of the CPU, that the computer use to store intermediate values). There are 8 XMM registers in your processor, so you can have only 8 simultaneous operations in a single line, otherwise your CPU has nowhere to store the intermediate values, except RAM (by creating intermediate variable). However, DSP code compiler in FS is not smart enough to do this by itself, you have to do it manually.

Notice the Code module has a text output. The output is the assembly code that is compiled from your DSP code. In assembly code you may observe what actual operations are done with the variables in RAM and registers in CPU. Normally you should see only registers: xmm0,...,xmm7 (the 8 ones I mentioned + there are more like eax,ecx). When you use more then 8 simultaneous operations you will see the compiler will output some weird code (like registers xmm999 or so). That indicates your line in code is too long and you have to split it. It is also mentioned in the manual in the DSP code component section - read it and you'll see!
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Help needed for a valve gainstaging project

Postby jotb » Sat Sep 06, 2014 5:17 pm

Thank you for that explanation!

I have another math question:
I need to normalise the output of the gain-function, so the output (y) value is smaller than 1.
the original matlab code is something like:
y = x./max(abs(x));
where x is the input.
how do I do that in flowstone DSP?
jotb
 
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: Help needed for a valve gainstaging project

Postby KG_is_back » Sat Sep 06, 2014 5:48 pm

jotb wrote:Thank you for that explanation!

I have another math question:
I need to normalise the output of the gain-function, so the output (y) value is smaller than 1.
the original matlab code is something like:
y = x./max(abs(x));
where x is the input.
how do I do that in flowstone DSP?


The matlab code finds the biggest value in the x array (sequence of inputs) and then divides everything by it. In DSP this is not possible, because you are processing an endless stream of data (you can not know what will be next in the stream). To preform such task in DSP brickwall limiters are used - they temporarily cut the gain so it always fits <-1,1> range.
Another, more adequate solution is to make some kind of "automatic makeup gain" that will compensate volume change based on the algorithm parameters (the bias and filter cutoffs).
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Help needed for a valve gainstaging project

Postby jotb » Sat Sep 06, 2014 6:30 pm

oh. how do I realize that kind of automatic gain?
sorry I am a noob :oops:
jotb
 
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: Help needed for a valve gainstaging project

Postby KG_is_back » Sat Sep 06, 2014 7:23 pm

jotb wrote:oh. how do I realize that kind of automatic gain?
sorry I am a noob :oops:


There are multiple ways to do it. First prepare your schematic and use some kind of sample player (there are multiple examples here, on SM forum and flowstone.guru) and load a sample of audio that you assume will be used with this schematic (for example if your schematic should be a guitar amp then load prerecorded DI guitar). Now you need to create a table (on a paper) that would look something like this:
Code: Select all
|parameter A |parameter B |parameter C |... |input peak |input RMS|output peak| output RMS|
|            |            |            |    |           |         |           |           |
|            |            |            |    |           |         |           |           |
|            |            |            |    |           |         |           |           |

Now fill the table: use different A B or C parameter or different input volume and measure output peak values and RMS values

Following code may measure that for you (I recommend using it with analyzer primitive)
Code: Select all
streamin in;
streamout peak;
streamout RMS;
float T=0;
float C=0;
float A=0;
float n=0;
peak=max(peak,abs(in));

T=T+in*in;
C=T%1;
C=T-C;
A=A+C;
T=T-C;
n=n+1;
RMS=sqrt(A/n);


Now here comes the hard part. We need to approximate an equation of function gain=f(A,B,C,...)
Observe one parameter at a time and ask yourself following questions:
When other parameters are static, how does the output peak/RMS depend on this parameter? (linear? exponential? hyperbolic? ...)
When other parameter changes, does the output peak/RMS dependency on this parameter changes?

Now you may attempt to write an equation for the function (in ruby, DSP code or green) and test it with the schematic.
Multidimensional least squares method may be a good start when parameters seem to be more or less independent (you can find it in Excel as linest() )
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Help needed for a valve gainstaging project

Postby jotb » Mon Sep 08, 2014 10:08 am

wow. thanks a lot!
Just an idea how to make it a bit easier for me:
if I use a Sampleplayer with a guitar DI signal, theoretical the output is always max. 0 DB.
If I readout the output of each processing stage with max "gain", I thought I could divide the output of the stage, so that it does not exceed 1. Or is that just a stupid idea?
jotb
 
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Next

Return to DSP

Who is online

Users browsing this forum: No registered users and 29 guests