if statement, long term memory

Jan 20, 2010 at 2:09am

if statement, long term memory

i am currently creating a compressor, i have rectified the waveform to make it easier to set the threshold, ive basically recreated the abs~ object using this following IF statement:

public void perform(MSPSignal[] ins, MSPSignal[] outs)
{

int i;
float[] in = ins[0].vec;
float[] out = outs[0].vec;
for(i = 0; i < in.length;i++)
{

if (in[i] < 0)

{
out[i] = in[i] * -1;
}

else

{
out[i] = in[i];
}

I need to make this IF statement remembered as a variable so i can refer to it in following code without worrying about retyping everything a million times, if anyone could assist me with setting an IF statement as a variable or let me know if it is even possible it would be much appreciated.

#47901
Jan 20, 2010 at 11:05am

you could write a method:

private void ifStatement(float[] in, float[] out, int i) {
    if (in[i]<0) {
        out[i] = in[i]*-1;
    } else {
        out[i] = in[i];
    }
}

and call that.

It looks like you want to create the absolute value of in. You could also use Math.abs():

out[i] = Math.abs(in[i]);
#172281
Jan 20, 2010 at 11:57am

I am not sure, but maybe you need to add the next header to the class:
import java.lang.Math;

#172282
Jan 20, 2010 at 5:28pm

thanks, could you please tell me how to constantly apply an equation to the input signal please? this is what i have tried so far but it returns an error message saying the equation code is out of bounds…

public void perform(MSPSignal[] ins, MSPSignal[] outs)
{

int i;
float[] in = ins[0].vec;
float[] out = outs[0].vec;

for(i = 0; i < in.length;i++)

{

if (input == Math.abs(in[i])

{

if (input < threshold)

{
out[i] = 1.0f;
}

else

{
out[i] = ratio;
}

#172283
Jan 21, 2010 at 8:32pm

instead of using in.length, try using ins[0].n

#172284

You must be logged in to reply to this topic.