Controlling a SynthDef's envelope, from a "Master"

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Controlling a SynthDef's envelope, from a "Master"

Jables Deutsch
Hi List,

I posted a little while ago about messing with Pitch.kr for a friend's project, but I'm realizing in retrospect that my question was too big for anyone to spend time on..

I've simplified the problem to one specific issue: 

I'd like to be constantly monitoring an input signal. When the input signal goes above a threshold, I'd like to create a new instantiation of a Synth. When it goes below the threshold, I'd like to kill that instantiation.

Below is what I've come up with so far, but it's not working. Basically, the idea was that I'd send an OSC trigger for "on" that made the new Synth and a separate OSC trigger for "off" that would set a different value for the Synth, below a threshold. 

Any help would be greatly appreciated.. I feel totally lost at the moment. 
-----

(
SynthDef(\ok, {|vol=1, on, off, gatedVolume|
var in = SoundIn.ar(0);

vol=EnvFollow.kr(in);
gatedVolume = Select.ar(vol<0.35, [in, Silence.ar]);
on = Trig1.ar(gatedVolume>0.4);
off = Trig1.ar(gatedVolume<0.01);
SendReply.ar(on,'/on', [1], 1);
SendReply.ar(off,'/off', [gatedVolume>0], 1);
Out.ar(~bus, gatedVolume);
}).play;

SynthDef("tart",{|gateOff=1|
    var in, env;
in=SinOsc.ar(220, 0, 0.1);
env = EnvGen.ar(Env.adsr(0.5, 0.5, 1.0, 0.5), gateOff, doneAction:2);
Out.ar(0, in*env);
}).add;

OSCdef(\on, {
    |mess|
mess[3].postln;
x=Synth.new("tart", [\gateOff, 1], addAction:'addToTail');
}, \one, s.addr, nil, [nil, 1]);

OSCdef(\off, {
    |mess|
mess[3].postln;
x.set(\gateOff, 0);
}, \two, s.addr, nil, [nil, 1]);

)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Controlling a SynthDef's envelope, from a "Master"

Fredrik Olofsson
hi,
i've posted this one here before and it is what i use for detecting sounds.

(
s.latency= 0.05;
s.waitForBoot{
        var z= 16;  //optional counter
        SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
                var input= SoundIn.ar;
                var off= DetectSilence.ar(input, thresh, time);
                var on= 1-off; //invert
                var cnt= PulseCount.ar(on)%z+1; //buffer index counter
                var changed= HPZ1.ar(on).abs>0; //trigger
                SendTrig.ar(changed, 0, on*cnt); //0= rec off, >0 rec start index
        }).add;
        s.sync;
        OSCdef(\detector, {|msg|
                msg.postln;
        },'/tr');
        d= Synth(\f0SoundDetector);
};
)

d.set(\thresh, 0.1, \time, 0.1);  //time is required silence between sounds

basically it arms a trigger when it's been silent for 'time' seconds.  simple but works well for segmenting speech and musical phrases.
for your needs it could be simplified a bit (the counter is there for recording in to multiple buffers) but you can also ignore that and use as is.

quickly looking at your example i guess it could be greatly simplified with the Schmidt ugen.
good luck,
_f

