Quantcast

staying a SinOsc or an equivalent Ugen at a specific phase for a while?

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

staying a SinOsc or an equivalent Ugen at a specific phase for a while?

prko
Hi,

Could a SinOsc or equivalent Ugens stay at a specific phase for a while?

I have partially realised it by using Done.kr, Line.kr, DC.ar and SinOsc.ar. (temporary solution 1)
However, I think there must be a better way to do this.
The weakness of the method is that it is very clumsy to control the value after SinOsc.ar stops.

I also tried it with Select.ar, DC.ar and SinOsc. (temporary solution 2)


// temporary solution 1
(
{
arg start=0.5;
var phase, wait, nonVib, vib;
phase= 3pi/2; // pi/2;
wait= Line.kr(1,1,start);
nonVib= DC.ar(phase.sin);
vib= SinOsc.ar(Done.kr(wait)*start.reciprocal, phase, 1.557407724655).atan
}.plot(1.5)
)


// temporary solution 2
(
{
arg start=0.5;
var phase, which, nonVib, vib;
phase= 3pi/2; // pi/2;
nonVib= DC.ar(phase.sin);
vib= SinOsc.ar(start.reciprocal, phase, 1.557407724655).atan;
which = LFPulse.kr(start.reciprocal/2, 0.5)*2;
Select.ar(which, [ nonVib, vib ])
}.plot(2);
)

// the purpose of the codes above is to control the parameters of a vibrato as follows:
// in the following code, the phase at the last moment of SinOsc is not important, but controlling the phase at the last moment of SinOsc is important when repeating the vibrato in a Synth.
(
x= {
arg amp=1, len= 2, vPhase= 0, vStartAt= 0, vFreqS=3, vFreqE=7, vDepthS=1, vDepthE=1.5, vAmpAtten=0.3;
var wait, nonVib, vibFrq, vibDepth, vib, vibAmpAttenu, vibMul, sig;
vibFrq= XLine.kr(vFreqS, vFreqE, len-vStartAt);
vibDepth= XLine.kr(vDepthS, vDepthE, len-vStartAt);
wait= Line.kr(1,1,vStartAt*amp);
nonVib= DC.ar(vPhase.sin);
vib= SinOsc.ar(Done.kr(wait)*vibFrq, vPhase, 1.557407724655).atan.range(2**0, 2**(vibDepth/12));
vibAmpAttenu= XLine.kr(1, ((3/1) **( (vAmpAtten-0) / 2 ) * 1 ) - 1, vStartAt);
vibMul= 1 - ( (( ( ( 2**(vibDepth/12) ) / 1) ** ((vibFrq - -1) / (1 - -1 )) * 1 ) - 1 ));
sig = SinOsc.ar(440!2 * vib, 0, vibAmpAttenu*vibMul)*Env.perc(0.02, len).kr(doneAction:2) * amp
}
)
y=x.play(args: [vPhase: 3pi/2, vFreqS: 0.1, vStartAt: 0, len: 4])
y=x.play(args: [vPhase: 3pi/2, vFreqS: 0.1, vStartAt: 1, len: 4])
y=x.play(args: [vPhase: 3pi/2, vFreqS: 0.4, vStartAt: 0.2, vFreqE: 0.2, vDepthS: 5.1, vDepthE:  5, len: 2])

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

Re: staying a SinOsc or an equivalent Ugen at a specific phase for a while?

Fredrik Olofsson
hi,
there are many ways to do this.  here are two...

//alternative one - wavetable
(
s.waitForBoot{
        b= Buffer.alloc(s, 512);
        s.sync;
        b.sine1([1], true, false);
        s.sync;
        {
                var lfotrig= Impulse.kr(0.4); //trigger make lfo start at beginning of cycle
                var lforamp= Sweep.ar(lfotrig, 500); //ramping upwards when triggered
                var lfosine= BufRd.ar(1, b, lforamp, 0); //use ramp as reading position (phase)
                SinOsc.ar(lfosine*200+400, 0, 0.4)!2;
        }.play;
}
)

optionally - more complex lfo waves
b.sine1(1/[1, 3, 5, 7], false, false);
b.sine2(1/[1, 3, 5, 7], [1, 4, 1, 0.5], false, false);
b.sine3([1, 2, 4, 8], 0.5, [0, 0.1pi, 0.2pi, 0.3pi], false, false);



//alternative two - set frequency to zero
probably this is the easiest and most flexible one.  will work for a lot of different ugens.
(
{
        var lfopause= 1-MouseButton.kr(0, 1, 0); //click mouse to freeze
        var lfosine= SinOsc.ar(1*lfopause); //basically *0 to freeze the oscillator
        SinOsc.ar(lfosine*200+400, 0, 0.4)!2;
}.play;
)

in combination with a squarewave you can get it to automatically run for for example 3 cycles and then freeze for a bit
(
{
        var numCycles= 3;
        var lfopause= LFPulse.ar(20/numCycles*0.75, 1, 0.75); //freq here need to be calculated in relation to width and lfosine freq below
        var lfosine= SinOsc.ar(20*lfopause); //basically *0 to freeze the oscillator
        lfosine;
}.plot(0.5);
)

