trigger event from soundfile

Jul 18, 2007 at 9:55pm

trigger event from soundfile

Hello,

Very new to Max/Msp and I’m sure this is easy but…
I am playing a sound file using sfplay and want to trigger events when the file reached various points as it plays. What if the best way to to do this?

e.g. file reaches 1.54 seconds, button 1 is automatically pressed, files reaches 2.73 secs button 2 is pressed.

many thanks,
Matt

#32946
Jul 19, 2007 at 12:03am

At 10:55 PM +0100 7/18/07, cloughy wrote:
>Hello,
>
>Very new to Max/Msp and I’m sure this is easy but…
>I am playing a sound file using sfplay and want to trigger events when the file reached various points as it plays. What if the best way to to do this?

Look in the help patcher for sfplay~, particularly in the “new features” section for info on how to find out the current position.

The sfinfo~ object reports the length of the file (among other things) so you could calculate percent of file played based on the ratio of position to length

-C.


Chris Muir | “There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,
http://www.xfade.com | and radicals always argue.” – Brian Eno

#109146
Jul 20, 2007 at 1:54am

You could also start a count~ object when you start playing, or for that matter a timer too, then select a specific number. Maybe better, do a comparison: so “when time > 2.73 sec” then trigger. Sometimes specific numbers get skipped when they’re changing fast (i.e. the scheduler can’t update the numbers to keep up with the signal~).

–CJ

#109147
Nov 18, 2007 at 9:43pm

#109148
Nov 18, 2007 at 10:41pm

You can try using a delay (or pipe) of the first sfplay~ trigger?

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 84 356 45 9109513 seek $1;
#P newex 84 298 50 9109513 pipe 1000;
#P button 196 26 15 0;
#P user meter~ 238 144 251 370 50 68 0 150 0 0 0 191 202 255 255 255 255 163 141 255 89 0 248 12 3 3 3 3;
#P user gain~ 220 144 14 204 158 1 1.071519 7.94321 500.;
#P user meter~ 202 144 215 370 50 68 0 150 0 0 0 191 202 255 255 255 255 163 141 255 89 0 248 12 3 3 3 3;
#P user gain~ 184 144 14 204 158 1 1.071519 7.94321 500.;
#P flonum 196 49 58 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 30 459 27 9109513 stop;
#P message 15 441 65 9109513 startwindow;
#P newex 123 441 39 9109513 *~ 0.5;
#P newex 83 441 39 9109513 *~ 0.5;
#P newex 184 500 32 9109513 dac~;
#P message 21 374 30 9109513 open;
#N sfplay~ 2 100000 2 ;
#P newobj 83 399 101 9109513 sfplay~ 2 100000 2;
#P message 133 82 30 9109513 open;
#P message 196 81 45 9109513 seek $1;
#N sfplay~ 2 100000 1 ;
#P newobj 195 104 88 9109513 sfplay~ 2 100000 1;
#P fasten 10 0 16 0 201 74 89 74;
#P connect 10 0 1 0;
#P connect 13 0 5 1;
#P hidden connect 13 0 14 0;
#P connect 11 0 5 0;
#P hidden connect 11 0 12 0;
#P connect 16 0 17 0;
#P connect 17 0 3 0;
#P connect 15 0 10 0;
#P hidden connect 0 0 11 0;
#P connect 2 0 0 0;
#P connect 1 0 0 0;
#P hidden connect 0 1 13 0;
#P hidden connect 11 1 13 0;
#P fasten 7 0 5 1 128 465 211 465;
#P connect 6 0 5 0;
#P fasten 8 0 5 0 20 478 189 478;
#P fasten 9 0 5 0 35 478 189 478;
#P connect 3 1 7 0;
#P connect 3 0 6 0;
#P connect 4 0 3 0;
#P window clipboard copycount 18;

#109149
Nov 18, 2007 at 11:02pm