> 9 mar 2017 kl. 23:20 skrev Jables Deutsch <[hidden email]>:
>
> Hi List,
>
> I posted a little while ago about messing with Pitch.kr for a friend's project, but I'm realizing in retrospect that my question was too big for anyone to spend time on..
>
> I've simplified the problem to one specific issue:
>
> I'd like to be constantly monitoring an input signal. When the input signal goes above a threshold, I'd like to create a new instantiation of a Synth. When it goes below the threshold, I'd like to kill that instantiation.
>
> Below is what I've come up with so far, but it's not working. Basically, the idea was that I'd send an OSC trigger for "on" that made the new Synth and a separate OSC trigger for "off" that would set a different value for the Synth, below a threshold.
>
> Any help would be greatly appreciated.. I feel totally lost at the moment.
> -----
>
> (
> SynthDef(\ok, {|vol=1, on, off, gatedVolume|
> var in = SoundIn.ar(0);
>
> vol=EnvFollow.kr(in);
> gatedVolume = Select.ar(vol<0.35, [in, Silence.ar]);
> on = Trig1.ar(gatedVolume>0.4);
> off = Trig1.ar(gatedVolume<0.01);
> SendReply.ar(on,'/on', [1], 1);
> SendReply.ar(off,'/off', [gatedVolume>0], 1);
> Out.ar(~bus, gatedVolume);
> }).play;
>
> SynthDef("tart",{|gateOff=1|
>     var in, env;
> in=SinOsc.ar(220, 0, 0.1);
> env = EnvGen.ar(Env.adsr(0.5, 0.5, 1.0, 0.5), gateOff, doneAction:2);
> Out.ar(0, in*env);
> }).add;
>
> OSCdef(\on, {
>     |mess|
> mess[3].postln;
> x=Synth.new("tart", [\gateOff, 1], addAction:'addToTail');
> }, \one, s.addr, nil, [nil, 1]);
>
> OSCdef(\off, {
>     |mess|
> mess[3].postln;
> x.set(\gateOff, 0);
> }, \two, s.addr, nil, [nil, 1]);
>
> )
>


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Controlling a SynthDef's envelope, from a "Master"

Jables Deutsch
Ah, this is much more elegant than the (addTo)Tail I was chasing..

I am still a little confused about how to orient the OscDef to handle a different SynthDef, though..


Something like this should work, right? 

(
s.latency= 0.05;
s.waitForBoot{
        var z= 16;  //optional counter
        SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
                var input= SoundIn.ar;
                var off= DetectSilence.ar(input, thresh, time);
                var on= 1-off;                          //invert
                var changed= HPZ1.ar(on).abs>0; //trigger
                SendTrig.ar(changed, 0, on);       
        }).add;
        s.sync;

        OSCdef(\detector, {|msg|                                               
Synth.new("ok", [\vol, msg[3]], addAction: 'addToTail');
        },'/tr');
 
SynthDef(\ok, {|vol=1|
var sig = SinOsc.ar(220, 0, 0.1)*vol;
DetectSilence.ar(sig, doneAction:2);
Out.ar(1, sig);
}).add;
d= Synth(\f0SoundDetector);
};
)

On Thu, Mar 9, 2017 at 6:16 PM, Fredrik Olofsson <[hidden email]> wrote:
hi,
i've posted this one here before and it is what i use for detecting sounds.

(
s.latency= 0.05;
s.waitForBoot{
        var z= 16;  //optional counter
        SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
                var input= SoundIn.ar;
                var off= DetectSilence.ar(input, thresh, time);
                var on= 1-off;                          //invert
                var cnt= PulseCount.ar(on)%z+1; //buffer index counter
                var changed= HPZ1.ar(on).abs>0; //trigger
                SendTrig.ar(changed, 0, on*cnt);        //0= rec off, >0 rec start index
        }).add;
        s.sync;
        OSCdef(\detector, {|msg|
                msg.postln;
        },'/tr');
        d= Synth(\f0SoundDetector);
};
)

d.set(\thresh, 0.1, \time, 0.1);  //time is required silence between sounds

basically it arms a trigger when it's been silent for 'time' seconds.  simple but works well for segmenting speech and musical phrases.
for your needs it could be simplified a bit (the counter is there for recording in to multiple buffers) but you can also ignore that and use as is.

quickly looking at your example i guess it could be greatly simplified with the Schmidt ugen.
good luck,
_f

