I'm curious what is the easiest way to play a sound file or some frequency with given tempo. The easiest metronome you can implement. Any ideas?
Asked
Active
Viewed 373 times
1 Answers
2
If it's simplicity you're looking for then the "easiest metronome" is
~bpm = 120;
x = {Impulse.ar(~bpm/60)}.play;
but it won't sound very pleasant, and it'll only be in the left channel.
For a tone rather than a click, and in both channels, one simple way is
~bpm = 120;
x = {SinOsc.ar.dup * Pulse.ar(~bpm/60, 0.01).lag}.play;
To play back a WAV file, you can simply use a PlayBuf unit and retrigger it at the right tempo. Here we assume you've loaded a sample into a Buffer b
:
x = {PlayBuf.ar(1, b, trigger: Impulse.kr(~bpm/60))}.play;
or alternatively, instead of doing it as a Synth as I did just then, you can put something together using Patterns:
p = Pseq([Pfunc({ b.play; 60/~bpm })], inf).play

Dan Stowell
- 4,618
- 2
- 20
- 30
-
Easier than I thought! What about wav samples, would it be much more complicated? – ciembor Jul 26 '15 at 01:31
-
OK, added that to my answer. If you like the answer pls accept it :) – Dan Stowell Jul 27 '15 at 07:53