Forums > MaxMSP

bonk~ & storing a drum beat

March 26, 2008 | 7:15 pm

Hi list,

I’m trying to use bonk~ so that a user can set sounds (percussive), and then clap a rythmn using these sounds at a specific tempo. The idea is that bonk~ will detect the sounds, and which specific sound, and I can then store this information so that I can play back the rythmn.

I have something roughly working, but I’m finding the actual method to store the rythmn a bit elusive. The idea is that only 16 beats will be used, so if the rythm is longer it will simply loop back to the start and overwrite the previous data. What I have so far seems a bit clunky, and suffers from ‘stuck notes’. Any suggestions on how I could achieve my ideas, or improve how I’m currently doing it would be much appreciated,

Thanks,

Mike

max v2;
#N vpatcher 93 98 888 734;
#P origin 0 85;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 258 374 30 196617 t b b;
#P message 278 396 14 196617 1;
#P message 258 396 14 196617 0;
#P newex 206 353 67 196617 unpack 0 0 0;
#P newex 212 423 57 196617 pack 0 0 0;
#P newex 26 367 40 196617 t i i i;
#P number 47 314 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 29 315 15 0;
#P newex 26 344 53 196617 tempo;
#P message 92 471 33 196617 clear;
#P newex 304 373 32 196617 print;
#N counter 0 0 15;
#X flags 0 0;
#P newobj 36 283 77 196617 counter 0 0 15;
#P message 212 446 52 196617 $1 $2 $3;
#P user matrixctrl 212 489 258 50 MatrixDefaultCell.pct MatrixDefaultBkgnd.pct 258 50 16 16 16 3 16 16 1 1 48 2 5120 0;
#P message 310 228 30 196617 read;
#P toggle 227 0 15 0;
#P button 227 273 15 0;
#P newex 178 22 29 196617 adc~;
#B color 5;
#P message 227 249 30 196617 print;
#P message 227 228 77 196617 read templates;
#P message 227 210 33 196617 write;
#P message 227 183 64 196617 forget;
#P message 227 164 64 196617 learn 0;
#P message 227 144 64 196617 learn 10;
#P message 227 125 64 196617 learn 1;
#P message 227 106 64 196617 debounce 0.;
#P message 227 67 65 196617 mask 4 0.7;
#P message 227 48 65 196617 minvel 10;
#P message 227 22 65 196617 thresh 6 50;
#P newex 206 324 34 196617 bonk~;
#B color 5;
#P window linecount 2;
#P comment 296 22 321 196617 • Set low and high thresholds. Signal growth must exceed the high one and then fall to the low one to make an attack.;
#P window linecount 1;
#P comment 296 48 276 196617 • Minimum velocity to output (quieter notes are ignored.);
#P window linecount 3;
#P comment 296 67 324 196617 • Describes how energyin each frequency band masks later energy in the band. Here the masking is total for 4 analysis periods and then drops by 0.7 each period.;
#P window linecount 1;
#P comment 296 106 278 196617 • Minimum time (msec) between attacks;
#P window linecount 3;
#P comment 296 125 333 196617 • Forget all templates and start learning new ones. The argument gives the number of times you will hit each instrument (10 recommended.) Turn on the output volume above for audible feedback as you train Bonk.;
#P window linecount 1;
#P comment 296 164 162 196617 • "Learn 0" exits learn mode.;
#P window linecount 2;
#P comment 296 183 325 196617 • Forget the last template. In Learn mode , use "forget" to erase and record over a template.;
#P window linecount 1;
#P comment 263 210 271 196617 • Write templates to a file in text-editable format.;
#P comment 346 229 151 196617 • Read templates from a file.;
#P comment 263 249 185 196617 • Print out all settings and templates.;
#P window linecount 4;
#P comment 263 273 183 196617 • Poll the current spectrum via "raw" outlet , You can set a very high threshold if you don’t want attacks mixed in.;
#P window linecount 1;
#P comment 246 0 127 196617 • click here to start DSP.;
#P connect 34 0 33 0;
#P connect 33 0 36 0;
#P connect 35 0 33 1;
#P fasten 26 0 24 0 232 18 183 18;
#P fasten 27 0 12 0 315 246 211 246;
#P fasten 23 0 12 0 232 269 211 269;
#P fasten 22 0 12 0 232 246 211 246;
#P fasten 21 0 12 0 232 226 211 226;
#P fasten 20 0 12 0 232 200 211 200;
#P fasten 19 0 12 0 232 181 211 181;
#P fasten 24 0 12 0 183 307 211 307;
#P fasten 25 0 12 0 232 296 211 296;
#P fasten 18 0 12 0 232 161 211 161;
#P fasten 17 0 12 0 232 142 211 142;
#P fasten 16 0 12 0 232 123 211 123;
#P fasten 15 0 12 0 232 86 211 86;
#P fasten 14 0 12 0 232 64 211 64;
#P fasten 13 0 12 0 232 40 211 40;
#P fasten 12 1 38 0 235 347 211 347;
#P fasten 36 0 37 0 31 403 217 403;
#P connect 37 0 29 0;
#P connect 32 0 28 0;
#P connect 29 0 28 0;
#P fasten 38 0 37 1 211 387 240 387;
#P connect 38 0 41 0;
#P connect 39 0 37 2;
#P fasten 40 0 37 2 283 417 263 417;
#P connect 41 1 40 0;
#P fasten 38 0 31 0 211 370 309 370;
#P pop;