> 9 mar 2017 kl. 23:20 skrev Jables Deutsch <[hidden email]>:
>
> Hi List,
>
> I posted a little while ago about messing with Pitch.kr for a friend's project, but I'm realizing in retrospect that my question was too big for anyone to spend time on..
>
> I've simplified the problem to one specific issue:
>
> I'd like to be constantly monitoring an input signal. When the input signal goes above a threshold, I'd like to create a new instantiation of a Synth. When it goes below the threshold, I'd like to kill that instantiation.
>
> Below is what I've come up with so far, but it's not working. Basically, the idea was that I'd send an OSC trigger for "on" that made the new Synth and a separate OSC trigger for "off" that would set a different value for the Synth, below a threshold.
>
> Any help would be greatly appreciated.. I feel totally lost at the moment.
> -----
>
> (
> SynthDef(\ok, {|vol=1, on, off, gatedVolume|
>       var in = SoundIn.ar(0);
>
>       vol=EnvFollow.kr(in);
>       gatedVolume = Select.ar(vol<0.35, [in, Silence.ar]);
>       on = Trig1.ar(gatedVolume>0.4);
>       off = Trig1.ar(gatedVolume<0.01);
>       SendReply.ar(on,'/on', [1], 1);
>       SendReply.ar(off,'/off', [gatedVolume>0], 1);
>       Out.ar(~bus, gatedVolume);
> }).play;
>
> SynthDef("tart",{|gateOff=1|
>     var in, env;
>       in=SinOsc.ar(220, 0, 0.1);
>       env = EnvGen.ar(Env.adsr(0.5, 0.5, 1.0, 0.5), gateOff, doneAction:2);
>       Out.ar(0, in*env);
> }).add;
>
> OSCdef(\on, {
>     |mess|
>       mess[3].postln;
>       x=Synth.new("tart", [\gateOff, 1], addAction:'addToTail');
> }, \one, s.addr, nil, [nil, 1]);
>
> OSCdef(\off, {
>     |mess|
>       mess[3].postln;
>       x.set(\gateOff, 0);
> }, \two, s.addr, nil, [nil, 1]);
>
> )
>


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Controlling a SynthDef's envelope, from a "Master"

Fredrik Olofsson
almost, but not quite right.  msg[3] isn't volume in this case - more like a flag that goes non-zero when there's a sound starting and goes back to zero when the sound ends.

may i also recommend to use a single synth object that's controlled with a gate instead.  it depends on what your planning to do with this, but creating new synth objects each time a sound is detected makes it hard to keep track of them and later turn off the right one when sound is stopping (osc msg zero - it shouldn't double trig but still - less risk of hanging notes).  with a single synth you'll avoid this bookkeeping and can keep the code simple.
like this...
(
s.latency= 0.05;
s.waitForBoot{
        var synth;
        var detector;
        var z= 16;  //optional counter
        SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
                var input= SoundIn.ar;
                var off= DetectSilence.ar(input, thresh, time);
                var on= 1-off;                          //invert
                var changed= HPZ1.ar(on).abs>0; //trigger
                SendTrig.ar(changed, 0, on);      
        }).add;
        SynthDef(\ok, {|gate= 0|
                var sig = SinOsc.ar(220, 0, 0.1)*EnvGen.kr(Env.asr(0.01, 1, 0.1), gate);
                Out.ar(1, sig);
        }).add;
        s.sync;
       
        detector= Synth(\f0SoundDetector);
        synth= Synth(\ok);
       
        OSCdef(\detector, {|msg|
                if(msg[3]>0, {
                        "on".postln;
                        synth.set(\gate, 1);
                }, {
                        "off".postln;
                        synth.set(\gate, 0);
                });
        },'/tr');
};
)

_f