Fletcher the main problem with your system is that the number~ object is set to report values at 250ms intervals that means the play time coming out of it might look something like this; press play, 0,250,500,750etc. But because of the way snapshot works (it put out values regularly at a set frequency) it’s output could also look like this;press play, 111, 361, 611 etc

Your >= and < = objects are loking for a number between 1000 and 1100 (a range of 100) and your play position is only changing every 250ms certain cues may get skipped. Make sense?

Number~ can be made to report much faster like 25ms which will improve cue accuracy and i’d suggest using >= as a better option than >= and < =

I had a little play about with your patch and came up with a couple of options for you including a sample accurate one.

Best,

John.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P comment 511 284 48 196617 next cue;
#P comment 248 452 156 196617 http://www.leafcutterjohn.com;
#P button 720 413 15 0;
#P comment 639 180 137 196617 add a cue – index , time (ms);
#P message 676 195 49 196617 6 16000;
#P window linecount 3;
#P comment 349 39 227 196617 Method two , is sample accurate – the cues live in the coll object. After a cue is triggered the next one is called from the coll by the counter;
#P button 704 413 15 0;
#P button 688 413 15 0;
#P button 672 413 15 0;
#P button 656 413 15 0;
#P button 640 413 15 0;
#P button 624 413 15 0;
#P window linecount 1;
#P newex 624 354 27 196617 i;
#P newex 624 387 127 196617 sel 0 1 2 3 4 5 6;
#P number 418 403 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 505 267 72 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 597 178 14 196617 0;
#P newex 597 153 32 196617 sel 1;
#N counter 0 1 1000;
#X flags 0 0;
#P newobj 418 357 89 196617 counter 0 1 1000;
#P toggle 421 79 15 0;
#P button 418 319 15 0;
#P newex 418 297 36 196617 edge~;
#P newex 418 268 54 196617 >=~ 1000;
#N coll ;
#T flags 1 0;
#T 0 2000;
#T 1 3000;
#T 2 4500.5;
#T 3 10000.;
#T 4 15000;
#T 5 15050;
#P newobj 505 228 53 196617 coll;
#P user ezdac~ 348 276 392 309 0;
#P message 314 147 30 196617 open;
#N sfplay~ 2 100000 2 ;
#P newobj 348 173 101 196617 sfplay~ 2 100000 2;
#P newex 232 337 32 196617 sel 1;
#P button 232 363 15 0;
#P newex 232 310 40 196617 change;
#P toggle 232 285 15 0;
#P newex 232 259 54 196617 >= 10000;
#P newex 178 337 32 196617 sel 1;
#P button 178 363 15 0;
#P newex 178 310 40 196617 change;
#P toggle 178 285 15 0;
#P newex 178 259 48 196617 >= 2555;
#P newex 124 337 32 196617 sel 1;
#P button 124 363 15 0;
#P newex 124 310 40 196617 change;
#P toggle 124 285 15 0;
#P newex 124 259 48 196617 >= 1000;
#P user ezdac~ 47 272 91 305 0;
#P newex 124 220 70 196617 snapshot~ 50;
#P window linecount 3;
#P comment 1118 236 119 196617 the greater the gap the better the odds – but not accurate enough;
#P button 47 88 15 0;
#P flonum 47 111 58 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 13 143 30 196617 open;
#P message 47 143 45 196617 seek $1;
#N sfplay~ 2 100000 2 ;
#P newobj 47 169 101 196617 sfplay~ 2 100000 2;
#P window linecount 4;
#P comment 9 32 128 196617 Method one , Not sample accurate – the accuracy depends on the resolution of the snapshot object.;
#P connect 5 0 4 0;
#P connect 4 0 2 0;
#P connect 2 0 1 0;
#P fasten 3 0 1 0 18 163 52 163;
#P connect 1 0 8 0;
#P fasten 1 1 8 1 74 229 86 229;
#P fasten 1 2 7 0 96 204 129 204;
#P connect 7 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P connect 11 0 13 0;
#P connect 13 0 12 0;
#P fasten 7 0 14 0 129 241 183 241;
#P connect 14 0 15 0;
#P connect 15 0 16 0;
#P connect 16 0 18 0;
#P connect 18 0 17 0;
#P fasten 7 0 19 0 129 247 237 247;
#P connect 19 0 20 0;
#P connect 20 0 21 0;
#P connect 21 0 23 0;
#P connect 23 0 22 0;
#P fasten 31 0 24 0 426 144 353 144;
#P fasten 25 0 24 0 319 167 353 167;
#P connect 24 0 26 0;
#P fasten 24 1 26 1 375 233 387 233;
#P fasten 24 2 28 0 397 229 423 229;
#P connect 28 0 29 0;
#P connect 29 0 30 0;
#P connect 30 0 32 0;
#P connect 32 0 36 0;
#P fasten 27 0 28 1 510 256 467 256;
#P fasten 34 0 32 3 602 332 480 332;
#P fasten 32 0 27 0 423 389 580 389 580 224 510 224;
#P fasten 46 0 27 0 681 216 510 216;
#P connect 27 0 35 0;
#P fasten 31 0 33 0 426 112 602 112;
#P connect 33 0 34 0;
#P fasten 30 0 38 0 423 342 629 342;
#P connect 38 0 37 0;
#P connect 37 0 39 0;
#P connect 37 1 40 0;
#P fasten 27 1 38 1 524 255 646 255;
#P connect 37 2 41 0;
#P connect 37 3 42 0;
#P connect 37 4 43 0;
#P connect 37 5 44 0;
#P connect 37 6 48 0;
#P window clipboard copycount 51;

