rotate buffer

Feb 22, 2007 at 9:49pm

rotate buffer

dear all, please can someone give some helps on it..

max v2;
#N vpatcher 14 49 638 481;
#P origin -48 0;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 168 356 44 196617 pack f f;
#P message 365 217 17 196617 0.;
#P newex 284 287 31 196617 * -1;
#P newex 286 324 88 196617 scale -1. 1. -1 1.;
#P newex 284 263 27 196617 / 2.;
#P newex 168 333 27 196617 +;
#P user multiSlider 385 217 200 14 -1. 1. 1 2680 47 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P newex 125 88 30 196617 t b b;
#P message 269 102 43 196617 size $1;
#P message 385 117 41 196617 set b 1;
#P user waveform~ 385 138 200 74 3 9;
#W mode select;
#W mouseoutput continuous;
#W unit ms;
#W grid 1000.;
#W ticks 0;
#W labels 1;
#W vlabels 0;
#W vticks 1;
#W bpm 120. 4.;
#W frgb 33 0 0;
#W brgb 60 178 173;
#W rgb2 0 95 255;
#W rgb3 0 0 0;
#W rgb4 0 0 0;
#W rgb5 190 137 255;
#W rgb6 100 100 100;
#W rgb7 100 100 100;
#P newex 269 122 52 196617 buffer~ b;
#P newex 168 381 44 196617 peek~ b;
#P newex 242 262 29 196617 t b f;
#P newex 186 238 66 196617 mstosamps~;
#P newex 168 292 27 196617 t i i;
#P newex 168 263 27 196617 – 1;
#P newex 223 330 44 196617 peek~ a;
#P button 138 203 15 0;
#P newex 138 240 40 196617 uzi;
#P number 168 178 76 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 203 148 66 196617 mstosamps~;
#P newex 125 123 105 196617 info~ a;
#P message 83 37 43 196617 replace;
#P newex 83 65 52 196617 buffer~ a;
#P comment 450 234 74 196617 < ---scroll--->;
#P window linecount 3;
#P comment 5 332 158 196617 here i’m stuck..can’t find a way to wrap the indexes when < 0 and > total sample length..;
#P connect 3 0 2 0;
#P connect 2 1 19 0;
#P fasten 19 1 4 0 150 114 130 114;
#P fasten 13 0 8 0 247 284 129 284 129 198 143 198;
#P fasten 19 0 8 0 130 119 143 119;
#P connect 8 0 7 0;
#P fasten 5 1 6 0 264 169 173 169;
#P connect 6 0 7 1;
#P connect 7 2 10 0;
#P connect 10 0 11 0;
#P connect 11 0 21 0;
#P connect 21 0 26 0;
#P connect 26 0 14 0;
#P connect 13 1 21 1;
#P fasten 23 0 12 0 291 346 279 346 279 224 191 224;
#P connect 9 0 26 1;
#P connect 4 6 5 0;
#P connect 11 1 9 0;
#P connect 12 1 13 0;
#P fasten 4 6 18 0 208 145 251 145 251 97 274 97;
#P connect 18 0 15 0;
#P fasten 4 6 22 0 208 145 289 145;
#P connect 22 0 24 0;
#P fasten 20 0 23 0 390 303 368 303 368 321 291 321;
#P fasten 24 0 23 3 289 308 336 308;
#P fasten 22 0 23 4 289 283 351 283;
#P fasten 19 1 17 0 150 107 227 107 227 70 390 70;
#P connect 17 0 16 0;
#P connect 25 0 20 0;
#P pop;

#30418
Feb 23, 2007 at 9:01am

#97249
Feb 23, 2007 at 10:42am

mic wrote:
> dear all, please can someone give some helps on it..

%.help

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#97250
Feb 23, 2007 at 12:33pm

#97251
Feb 23, 2007 at 12:56pm

Falk Grieffenhagen wrote:
> mxj is faster then peeking via uzi.

For sure? This would make a big difference to me. What magnitude of
improvement are we talking about?

Thanks for any info…

-Jon

#97252
Feb 23, 2007 at 1:18pm

#97253
Feb 23, 2007 at 3:26pm

it seems make some mistake: i get this error when trying to compile hacked buf.op