> 10 mar 2017 kl. 08:21 skrev Jables Deutsch <[hidden email]>:
>
> Ah, this is much more elegant than the (addTo)Tail I was chasing..
>
> I am still a little confused about how to orient the OscDef to handle a different SynthDef, though..
>
>
> Something like this should work, right?
>
> (
> s.latency= 0.05;
> s.waitForBoot{
>         var z= 16;  //optional counter
>         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
>                 var input= SoundIn.ar;
>                 var off= DetectSilence.ar(input, thresh, time);
>                 var on= 1-off;                          //invert
>                 var changed= HPZ1.ar(on).abs>0; //trigger
>                 SendTrig.ar(changed, 0, on);      
>         }).add;
>         s.sync;
>
>         OSCdef(\detector, {|msg|                                              
> Synth.new("ok", [\vol, msg[3]], addAction: 'addToTail');
>         },'/tr');
>  
> SynthDef(\ok, {|vol=1|
> var sig = SinOsc.ar(220, 0, 0.1)*vol;
> DetectSilence.ar(sig, doneAction:2);
> Out.ar(1, sig);
> }).add;
> d= Synth(\f0SoundDetector);
> };
> )
>
> On Thu, Mar 9, 2017 at 6:16 PM, Fredrik Olofsson <[hidden email]> wrote:
> hi,
> i've posted this one here before and it is what i use for detecting sounds.
>
> (
> s.latency= 0.05;
> s.waitForBoot{
>         var z= 16;  //optional counter
>         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
>                 var input= SoundIn.ar;
>                 var off= DetectSilence.ar(input, thresh, time);
>                 var on= 1-off;                          //invert
>                 var cnt= PulseCount.ar(on)%z+1; //buffer index counter
>                 var changed= HPZ1.ar(on).abs>0; //trigger
>                 SendTrig.ar(changed, 0, on*cnt);        //0= rec off, >0 rec start index
>         }).add;
>         s.sync;
>         OSCdef(\detector, {|msg|
>                 msg.postln;
>         },'/tr');
>         d= Synth(\f0SoundDetector);
> };
> )
>
> d.set(\thresh, 0.1, \time, 0.1);  //time is required silence between sounds
>
> basically it arms a trigger when it's been silent for 'time' seconds.  simple but works well for segmenting speech and musical phrases.
> for your needs it could be simplified a bit (the counter is there for recording in to multiple buffers) but you can also ignore that and use as is.
>
> quickly looking at your example i guess it could be greatly simplified with the Schmidt ugen.
> good luck,
> _f
>
> > 9 mar 2017 kl. 23:20 skrev Jables Deutsch <[hidden email]>:
> >
> > Hi List,
> >
> > I posted a little while ago about messing with Pitch.kr for a friend's project, but I'm realizing in retrospect that my question was too big for anyone to spend time on..
> >
> > I've simplified the problem to one specific issue:
> >
> > I'd like to be constantly monitoring an input signal. When the input signal goes above a threshold, I'd like to create a new instantiation of a Synth. When it goes below the threshold, I'd like to kill that instantiation.
> >
> > Below is what I've come up with so far, but it's not working. Basically, the idea was that I'd send an OSC trigger for "on" that made the new Synth and a separate OSC trigger for "off" that would set a different value for the Synth, below a threshold.
> >
> > Any help would be greatly appreciated.. I feel totally lost at the moment.
> > -----
> >
> > (
> > SynthDef(\ok, {|vol=1, on, off, gatedVolume|
> >       var in = SoundIn.ar(0);
> >
> >       vol=EnvFollow.kr(in);
> >       gatedVolume = Select.ar(vol<0.35, [in, Silence.ar]);
> >       on = Trig1.ar(gatedVolume>0.4);
> >       off = Trig1.ar(gatedVolume<0.01);
> >       SendReply.ar(on,'/on', [1], 1);
> >       SendReply.ar(off,'/off', [gatedVolume>0], 1);
> >       Out.ar(~bus, gatedVolume);
> > }).play;
> >
> > SynthDef("tart",{|gateOff=1|
> >     var in, env;
> >       in=SinOsc.ar(220, 0, 0.1);
> >       env = EnvGen.ar(Env.adsr(0.5, 0.5, 1.0, 0.5), gateOff, doneAction:2);
> >       Out.ar(0, in*env);
> > }).add;
> >
> > OSCdef(\on, {
> >     |mess|
> >       mess[3].postln;
> >       x=Synth.new("tart", [\gateOff, 1], addAction:'addToTail');
> > }, \one, s.addr, nil, [nil, 1]);
> >
> > OSCdef(\off, {
> >     |mess|
> >       mess[3].postln;
> >       x.set(\gateOff, 0);
> > }, \two, s.addr, nil, [nil, 1]);
> >
> > )
> >
>
>
>   #|
>      fredrikolofsson.com     musicalfieldsforever.com
>   |#
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Controlling a SynthDef's envelope, from a "Master"