March 28, 2008 | 8:47 pm

For anyone looking here’s the solution I came up with. I think it’s a bit brute forceish, but it does the trick.

Any improvements/ideas feel free to comment,

Mike

max v2;
#N vpatcher 99 67 894 703;
#P origin 0 64;
#P window setfont "Sans Serif" 9.;
#P comment 611 336 38 196617 BPM;
#P comment 356 437 39 196617 note on;
#P button 230 372 15 0;
#P message 395 460 39 196617 set $1;
#P newex 212 482 40 196617 append;
#P message 427 435 14 196617 0;
#P newex 211 512 29 196617 gate;
#P message 574 439 106 196617 $1 0 0 $1 1 0 $1 2 0;
#P message 395 435 14 196617 1;
#P newex 206 391 67 196617 unpack 0 0 0;
#P newex 212 459 43 196617 pak 0 0;
#P newex 559 397 57 196617 t i i i i;
#P number 577 336 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 559 337 15 0;
#P newex 559 374 64 196617 tempo;
#P message 82 516 33 196617 clear;
#P user matrixctrl 211 562 274 50 MatrixDefaultCell.pct MatrixDefaultBkgnd.pct 274 50 16 16 17 3 16 16 1 1 48 2 5120 0;
#P message 310 249 30 196617 read;
#P toggle 227 21 15 0;
#P button 227 294 15 0;
#P newex 178 43 29 196617 adc~;
#B color 5;
#P message 227 270 30 196617 print;
#P message 227 249 77 196617 read templates;
#P message 227 231 33 196617 write;
#P message 227 204 64 196617 forget;
#P message 227 185 64 196617 learn 0;
#P message 227 165 64 196617 learn 10;
#P message 227 146 64 196617 learn 1;
#P message 227 127 64 196617 debounce 0.;
#P message 227 88 65 196617 mask 4 0.7;
#P message 227 69 65 196617 minvel 10;
#P message 227 43 65 196617 thresh 6 50;
#P newex 206 345 34 196617 bonk~;
#B color 5;
#P window linecount 2;
#P comment 296 43 321 196617 • Set low and high thresholds. Signal growth must exceed the high one and then fall to the low one to make an attack.;
#P window linecount 1;
#P comment 296 69 276 196617 • Minimum velocity to output (quieter notes are ignored.);
#P window linecount 3;
#P comment 296 88 324 196617 • Describes how energyin each frequency band masks later energy in the band. Here the masking is total for 4 analysis periods and then drops by 0.7 each period.;
#P window linecount 1;
#P comment 296 127 278 196617 • Minimum time (msec) between attacks;
#P window linecount 3;
#P comment 296 146 333 196617 • Forget all templates and start learning new ones. The argument gives the number of times you will hit each instrument (10 recommended.) Turn on the output volume above for audible feedback as you train Bonk.;
#P window linecount 1;
#P comment 296 185 162 196617 • "Learn 0" exits learn mode.;
#P window linecount 2;
#P comment 296 204 325 196617 • Forget the last template. In Learn mode , use "forget" to erase and record over a template.;
#P window linecount 1;
#P comment 263 231 271 196617 • Write templates to a file in text-editable format.;
#P comment 346 250 151 196617 • Read templates from a file.;
#P comment 263 270 185 196617 • Print out all settings and templates.;
#P window linecount 4;
#P comment 263 294 183 196617 • Poll the current spectrum via "raw" outlet , You can set a very high threshold if you don’t want attacks mixed in.;
#P window linecount 1;
#P comment 246 21 127 196617 • click here to start DSP.;
#P user multiSlider 211 548 274 64 0. 15. 1 2936 15 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 comment 440 436 100 196617 Prevent stuck notes;
#P window linecount 2;
#P comment 252 480 100 196617 Add the on/off to the cell coordinate;
#P window linecount 1;
#P comment 240 514 228 196617 Stop messages getting through if set off at tempo;
#P comment 579 454 123 196617 Clear the current column;
#P comment 519 338 38 196617 On/off;
#P fasten 32 0 30 0 232 39 183 39;
#P fasten 33 0 18 0 315 267 211 267;
#P fasten 29 0 18 0 232 290 211 290;
#P fasten 28 0 18 0 232 267 211 267;
#P fasten 27 0 18 0 232 247 211 247;
#P fasten 26 0 18 0 232 221 211 221;
#P fasten 25 0 18 0 232 202 211 202;
#P fasten 30 0 18 0 183 328 211 328;
#P fasten 31 0 18 0 232 317 211 317;
#P fasten 24 0 18 0 232 182 211 182;
#P fasten 23 0 18 0 232 163 211 163;
#P fasten 22 0 18 0 232 144 211 144;
#P fasten 21 0 18 0 232 107 211 107;
#P fasten 20 0 18 0 232 85 211 85;
#P fasten 19 0 18 0 232 61 211 61;
#P fasten 18 1 41 0 235 368 211 368;
#P fasten 37 0 44 0 564 368 138 368 138 508 216 508;
#P fasten 39 3 5 0 609 432 701 432 701 541 216 541;
#P fasten 35 0 34 0 87 534 216 534;
#P connect 44 0 34 0;
#P fasten 43 0 34 0 579 532 216 532;
#P fasten 39 0 40 0 564 422 217 422;
#P connect 40 0 46 0;
#P fasten 47 0 46 0 400 478 217 478;
#P connect 18 1 48 0;
#P fasten 46 0 44 1 217 505 235 505;
#P fasten 41 0 40 1 211 433 250 433;
#P fasten 41 0 42 0 211 416 400 416;
#P connect 42 0 47 0;
#P fasten 45 0 47 0 432 455 400 455;
#P fasten 39 2 45 0 594 429 432 429;
#P connect 37 0 36 0;
#P connect 36 0 39 0;
#P connect 39 1 43 0;
#P connect 38 0 36 1;
#P pop;


May 7, 2008 | 9:55 am

Hi, this patch looks interesting, thanks for posting. Could you give a couple of clues as to how to get it to do its stuff (a ‘hello work’-style basic test)?

I tinkered around a bit, using my laptop’s built-in mic as a sound source, but couldn’t get the bonk~ object to fire yet. Probably overlooking something simple.


March 20, 2014 | 7:37 am

Hi,

I’m interested to see your patch but it’s in 4.5.
any chance you could re-up it in the new text format?

I’m quite struggling with using bonk to detect a sound.

cheers!


March 20, 2014 | 8:35 pm

just copy and paste it from the forum — Max 6 will know what to do with it.

\M


March 21, 2014 | 3:43 am

oups yes for some reason it didn’t work, got it working now


Viewing 6 posts - 1 through 6 (of 6 total)