/Library/Application Support/Cycling ’74/java/classes/buf/Op.java[ 302 ] ‘class’ or ‘interface’ expected
public void copyFrom(String frombuf, long destoffset) {

#97254
Feb 23, 2007 at 3:27pm

1 error
[ 23-feb-2007 16.35.13 ]
compilation of /Library/Application Support/Cycling ’74/java/classes/buf/Op.java failed.

#97255
Feb 23, 2007 at 3:31pm

anyway using only peek~ and % doesn’t work properly since buffer is ruined when scrolled..tryin to play it sounds very bad with many clicks and hiccups

#97256
Feb 23, 2007 at 4:12pm

strange…

here is the altered source which works here in case something went
wrong updating the source code:

Falk

package buf;
import com.cycling74.max.*;
import com.cycling74.msp.*;

/**
* a collection of buffer utilities
*
* created on Apr 12, 2004
* @author bbn
*
* TODO support joint operations on more than one channel.
* ie, DC offset
*
*/
public class Op extends MaxObject {

String bufname = null;

Op(Atom[] a) {
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});
createInfoOutlet(false);
if (a.length>0)
set(a[0].toString());
}

public void set(String s) {
bufname = s;
}

public void merge(final Atom[] a) {
MaxSystem.deferLow(new Executable() {
public void execute() {
long maxFrames = 0;
int channelSum = 0;
int[] channels = new int[a.length];
long[] frames = new long[a.length];
String[] name = new String[a.length];
for (int i=0;i
name[i] = a[i].toString();
channels[i] = MSPBuffer.getChannels(name[i]);
channelSum+=channels[i];
frames[i] = MSPBuffer.getFrames(name[i]);
if (frames[i] > maxFrames)
maxFrames = frames[i];
}
MSPBuffer.setFrames(bufname, channelSum, maxFrames);
int count = 1;
for (int i=0;i
for (int j=0;j
float[] data = MSPBuffer.peek(name[i], j+1);
MSPBuffer.poke(bufname, count++, data);
}
}
}
}
);
}

public void split(final Atom[] a) {
MaxSystem.deferLow(new Executable() {
public void execute() {
int channels = MSPBuffer.getChannels(bufname);
if (a.length != channels) {
error(“buf.Op: need ” +channels+ ” buffer name arguments “
+” to split “+bufname);
return;
}
long chanSize = MSPBuffer.getSize(bufname)/channels;
for (int i=0;i
String name = a[i].toString();
MSPBuffer.setSize(name, 1, chanSize);
MSPBuffer.poke(name, MSPBuffer.peek(bufname, i+1));
}
}
}
);
}

public void equals(String thatbuf) {
boolean equal = true;
long size = MSPBuffer.getSize(bufname);
if (size != MSPBuffer.getSize(thatbuf))
equal = false;
else if (MSPBuffer.getChannels(bufname)
!= MSPBuffer.getChannels(thatbuf))
equal = false;
else {
float[] thisData = MSPBuffer.peek(bufname);
float[] thatData = MSPBuffer.peek(thatbuf);
int index = 0;
while ((equal)&&(index < size)) {
if (thisData[index] != thatData[index])
equal = false;
index++;
}
outlet(0, equal);
}
}

public void copyFrom(final String frombuf) {
MaxSystem.deferLow(new Executable() {
public void execute() {
long size = MSPBuffer.getSize(frombuf);
int channels = MSPBuffer.getChannels(frombuf);
MSPBuffer.setSize(bufname, channels, size);
MSPBuffer.poke(bufname, MSPBuffer.peek(frombuf));
}
}
);
}

public void copyInto(final String destbuf) {
MaxSystem.deferLow(new Executable() {
public void execute() {
long size = MSPBuffer.getSize(bufname);
int channels = MSPBuffer.getChannels(bufname);
MSPBuffer.setSize(destbuf, channels, size);
MSPBuffer.poke(destbuf, MSPBuffer.peek(bufname));
}
}
);
}

public void dataFrom(String frombuf) {
dataMove(frombuf, bufname);
}
public void dataInto(String tobuf) {
dataMove(bufname, tobuf);
}