#109150
Nov 18, 2007 at 11:44pm

I do not want to sound to “flowery” as someone once told me my resume was, but I am honored by your reply Leafcutter John. I now understand, thank you for that. Thank you for giving to this community. Thank you for helping me get past that hurdle.
Sincerely,
Chad Fletcher

#109151
Dec 1, 2007 at 6:23pm

I found John’s solution inspiring to change a patch I use often. In this patch I translate the cycle of a phasor~ to 8th parts from which I can sync non audio objects. It works good for finding all milisecs but the zero. I can solve this by entering a number slightly higher (0.0001) but taht;s a bit off beat…

Maybe one knows how to find the zero?

max v2;
#N vpatcher 1211 253 1415 486;
#P window setfont “Sans Serif” 9.;
#P number 38 177 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 80 102 55 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 38 126 36 196617 edge~;
#N counter 0 0 7;
#X flags 0 0;
#P newobj 38 149 71 196617 counter 0 0 7;
#P newex 38 102 39 196617 >=~ 0.;
#N coll ;
#T flags 1 0;
#T 0 0.0001;
#T 1 0.125;
#T 2 0.25;
#T 3 0.375;
#T 4 0.5;
#T 5 0.625;
#T 6 0.75;
#T 7 0.875;
#P newobj 67 76 53 196617 coll;
#P newex 38 49 70 196617 phasor~ 0.92;
#P connect 0 0 2 0;
#P connect 2 0 4 0;
#P connect 4 0 3 0;
#P connect 3 0 6 0;
#P fasten 3 0 1 0 43 171 140 171 140 71 72 71;
#P connect 1 0 2 1;
#P connect 1 0 5 0;
#P pop;

Thanks for reading!

#109152
Dec 2, 2007 at 8:15pm

Frans-Jan Wind schrieb:
> I found John’s solution inspiring to change a patch I use often. In
> this patch I translate the cycle of a phasor~ to 8th parts from which
> I can sync non audio objects. It works good for finding all milisecs
> but the zero. I can solve this by entering a number slightly higher
> (0.0001) but taht;s a bit off beat…
>
> Maybe one knows how to find the zero?

It won’t find a zero if there is no zero. The zero most likely is
between two samples. And how much off beat is 0.0001? Get out your
calculator, I bet its less than a scheduler tick…

Stefan


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

#109153
Dec 3, 2007 at 4:36pm

You’re right, I can’t hear it. I guess it’s between the ears then!

#109154

You must be logged in to reply to this topic.