0

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?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
ciembor
  • 7,189
  • 13
  • 59
  • 100

1 Answers1

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