How to trigger sound samples with an input signal?

I’m trying to write code but don’t know where to start. I hope all of you out there can give me a head start. My idea is to have sound samples (short phrases and words) triggered by amplitudes of an input signal (a guitar).

Let’s say if I have a signal range from 0.1-0.3, it will trigger sample no.1, and from 0.4-0.6, it will trigger sample no.2. Another idea is whether it’s possible to have samples triggered by frequencies of input signal (a guitar)

Thank you so much, and I’m excited to work on it

This may be interesting to watch:

1 Like

I just watched the video @shiihs posted, excellent starting point. The main challenge in what you are describing is getting reliable and not too many triggers. You cannot really use amplitude as since the values fluctuate too much. You need to measure the loudness or the rms of the signal or something similar. Here is an example using rms to set a sound between 3 different states : silence, 110 hz and 220 hz, maybe it can serve as inspiration. The threshold settings are tuned to my guitar setup, you should tune them according to your input level. Also play around with the window size of the rms.

	var in =;
	var rms = MovingAverage.rms(in, s.sampleRate * 0.1, s.sampleRate);
	var trig1 = > 0.05, rms < 0.05);
	var trig2 = > 0.1, rms < 0.1);
	var sig = [,, 0.1),, 0.1)];
	(trig1 + trig2).poll; + trig2).lag(0.2), sig)

Amazing! Thank yo so much for the tips, @shiihs

This is so great to give me a head start. Thank you so much, @Thor_Madsen

FYI Pure Data has bonk