buffer help

Feb 15, 2008 at 12:12am

buffer help

i am sure my problem is a no brainer.im passing a signal into a buffer 256 samples in size i then need to add the contents of the current sample frame to the contents of the previous sample frame. how would i go about this. any help would be appreciated. ben

#35825
Feb 15, 2008 at 2:15am

perhaps use two index~ objects…
have a counter go from 0-255 and use it as the index for one of them, and add 1 to that number and use it as the index for the other one
add the results, and send them to a record~ object

#122604
Feb 15, 2008 at 9:30pm

im not sure if i’ve explained myself properly. i want to add all 256 values in the buffer to the previous 256 values. the first sample in the current frame to the first value in the previous frame, the second sample in the current frame to the second value in the previous frame. and so on.

#122605
Feb 16, 2008 at 11:52pm

any help with my issue would be appreciated, its part of my final year project and carrying out this process is essential.

#122606
Feb 17, 2008 at 12:17am

I’ve never tried this specifically, but off the top of my head…

it seems like you can record into 2 separate 256 sample buffers, then use [peek~] to get the index values out, [+~] to add the values together, and [poke~] to write the result into a new buffer.

hope that helps,
/dan

Quote: jamin wrote on Fri, 15 February 2008 14:30
—————————————————-
> im not sure if i’ve explained myself properly. i want to add all 256 values in the buffer to the previous 256 values. the first sample in the current frame to the first value in the previous frame, the second sample in the current frame to the second value in the previous frame. and so on.
—————————————————-

#122607
Feb 17, 2008 at 1:40am

[poke~] will be so slow. why not do it in java with the [mxj
buf.Op]? add the following to the buf/Op.java file and recompile.

public void mix(final String frombuf) {
MaxSystem.deferLow(new Executable() {
public void execute() {
int channels= MSPBuffer.getChannels(bufname);
for(int i= 1; i< =channels; i++) {
float[] sampsFrom= MSPBuffer.peek(frombuf, i);
float[] sampsTo= MSPBuffer.peek(bufname, i);
for(int j= 0; j
sampsTo[j]= sampsTo[j]+sampsFrom[j];
}
MSPBuffer.poke(bufname, i, sampsTo);
}
outlet(0, “done”);
}
});
}

mix one buffer with another (assumes equal length and channels).
note – very quick hack, not thoroughly tested and there’s no clipping
or scaling. but you’ll see the principle and it’s easy to add a
*0.707 or something to scale the amp down a little.

max v2;
#N vpatcher 381 95 1165 419;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P comment 165 64 157 196617 keep same num channels and size;
#P newex 492 26 48 196617 loadbang;
#P newex 189 190 30 196617 t b b;
#P button 189 173 15 0;
#P comment 167 157 120 196617 refresh views after mix;
#P newex 462 79 40 196617 t b b b;
#P button 462 62 15 0;
#P newex 667 105 27 196617 t i i;
#P newex 667 124 91 196617 expr sin($i1/20.);
#P newex 667 148 54 196617 poke~ bar;
#P newex 574 105 27 196617 t i i;
#P newex 574 124 92 196617 scale 0 999 -1. 1.;
#P newex 626 73 27 196617 – 1;
#P newex 586 54 50 196617 uzi 1000;
#P comment 459 46 23 196617 init;
#P message 40 88 44 196617 mix foo;
#P message 500 149 40 196617 wclose;
#P message 462 149 30 196617 open;
#P newex 538 238 77 196617 buffer~ bar 20;
#P newex 538 213 76 196617 buffer~ foo 20;
#P newex 574 148 53 196617 poke~ foo;
#P newex 91 269 62 196617 print buf.Op;
#P newex 91 246 77 196617 mxj buf.Op bar;
#P message 91 217 61 196617 viewsource;
#P connect 8 0 1 0;
#P connect 0 0 1 0;
#P connect 1 0 2 0;
#P connect 20 0 21 0;
#P connect 22 0 17 0;
#P connect 17 0 18 0;
#P connect 21 0 6 0;
#P connect 18 0 6 0;
#P connect 21 1 7 0;
#P connect 18 1 7 0;
#P connect 7 0 4 0;
#P connect 6 0 4 0;
#P connect 7 0 5 0;
#P connect 6 0 5 0;
#P connect 11 0 13 0;
#P connect 13 0 12 0;
#P connect 12 0 3 0;
#P connect 18 2 10 0;
#P connect 13 1 3 1;
#P connect 10 2 11 0;
#P connect 11 0 16 0;
#P connect 16 0 15 0;
#P connect 15 0 14 0;
#P connect 16 1 14 1;
#P pop;

Am 17.02.2008 um 01:17 schrieb Dan:

>
> I’ve never tried this specifically, but off the top of my head…
>
> it seems like you can record into 2 separate 256 sample buffers,
> then use [peek~] to get the index values out, [+~] to add the
> values together, and [poke~] to write the result into a new buffer.
>
> hope that helps,
> /dan
>
>
> Quote: jamin wrote on Fri, 15 February 2008 14:30
> —————————————————-
>> im not sure if i’ve explained myself properly. i want to add all
>> 256 values in the buffer to the previous 256 values. the first
>> sample in the current frame to the first value in the previous
>> frame, the second sample in the current frame to the second value
>> in the previous frame. and so on.
> —————————————————-
>
>
>

#|
fredrikolofsson.com klippav.org musicalfieldsforever.com
|#

#122608
Feb 17, 2008 at 2:10pm

thanks for your thoughts, java in max/msp isn’t something i’ve really explored. i suppose this is as good a reason as any to start. should it be possible to modify the code such that im constantly receiving present buffer values summing these to the old values and replacing with the new result.thanks once again ben

#122609
Feb 17, 2008 at 8:41pm

to me it isn’t clear what you want to do with the data. show an
example patch. by ‘constantly’ you mean streaming audio? so you
want it to run in audiorate like some effect? then it sounds like
you’re just after a simple 256samples long delay~ with feedback.
the mix method for mxj buf.Op i posted is not well suited for driving
with an audio sync.
_f

Am 17.02.2008 um 14:10 schrieb ben Gilman:

>
> thanks for your thoughts, java in max/msp isn’t something i’ve
> really explored. i suppose this is as good a reason as any to
> start. should it be possible to modify the code such that im
> constantly receiving present buffer values summing these to the old
> values and replacing with the new result.thanks once again ben

#|
fredrikolofsson.com klippav.org musicalfieldsforever.com
|#

#122610
Feb 20, 2008 at 6:41pm

thanks for your help it was just a case of a 256 sample delay with feedback. thanks once again ben

#122611

You must be logged in to reply to this topic.