lance.bantham
Thank you, Fredrik - I have been struggling with this for over a week... The only problem is that I need the triggered Synths to overlap..Can you recommend a part of the documentation to read regarding "the bookkeeping" aspect of that? I feel a little foggy on how it's done..


On Fri, Mar 10, 2017 at 3:55 AM, Fredrik Olofsson <[hidden email]> wrote:
almost, but not quite right.  msg[3] isn't volume in this case - more like a flag that goes non-zero when there's a sound starting and goes back to zero when the sound ends.

may i also recommend to use a single synth object that's controlled with a gate instead.  it depends on what your planning to do with this, but creating new synth objects each time a sound is detected makes it hard to keep track of them and later turn off the right one when sound is stopping (osc msg zero - it shouldn't double trig but still - less risk of hanging notes).  with a single synth you'll avoid this bookkeeping and can keep the code simple.
like this...
(
s.latency= 0.05;
s.waitForBoot{
        var synth;
        var detector;
        var z= 16;  //optional counter
        SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
                var input= SoundIn.ar;
                var off= DetectSilence.ar(input, thresh, time);
                var on= 1-off;                          //invert
                var changed= HPZ1.ar(on).abs>0; //trigger
                SendTrig.ar(changed, 0, on);
        }).add;
        SynthDef(\ok, {|gate= 0|
                var sig = SinOsc.ar(220, 0, 0.1)*EnvGen.kr(Env.asr(0.01, 1, 0.1), gate);
                Out.ar(1, sig);
        }).add;
        s.sync;

        detector= Synth(\f0SoundDetector);
        synth= Synth(\ok);

        OSCdef(\detector, {|msg|
                if(msg[3]>0, {
                        "on".postln;
                        synth.set(\gate, 1);
                }, {
                        "off".postln;
                        synth.set(\gate, 0);
                });
        },'/tr');
};
)

_f

