java MSPBuffer.pok question
Peiman
Jun 19 2015 | 9:42 am
I'm working on a little java external to merge all the channels of an 8-channel file into one. It's all working, except that the content of the resulting buffer is twice the speed (and half the duration) or the original. I cannot figure out why since I'm just using a straight copy with MSPBuffer.pok and MSPBuffer.peek...
I'd really appreciate it if a java guru could take a look at the code below and tell me where I'm going wrong. I only started learning java two days ago so I'm a little clueless!
Many Thanks
Peiman
////////////////////////////////
import com.cycling74.max.*;
import com.cycling74.msp.*;
public class buftest extends MaxObject{
String bufname = null;
String destination = null;
buftest(Atom[] a) {
declareAttribute("destination");
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});
createInfoOutlet(false);
if (a.length>0)
bufname = a[0].toString();
destination = a[1].toString();
}
public void normalize() {
float[] samps = MSPBuffer.peek(destination, 0);
double max = Double.MIN_VALUE;
for (int i=0;i
if (Math.abs(samps[i]) > max)
max = Math.abs(samps[i]);
double scale = ((double)Math.abs(1))/max;
for (int i=0;i
samps[i] *= scale;
MSPBuffer.poke(destination, 0, samps);
}
public void merge() {
float[] arrayA = MSPBuffer.peek(bufname, 0);
float[] arrayB = MSPBuffer.peek(bufname, 1);
float[] arrayC = MSPBuffer.peek(bufname, 2);
float[] arrayD = MSPBuffer.peek(bufname, 3);
float[] arrayE = MSPBuffer.peek(bufname, 4);
float[] arrayF = MSPBuffer.peek(bufname, 5);
float[] arrayG = MSPBuffer.peek(bufname, 6);
float[] arrayH = MSPBuffer.peek(bufname, 7);
float[] arraySum = new float[arrayA.length];
for (int i = 0; i < arrayA.length; ++i){
arraySum[i] = arrayA[i] + arrayB[i] + arrayC[i] + arrayD[i] + arrayE[i] + arrayF[i] + arrayG[i] + arrayH[i];
}
MSPBuffer.poke(destination, arraySum);
normalize();
}
}