_f

> 15 maj 2017 kl. 03:01 skrev [hidden email]:
>
> Hi,
>
> Could a SinOsc or equivalent Ugens stay at a specific phase for a while?
>
> I have partially realised it by using Done.kr, Line.kr, DC.ar and SinOsc.ar. (temporary solution 1)
> However, I think there must be a better way to do this.
> The weakness of the method is that it is very clumsy to control the value after SinOsc.ar stops.
>
> I also tried it with Select.ar, DC.ar and SinOsc. (temporary solution 2)
>
>
> // temporary solution 1
> (
> {
> arg start=0.5;
> var phase, wait, nonVib, vib;
> phase= 3pi/2; // pi/2;
> wait= Line.kr(1,1,start);
> nonVib= DC.ar(phase.sin);
> vib= SinOsc.ar(Done.kr(wait)*start.reciprocal, phase, 1.557407724655).atan
> }.plot(1.5)
> )
>
>
> // temporary solution 2
> (
> {
> arg start=0.5;
> var phase, which, nonVib, vib;
> phase= 3pi/2; // pi/2;
> nonVib= DC.ar(phase.sin);
> vib= SinOsc.ar(start.reciprocal, phase, 1.557407724655).atan;
> which = LFPulse.kr(start.reciprocal/2, 0.5)*2;
> Select.ar(which, [ nonVib, vib ])
> }.plot(2);
> )
>
> // the purpose of the codes above is to control the parameters of a vibrato as follows:
> // in the following code, the phase at the last moment of SinOsc is not important, but controlling the phase at the last moment of SinOsc is important when repeating the vibrato in a Synth.
> (
> x= {
> arg amp=1, len= 2, vPhase= 0, vStartAt= 0, vFreqS=3, vFreqE=7, vDepthS=1, vDepthE=1.5, vAmpAtten=0.3;
> var wait, nonVib, vibFrq, vibDepth, vib, vibAmpAttenu, vibMul, sig;
> vibFrq= XLine.kr(vFreqS, vFreqE, len-vStartAt);
> vibDepth= XLine.kr(vDepthS, vDepthE, len-vStartAt);
> wait= Line.kr(1,1,vStartAt*amp);
> nonVib= DC.ar(vPhase.sin);
> vib= SinOsc.ar(Done.kr(wait)*vibFrq, vPhase, 1.557407724655).atan.range(2**0, 2**(vibDepth/12));
> vibAmpAttenu= XLine.kr(1, ((3/1) **( (vAmpAtten-0) / 2 ) * 1 ) - 1, vStartAt);
> vibMul= 1 - ( (( ( ( 2**(vibDepth/12) ) / 1) ** ((vibFrq - -1) / (1 - -1 )) * 1 ) - 1 ));
> sig = SinOsc.ar(440!2 * vib, 0, vibAmpAttenu*vibMul)*Env.perc(0.02, len).kr(doneAction:2) * amp
> }
> )
> y=x.play(args: [vPhase: 3pi/2, vFreqS: 0.1, vStartAt: 0, len: 4])
> y=x.play(args: [vPhase: 3pi/2, vFreqS: 0.1, vStartAt: 1, len: 4])
> y=x.play(args: [vPhase: 3pi/2, vFreqS: 0.4, vStartAt: 0.2, vFreqE: 0.2, vDepthS: 5.1, vDepthE:  5, len: 2])
>
> best,
> prko


  #|
     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: staying a SinOsc or an equivalent Ugen at a specific phase for a while?

lfsaw
thanks for this, fredrik,


I played a little around with your example, generalising it to arbitrary values for freq, pause cycles and dutycycles.


> On 15. May 2017, at 13:37, [hidden email] wrote:
>
> in combination with a squarewave you can get it to automatically run for for example 3 cycles and then freeze for a bit
> (
> {
> var numCycles= 3;
> var lfopause= LFPulse.ar(20/numCycles*0.75, 1, 0.75); //freq here need to be calculated in relation to width and lfosine freq below
> var lfosine= SinOsc.ar(20*lfopause); //basically *0 to freeze the oscillator
> lfosine;
> }.plot(0.5);
> )


However, I stumbled over inprecisions, possibly due to my stupidity/inability to calculate the correct factors, or is it due to FP-error?

(try changing the numCycles and pauseCycles )



(
Ndef(\pausing, {
        arg numCycles = 2, // how many cycles to play
        pauseCycles = 3, // how many cycles to mute
        freq = 200;
       
        var repeatRate = (pauseCycles+numCycles).reciprocal;
        var lfWidth   = numCycles * repeatRate;
        var lfFreq    = freq * repeatRate;
       
        var lfopause= LFPulse.ar(
                lfFreq,
                0.5,
                lfWidth
        );
       
        SinOsc.ar(freq*lfopause)
})
)


// all good (slight offset due to kr timing inaccuracy
Ndef(\pausing).set(\numCycles, 2);
Ndef(\pausing).set(\numCycles, 3);


// why is there a constant phase shift?
Ndef(\pausing).set(\numCycles, 3);
Ndef(\pausing).set(\numCycles, 7);


Ndef(\pausing).scope


cheers
        Till


_______________________________________________
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...