# Synth triggered by the level of a sample

**URL:** <https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325>\
**Category:** Support, Help & Resources\
**Created:** [January 2, 2022, 4:56pm UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325 "2022-01-02T16:56:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prof1220](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/prof1220/32/1150_2.png) [@Prof1220](https://in-thread.sonic-pi.net/u/Prof1220)\
**Post date:** [January 2, 2022, 4:56pm UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/1 "2022-01-02T16:56:50Z")

</div>

Hi everybody,  
as a newbie, I wonder if there is some way to obtain the following result.  
When a sample (or live\_audio) is playing, the level (amplitude) of the sampled-sound controls another action: if it overcomes a threshold level, it triggers a note synth. In other words: is there a way to read continuously the level of a sample or the live\_audio input?  
An example of this could be: a piano chord is triggered when a recorded speaking voice accentuates some vowels or in a drums loop the snare is hit.  
Thanks in advance to everyone who would like to answer,  
Leo

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [January 3, 2022, 5:17am UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/2 "2022-01-03T05:17:27Z")

</div>

@Prof1220 - @samaaron began attempting to integrate an amplitude monitor into Sonic Pi a while ago, but this has not been successfully completed. (See the following code segments for a few of the pieces:)

> <https://github.com/sonic-pi-net/sonic-pi/blob/3959d0e5924f58af9fb174036891e233d677b767/app/server/ruby/lib/sonicpi/studio.rb#L74-L76>

> <https://github.com/sonic-pi-net/sonic-pi/blob/3959d0e5924f58af9fb174036891e233d677b767/app/server/ruby/lib/sonicpi/studio.rb#L214-L219>

> <https://github.com/sonic-pi-net/sonic-pi/blob/dev/etc/synthdefs/designs/overtone/sonic-pi/src/sonic_pi/monitor.clj>

---

<div class="post-metadata">

**Author:** ![Prof1220](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/prof1220/32/1150_2.png) [@Prof1220](https://in-thread.sonic-pi.net/u/Prof1220)\
**Post date:** [January 3, 2022, 10:05am UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/3 "2022-01-03T10:05:01Z")

</div>

@ethancrawford, thank you for your suggestions. I suppose that this task is beyond my ability, but at list now I know it! Maybe in the future, I will try a workaround using Gate in Ableton Live as a trigger, sending MIDI note on/off (but I’ve still a lot to learn first in Sonic Pi).  
All the best,  
Leo

---

<div class="post-metadata">

**Author:** ![Hussein](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/hussein/32/1972_2.png) [@Hussein](https://in-thread.sonic-pi.net/u/Hussein)\
**Post date:** [January 3, 2022, 11:59am UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/4 "2022-01-03T11:59:52Z")

</div>

@Prof1220 As well as the gate, consider using an envelope follower. Some are shipped with Ableton or as M4L [Envelope Follower](https://maxforlive.com/library/index.php?by=any&q=envelope+follower).

---

<div class="post-metadata">

**Author:** ![Prof1220](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/prof1220/32/1150_2.png) [@Prof1220](https://in-thread.sonic-pi.net/u/Prof1220)\
**Post date:** [January 3, 2022, 1:54pm UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/5 "2022-01-03T13:54:37Z")

</div>

Thank you @Hussein, I will give a look.

---

<div class="post-metadata">

**Author:** ![Nina](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nina](https://in-thread.sonic-pi.net/u/Nina)\
**Post date:** [May 1, 2023, 4:33am UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/6 "2023-05-01T04:33:17Z")

</div>

Hi there!

I would like to know more about this, because I’m trying of check the state of a parameter’s synth or sample and use that data as part of a conditional. For example, if I set a pan slider in a synth that is playing to be able of checking in which point it is, in order to trigger another action. If this kind of information is being diplay in the register panel where I can see the data between brackets, how can I catch that data to use it? If a synth is a kind of ruby object, shouldn’t be a way to access to its parameters?

Thanks in advance.  
Nina

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [May 4, 2023, 1:51am UTC](https://in-thread.sonic-pi.net/t/synth-triggered-by-the-level-of-a-sample/6325/7 "2023-05-04T01:51:30Z")

</div>

Hello Nina,

> If a synth is a kind of ruby object, shouldn’t be a way to access to its parameters?

There is no way to retrieve the current value of a synth or fx opt directly from the playing synth or fx itself.  
You _can_ still use conditional checks to affect your script based on opt values, but you must deal with the opt values by assigning them to variables and working with them _before_ assigning them to the fx or synth.

The reason that you cannot access opt values directly from the synth or fx “object” is that Sonic Pi is its own language that is built on top of Ruby. It is not, however, intended to be an extension of, or 100% compatible with all of Ruby.  
(If you wish to read a bit more about that, see topics such as the following):

> [@MIDI loop/recording](https://in-thread.sonic-pi.net/t/midi-loop-recording/811/3):
>
> Hi @cyprien, you’re working on something fun - I’m looking forward to watching your progress. However, be aware that ‘all of standard Ruby’ is not supported in Sonic Pi. Although Sonic Pi is built-on-top-of Ruby, it isn’t Ruby and not all of Ruby works well with Sonic Pi’s design. For the record, only the things documented in the help section are officially supported. Everything else may or may not work and today and that situation may change without notice in the future. In other words, if y…

> [@Sonic Pi lang, Ruby and the eval](https://in-thread.sonic-pi.net/t/sonic-pi-lang-ruby-and-the-eval/6142):
>
> Sonic Pi is said to be a language “based on” or “derived from” Ruby. Trying to better understand how the Runtime interprets and executes the code I found that (correct me if I’m wrong) at the end of a lot of smart code there’s a call to the Kernel.eval() method. I suppose something magic happens before or after that evaluation that makes Sonic Pi a domain specific subset of Ruby, as stated elsewhere (e.g. the thread about using classes in Sonic Pi). I’m not an expert with Ruby so I wasn’t able…

> [@Loading Ruby gems for use within a Sonic Pi buffer](https://in-thread.sonic-pi.net/t/loading-ruby-gems-for-use-within-a-sonic-pi-buffer/2174):
>
> I’m trying to figure out how to load a Ruby gem for use within a Sonic Pi buffer. Has anyone tried doing this? I found this related thread from 2015: [https://groups.google.com/forum/#!msg/sonic-pi/QgX82sXcHqY/wNpxGLhggmUJ](https://groups.google.com/forum/#!msg/sonic-pi/QgX82sXcHqY/wNpxGLhggmUJ) I’m interested to hear your thoughts on that discussion. Here are mine: I get that Sonic Pi != Ruby, but I love that I can use plain old Ruby objects in Sonic Pi and it’d be really cool to know how to package them up and share them. Ruby gems come to mind. One of the project…

Hope that clears things up a bit - there will no doubt be plenty of folks able to help if you have further questions 🙂