> 10 mar 2017 kl. 08:21 skrev Jables Deutsch <[hidden email]>:
>
> Ah, this is much more elegant than the (addTo)Tail I was chasing..
>
> I am still a little confused about how to orient the OscDef to handle a different SynthDef, though..
>
>
> Something like this should work, right?
>
> (
> s.latency= 0.05;
> s.waitForBoot{
>         var z= 16;  //optional counter
>         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
>                 var input= SoundIn.ar;
>                 var off= DetectSilence.ar(input, thresh, time);
>                 var on= 1-off;                          //invert
>                 var changed= HPZ1.ar(on).abs>0; //trigger
>                 SendTrig.ar(changed, 0, on);
>         }).add;
>         s.sync;
>
>         OSCdef(\detector, {|msg|
>               Synth.new("ok", [\vol, msg[3]], addAction: 'addToTail');
>         },'/tr');
>
>       SynthDef(\ok, {|vol=1|
>               var sig = SinOsc.ar(220, 0, 0.1)*vol;
>               DetectSilence.ar(sig, doneAction:2);
>               Out.ar(1, sig);
>       }).add;
> d= Synth(\f0SoundDetector);
> };
> )
>
> On Thu, Mar 9, 2017 at 6:16 PM, Fredrik Olofsson <[hidden email]> wrote:
> hi,
> i've posted this one here before and it is what i use for detecting sounds.
>
> (
> s.latency= 0.05;
> s.waitForBoot{
>         var z= 16;  //optional counter
>         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
>                 var input= SoundIn.ar;
>                 var off= DetectSilence.ar(input, thresh, time);
>                 var on= 1-off;                          //invert
>                 var cnt= PulseCount.ar(on)%z+1; //buffer index counter
>                 var changed= HPZ1.ar(on).abs>0; //trigger
>                 SendTrig.ar(changed, 0, on*cnt);        //0= rec off, >0 rec start index
>         }).add;
>         s.sync;
>         OSCdef(\detector, {|msg|
>                 msg.postln;
>         },'/tr');
>         d= Synth(\f0SoundDetector);
> };
> )
>
> d.set(\thresh, 0.1, \time, 0.1);  //time is required silence between sounds
>
> basically it arms a trigger when it's been silent for 'time' seconds.  simple but works well for segmenting speech and musical phrases.
> for your needs it could be simplified a bit (the counter is there for recording in to multiple buffers) but you can also ignore that and use as is.
>
> quickly looking at your example i guess it could be greatly simplified with the Schmidt ugen.
> good luck,
> _f
>
> > 9 mar 2017 kl. 23:20 skrev Jables Deutsch <[hidden email]>:
> >
> > Hi List,
> >
> > I posted a little while ago about messing with Pitch.kr for a friend's project, but I'm realizing in retrospect that my question was too big for anyone to spend time on..
> >
> > I've simplified the problem to one specific issue:
> >
> > I'd like to be constantly monitoring an input signal. When the input signal goes above a threshold, I'd like to create a new instantiation of a Synth. When it goes below the threshold, I'd like to kill that instantiation.
> >
> > Below is what I've come up with so far, but it's not working. Basically, the idea was that I'd send an OSC trigger for "on" that made the new Synth and a separate OSC trigger for "off" that would set a different value for the Synth, below a threshold.
> >
> > Any help would be greatly appreciated.. I feel totally lost at the moment.
> > -----
> >
> > (
> > SynthDef(\ok, {|vol=1, on, off, gatedVolume|
> >       var in = SoundIn.ar(0);
> >
> >       vol=EnvFollow.kr(in);
> >       gatedVolume = Select.ar(vol<0.35, [in, Silence.ar]);
> >       on = Trig1.ar(gatedVolume>0.4);
> >       off = Trig1.ar(gatedVolume<0.01);
> >       SendReply.ar(on,'/on', [1], 1);
> >       SendReply.ar(off,'/off', [gatedVolume>0], 1);
> >       Out.ar(~bus, gatedVolume);
> > }).play;
> >
> > SynthDef("tart",{|gateOff=1|
> >     var in, env;
> >       in=SinOsc.ar(220, 0, 0.1);
> >       env = EnvGen.ar(Env.adsr(0.5, 0.5, 1.0, 0.5), gateOff, doneAction:2);
> >       Out.ar(0, in*env);
> > }).add;
> >
> > OSCdef(\on, {
> >     |mess|
> >       mess[3].postln;
> >       x=Synth.new("tart", [\gateOff, 1], addAction:'addToTail');
> > }, \one, s.addr, nil, [nil, 1]);
> >
> > OSCdef(\off, {
> >     |mess|
> >       mess[3].postln;
> >       x.set(\gateOff, 0);
> > }, \two, s.addr, nil, [nil, 1]);
> >
> > )
> >
>
>
>   #|
>      fredrikolofsson.com     musicalfieldsforever.com
>   |#
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Controlling a SynthDef's envelope, from a "Master"

Fredrik Olofsson
ok, then here's a simple mod to my example that'll spawn new synth objects instead of (re)triggering the same.  note this relies on that the detector synth always send a zero in between 'on' triggers - else you'll get a hanging note.  but here i believe it should be safe.  hope it works for you.

(
s.latency= 0.05;
s.waitForBoot{
        var synth;  //current synth object is stored in this variable
        var detector;
        var z= 16;  //optional counter
        SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
                var input= SoundIn.ar;
                var off= DetectSilence.ar(input, thresh, time);
                var on= 1-off;                          //invert
                var changed= HPZ1.ar(on).abs>0; //trigger
                SendTrig.ar(changed, 0, on);
        }).add;
        SynthDef(\ok, {|gate= 1|
                var sig = SinOsc.ar(Rand(220, 990), 0, 0.1)*EnvGen.kr(Env.asr(0.01, 1, 0.5), gate, doneAction:2);
                Out.ar(1, sig);
        }).add;
        s.sync;
       
        detector= Synth(\f0SoundDetector);
       
        OSCdef(\detector, {|msg|
                if(msg[3]>0, {
                        "on".postln;
                        synth= Synth(\ok);  //create a new synth object
                }, {
                        "off".postln;
                        synth.set(\gate, 0);  //release synth (frees itself)
                });
        },'/tr');
};
)

