Panning audio in Max Java
Hi,
I'm working with Java in Max MSP and i have created a delay effect. What i want to do now is be able to pan the original audio where i want but leave the delayed audio as it is.
Obviously I need to first create a second output for my Max Java Object which i have a rough idea on how to do but, I'm not sure on where i need to go after that.
If anyone could help me I would be more than grateful. I can send my code so far if anyone needs a look.
This is a very easy thing to do. What do you think is holding you up? It's just a matter of creating a class that extends MSPPerformer (which Max will do for you), then writing about four or five lines of trivial code.
I can't make my Max work properly at the moment (see other post). But, this is approximately what you want, I believe.
Please do not hand my code in as an assignment, if it's an assignment. That would be plagiarism. I'm just showing you the techniques that I use, and I hope you can learn from this example.
This is a bit more fancy than I mentioned above, but is still a trivial program. It just shows you how easy Java is to use with Max/MSP.
*sigh*
Edit: Ignore this.
I'm having a £*$£$ day of it. I can't test the above program, and just noticed that it doesn't copy the input into the delay line. This might work :(
import com.cycling74.max.*;
import com.cycling74.msp.*;
public class delayPanAudio extends MSPPerformer
{
private float pan = 0.5f;
private float mix = 0.5f;
private float delay[];
private int cursor;
private static final String[] INLET_ASSIST = new String[]{
"input (sig) + pan (float)", "mix (float)"
};
private static final String[] OUTLET_ASSIST = new String[]{
"left (sig)", "right (sig)"
};
public delayPanAudio(float gain)
{
declareInlets(new int[]{SIGNAL,DataTypes.FLOAT});
declareOutlets(new int[]{SIGNAL,SIGNAL});
setInletAssist(INLET_ASSIST);
setOutletAssist(OUTLET_ASSIST);
}
public void dspsetup(MSPSignal[] ins, MSPSignal[] outs)
{
int sr = (int) ins[0].sr;
delay = new float[ sr ];
cursor = 0;
}
public void inlet( float f )
{
if ( getInlet() == 0 )
{
if ( f >= 0 && f
{
pan = f;
}
}
else if ( getInlet() == 1 )
{
if ( f >= 0 && f
{
mix = f;
}
}
}
public void perform(MSPSignal[] ins, MSPSignal[] outs)
{
int i;
float[] in = ins[0].vec;
float[] out1 = outs[0].vec;
float[] out2 = outs[1].vec;
for(i = 0; i < in.length;i++)
{
float delayed = delay[ cursor ];
delay[cursor] = in[i];
cursor = ( cursor + 1 ) % delay.length;
float pannedLeft = in[i] * pan;
float pannedRight = in[i] * (1.0f-pan);
out1[i] = pannedLeft * (1.0f-mix) + delayed * mix;
out2[i] = pannedRight * (1.0f-mix) + delayed * mix;
}
}
}