private void dataMove(String frombuf, String tobuf)
{
long size = Math.min(MSPBuffer.getSize(frombuf), MSPBuffer.getSize
(tobuf));
int channels = Math.min(MSPBuffer.getChannels(frombuf),
MSPBuffer.getChannels(tobuf));
for (int c=0;c
{
MSPBuffer.poke(tobuf, c, 0, MSPBuffer.peek(frombuf, c, 0, size));
}
}

public void max(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
float max = Float.MIN_VALUE;
int index = 0;
for (int i=0;i
if (samps[i] > max) {
max = samps[i];
index = i;
}
outlet(0, new Atom[] {Atom.newAtom(index), Atom.newAtom(max)});
}

public void min(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
float min = Float.MAX_VALUE;
int index = 0;
for (int i=0;i
if (samps[i] < min) {
min = samps[i];
index = i;
}
outlet(0, new Atom[] {Atom.newAtom(index), Atom.newAtom(min)});
}

public void removeDC(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
double total = 0;
for (int i=0;i
total += samps[i];
}
float shift = (float)(total/(double)samps.length);
for (int i=0;i
samps[i] -= shift;
MSPBuffer.poke(bufname, channel, samps);
}

public void normalize(int channel, float f) {
float[] samps = MSPBuffer.peek(bufname, channel);
double max = Double.MIN_VALUE;
for (int i=0;i
if (Math.abs(samps[i]) > max)
max = samps[i];
double scale = ((double)Math.abs(f))/max;
for (int i=0;i
samps[i] *= scale;
MSPBuffer.poke(bufname, channel, samps);
}

public void multiply(int channel, float f) {
float[] samps = MSPBuffer.peek(bufname, channel);
for (int i=0;i
samps[i] *= f;
MSPBuffer.poke(bufname, channel, samps);
}

public void gain(float f) {
float factor = (float)Math.pow(10.0, f/20.);
int chans = MSPBuffer.getChannels(bufname);
for (int i=1;i< =chans;i++) {
multiply(i, factor);
}
}

public void add(int channel, float f) {
float[] samps = MSPBuffer.peek(bufname, channel);
for (int i=0;i
samps[i] += f;
MSPBuffer.poke(bufname, channel, samps);
}

public void reverse(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
float[] temp = new float[samps.length];
for (int i=0;i
temp[i] = samps[samps.length-i-1];
MSPBuffer.poke(bufname, channel, temp);
}

public void peek(int chan, long index) {
outlet(0, MSPBuffer.peek(bufname, chan, index));
}

public void poke(int chan, long index, float f) {
MSPBuffer.poke(bufname, chan, index, f);
}

public void pokeAll(int chan, float f) {
float[] data = new float[(int)MSPBuffer.getSize(bufname)];
for (int i=0;i
data[i] = f;
}
MSPBuffer.poke(bufname, chan, data);
}

public void sum(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
double total = 0;
for (int i=0;i
total += samps[i];
}
outlet(0, total);
}

public void stddev(int channel) {
outlet(0, Math.sqrt(doVariance(channel)));
}

public void variance(int channel) {
outlet(0, doVariance(channel));
}

private double doVariance(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
double total = 0;
for (int i=0;i
total += samps[i];
}
double mean = total / (double)samps.length;
total = 0;
for (int i=0;i
total += Math.pow(samps[i]-mean,2.);
}
return total/(double)(samps.length – 1);
}

public void average(int channel) {
float[] samps = MSPBuffer.peek(bufname, channel);
double total = 0;
for (int i=0;i
total += samps[i];
}
outlet(0, total/(double)samps.length);
}

public void mean(int channel) {
average(channel);
}

public void getLength() {
outlet(0, MSPBuffer.getLength(bufname));
}

public void setLength(int i, double d) {
MSPBuffer.setLength(bufname, i, d);
}

public void getSize() {
outlet(0, MSPBuffer.getSize(bufname));
}

public void setSize(int channels, long size) {
MSPBuffer.setSize(bufname, channels, size);
}

public void getChannels() {
outlet(0, MSPBuffer.getChannels(bufname));
}
//redFrik 050513, 051128, 060927
public void copyFrom(String frombuf, long destoffset) {
copyFrom(frombuf, destoffset, 0);
}
public void copyFrom(String frombuf, long destoffset, long srcoffset) {
long length= MSPBuffer.getSize(frombuf);
copyFrom(frombuf, destoffset, srcoffset, length-srcoffset);
}
public void copyFrom(final String frombuf, final long destoffset,
final long srcoffset, final long srcsize) {
MaxSystem.deferLow(new Executable() {
public void execute() {
int channels= MSPBuffer.getChannels(frombuf);
for(int i= 1; i< =channels; i++) {
MSPBuffer.poke(bufname, i, destoffset, MSPBuffer.peek(frombuf,
i, srcoffset, srcsize));
}
outlet(0, “done”);
}
});
}
}

Am 23.02.2007 um 16:26 schrieb mic:

>
> it seems make some mistake: i get this error when trying to compile
> hacked buf.op
>
> /Library/Application Support/Cycling ’74/java/classes/buf/Op.java
> [ 302 ] ‘class’ or ‘interface’ expected
> public void copyFrom(String frombuf, long destoffset) {

#97257

You must be logged in to reply to this topic.