for more advanced bookkeeping you could read up how to store your synth objects in List or in a IdentityDictionary.
_f

> 10 mar 2017 kl. 19:36 skrev Lance Bantham <[hidden email]>:
>
> Thank you, Fredrik - I have been struggling with this for over a week... The only problem is that I need the triggered Synths to overlap..Can you recommend a part of the documentation to read regarding "the bookkeeping" aspect of that? I feel a little foggy on how it's done..
>
>
> On Fri, Mar 10, 2017 at 3:55 AM, Fredrik Olofsson <[hidden email]> wrote:
> almost, but not quite right.  msg[3] isn't volume in this case - more like a flag that goes non-zero when there's a sound starting and goes back to zero when the sound ends.
>
> may i also recommend to use a single synth object that's controlled with a gate instead.  it depends on what your planning to do with this, but creating new synth objects each time a sound is detected makes it hard to keep track of them and later turn off the right one when sound is stopping (osc msg zero - it shouldn't double trig but still - less risk of hanging notes).  with a single synth you'll avoid this bookkeeping and can keep the code simple.
> like this...
> (
> s.latency= 0.05;
> s.waitForBoot{
>         var synth;
>         var detector;
>         var z= 16;  //optional counter
>         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
>                 var input= SoundIn.ar;
>                 var off= DetectSilence.ar(input, thresh, time);
>                 var on= 1-off;                          //invert
>                 var changed= HPZ1.ar(on).abs>0; //trigger
>                 SendTrig.ar(changed, 0, on);
>         }).add;
>         SynthDef(\ok, {|gate= 0|
>                 var sig = SinOsc.ar(220, 0, 0.1)*EnvGen.kr(Env.asr(0.01, 1, 0.1), gate);
>                 Out.ar(1, sig);
>         }).add;
>         s.sync;
>
>         detector= Synth(\f0SoundDetector);
>         synth= Synth(\ok);
>
>         OSCdef(\detector, {|msg|
>                 if(msg[3]>0, {
>                         "on".postln;
>                         synth.set(\gate, 1);
>                 }, {
>                         "off".postln;
>                         synth.set(\gate, 0);
>                 });
>         },'/tr');
> };
> )
>
> _f
>
> > 10 mar 2017 kl. 08:21 skrev Jables Deutsch <[hidden email]>:
> >
> > Ah, this is much more elegant than the (addTo)Tail I was chasing..
> >
> > I am still a little confused about how to orient the OscDef to handle a different SynthDef, though..
> >
> >
> > Something like this should work, right?
> >
> > (
> > s.latency= 0.05;
> > s.waitForBoot{
> >         var z= 16;  //optional counter
> >         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
> >                 var input= SoundIn.ar;
> >                 var off= DetectSilence.ar(input, thresh, time);
> >                 var on= 1-off;                          //invert
> >                 var changed= HPZ1.ar(on).abs>0; //trigger
> >                 SendTrig.ar(changed, 0, on);
> >         }).add;
> >         s.sync;
> >
> >         OSCdef(\detector, {|msg|
> >               Synth.new("ok", [\vol, msg[3]], addAction: 'addToTail');
> >         },'/tr');
> >
> >       SynthDef(\ok, {|vol=1|
> >               var sig = SinOsc.ar(220, 0, 0.1)*vol;
> >               DetectSilence.ar(sig, doneAction:2);
> >               Out.ar(1, sig);
> >       }).add;
> > d= Synth(\f0SoundDetector);
> > };
> > )
> >
> > On Thu, Mar 9, 2017 at 6:16 PM, Fredrik Olofsson <[hidden email]> wrote:
> > hi,
> > i've posted this one here before and it is what i use for detecting sounds.
> >
> > (
> > s.latency= 0.05;
> > s.waitForBoot{
> >         var z= 16;  //optional counter
> >         SynthDef(\f0SoundDetector, {|thresh= 0.075, time= 0.2|
> >                 var input= SoundIn.ar;
> >                 var off= DetectSilence.ar(input, thresh, time);
> >                 var on= 1-off;                          //invert
> >                 var cnt= PulseCount.ar(on)%z+1; //buffer index counter
> >                 var changed= HPZ1.ar(on).abs>0; //trigger
> >                 SendTrig.ar(changed, 0, on*cnt);        //0= rec off, >0 rec start index
> >         }).add;
> >         s.sync;
> >         OSCdef(\detector, {|msg|
> >                 msg.postln;
> >         },'/tr');
> >         d= Synth(\f0SoundDetector);
> > };
> > )
> >
> > d.set(\thresh, 0.1, \time, 0.1);  //time is required silence between sounds
> >
> > basically it arms a trigger when it's been silent for 'time' seconds.  simple but works well for segmenting speech and musical phrases.
> > for your needs it could be simplified a bit (the counter is there for recording in to multiple buffers) but you can also ignore that and use as is.
> >
> > quickly looking at your example i guess it could be greatly simplified with the Schmidt ugen.
> > good luck,
> > _f
> >
> > > 9 mar 2017 kl. 23:20 skrev Jables Deutsch <[hidden email]>:
> > >
> > > Hi List,
> > >
> > > I posted a little while ago about messing with Pitch.kr for a friend's project, but I'm realizing in retrospect that my question was too big for anyone to spend time on..
> > >
> > > I've simplified the problem to one specific issue:
> > >
> > > I'd like to be constantly monitoring an input signal. When the input signal goes above a threshold, I'd like to create a new instantiation of a Synth. When it goes below the threshold, I'd like to kill that instantiation.
> > >
> > > Below is what I've come up with so far, but it's not working. Basically, the idea was that I'd send an OSC trigger for "on" that made the new Synth and a separate OSC trigger for "off" that would set a different value for the Synth, below a threshold.
> > >
> > > Any help would be greatly appreciated.. I feel totally lost at the moment.
> > > -----
> > >
> > > (
> > > SynthDef(\ok, {|vol=1, on, off, gatedVolume|
> > >       var in = SoundIn.ar(0);
> > >
> > >       vol=EnvFollow.kr(in);
> > >       gatedVolume = Select.ar(vol<0.35, [in, Silence.ar]);
> > >       on = Trig1.ar(gatedVolume>0.4);
> > >       off = Trig1.ar(gatedVolume<0.01);
> > >       SendReply.ar(on,'/on', [1], 1);
> > >       SendReply.ar(off,'/off', [gatedVolume>0], 1);
> > >       Out.ar(~bus, gatedVolume);
> > > }).play;
> > >
> > > SynthDef("tart",{|gateOff=1|
> > >     var in, env;
> > >       in=SinOsc.ar(220, 0, 0.1);
> > >       env = EnvGen.ar(Env.adsr(0.5, 0.5, 1.0, 0.5), gateOff, doneAction:2);
> > >       Out.ar(0, in*env);
> > > }).add;
> > >
> > > OSCdef(\on, {
> > >     |mess|
> > >       mess[3].postln;
> > >       x=Synth.new("tart", [\gateOff, 1], addAction:'addToTail');
> > > }, \one, s.addr, nil, [nil, 1]);
> > >
> > > OSCdef(\off, {
> > >     |mess|
> > >       mess[3].postln;
> > >       x.set(\gateOff, 0);
> > > }, \two, s.addr, nil, [nil, 1]);
> > >
> > > )
> > >
> >
> >
> >   #|
> >      fredrikolofsson.com     musicalfieldsforever.com
> >   |#
> >
> >
> > _______________________________________________
> > sc-users mailing list
> >
> > info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> > archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> > search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
> >
>
>
>   #|
>      fredrikolofsson.com     musicalfieldsforever.com
>   |#
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Loading...