Forums > Java

if statement, long term memory

January 20, 2010 | 2:09 am

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.


January 20, 2010 | 11:05 am

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]);


efe
January 20, 2010 | 11:57 am

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


January 20, 2010 | 5:28 pm

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;
}


January 21, 2010 | 8:32 pm

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


Viewing 5 posts - 1 through 5 (of 5 total)