乒乓延迟

时间:2014-03-12 20:20:37

标签: max delay ping pong

我正在做一个项目,我需要为Max / Msp(mxj~)开发一个实现立体乒乓延迟的Java类,而且我对Java很新。新对象的用户应该能够通过对象的入口改变左右声道的延迟参数(时间和反馈)。我有基本的'骨架'对于代码,但我正在努力的部分,我需要使用户可以调整延迟参数以及如何编码乒乓延迟的主要部分。我感谢任何帮助!干杯:)

到目前为止,这是我的代码:

public class CW1 extends MSPPerformer {
   float[] _circBuffer = new float[44100]; // Maximum delay of 1 second at 44.1 SR
   int _delayTime = 22050; // Delay of half a second
   int _readIndex1 = 0;
   int _readIndex2 = 11025;
   int _writeIndex = _delayTime;
   float _feedback = 0.5f;
// Constructor
 CW1(){
    declareInlets(new int[]{SIGNAL,SIGNAL,SIGNAL,SIGNAL,SIGNAL,SIGNAL});
    declareOutlets(new int[]{SIGNAL,SIGNAL});
    setInletAssist(new String[] { "Signal1",
            "Signal2", "Left Delay", "Left Feedback", "Right Delay", "Right Feedback" });
    setOutletAssist(new String[] { "Left",
            "Right"});
}
// Audio processing method
public void perform(MSPSignal[] ins, MSPSignal[] outs){
    float[] in1 = ins[0].vec; // Assign the array to a local method variable array
    float[] in2 = ins[1].vec;
    float[] in3 = ins[2].vec;
    float[] in4 = ins[3].vec;
    float[] in5 = ins[4].vec;
    float[] in6 = ins[5].vec;
    float[] out1 = outs[0].vec;// Do the same with the output array
    float[] out2 = outs[1].vec;
/*Scanner myData = new Scanner(System.in)
double x = myData.nextDouble();*/
    for(int i = 0; i < in1.length; i++) // Loops through each sample
    {
        // Read the sample out of the buffer
        float temp = _circBuffer[_readIndex1++];
        // Write the input sample into the buffer along with the sample we've just read out.
        // Note we are only feeding back only one delay tap here
        _circBuffer[_writeIndex++] = in1[i] + (temp * _feedback);
        // Copy the delayed samples to the output buffer
        out1[i] = temp + _circBuffer[_readIndex2++];
        // Reset the array index values when the end of the buffer is reached (IMPORTANT)
        if(_readIndex1 > _delayTime)
            _readIndex1 = 0;
        if(_readIndex2 > _delayTime)
            _readIndex2 = 0;
        if(_writeIndex > _delayTime)
            _writeIndex = 0;
    }
}
}

0 个答案:

没有答案