Sig, SampHold, and Trig problem. Things not happening in code order: Sig.setValue happens at beginning of buffer?

31 views
Skip to first unread message

lucasparis

unread,
Aug 16, 2012, 11:10:03 AM8/16/12
to pyo-d...@googlegroups.com
Hey this is my first post here!

so I have a problem with this situation:

value = Sig(0)
trig = Trig()
samp = SampHold(value, trig,1)
printi = Print(samp,1)

def test():
    value.setValue(1)
    trig.play()
    value.setValue(2)

This should set samp's ouput to 1 and print it when the trig arives then set the control signal of the sample and hold to 2 so that the 2 is sampled on the next trig.
But what happens is that the 2 is sampled automatically, as if the code is executed like this:

value.setValue(1)
value.setValue(2)

My guess is that this happens because either Sig.setvalue or Trig.play() happens at the beginning of the buffer

Anybody can confirm this and tell me how to make it work in order? Thanks

lucasparis

unread,
Aug 16, 2012, 11:15:59 AM8/16/12
to pyo-d...@googlegroups.com
also I know a TrigValue object is in the works which would replace this, could you take into account this behaviour Oliver?

Olivier Bélanger

unread,
Aug 16, 2012, 11:34:28 PM8/16/12
to pyo-d...@googlegroups.com
Hi Lucas,

The problem is that every lines in the function are executed virtually at the same time. So, in the next server loop, when the trigger is really computed, the value of the Sig is already 2. in this example, you can avoid that by waiting one buffer size before calling value.setValue(2), with "import time":

    trig.play()
    time.sleep(s.getBufferSize()/s.getSamplingRate())
    value.setValue(2)

TrigVal will do what you need. I'm working on it right now!

Olivier
   
2012/8/16 lucasparis <lucaspa...@gmail.com>

Olivier Bélanger

unread,
Aug 17, 2012, 12:10:34 AM8/17/12
to pyo-d...@googlegroups.com
Done.

Revision 1016
Added new object: TrigVal: Outputs a previously defined value on a trigger signal.

Olivier

2012/8/16 Olivier Bélanger <bela...@gmail.com>

Olivier Bélanger

unread,
Aug 17, 2012, 12:56:19 AM8/17/12
to pyo-d...@googlegroups.com
Hi Lucas,

OscTrig Done.

Revision 1017
Added new object: OscTrig: An oscillator reading a waveform table with sample accurate reset signal.

Olivier

2012/8/17 Olivier Bélanger <bela...@gmail.com>

lucasparis

unread,
Aug 17, 2012, 10:21:43 AM8/17/12
to pyo-d...@googlegroups.com
yeaa thanks for TrigValue and OscTrig, it's christmas for me today!! going to test it out with TrigValue

lucasparis

unread,
Aug 17, 2012, 2:30:12 PM8/17/12
to pyo-d...@googlegroups.com
So same problem with TrigValue, the trig comes later.. Wouldn't it be possible to have the Trig happens instantly? I guess this is complicated because the buffer for the current time is being calculated so you can't shove the trig in there, you have to wait for the next buffer.

Your solution is a good Idea but It would not work in my scenario where I have this stuff happening in a class that could be instantiated about 50 times or more and the test() type function of these would get all called at the same time, so with a SR of 44100 and a buffer size of 512 all the delays would take 0.58 seconds which would be way too long. (The classes are for OSC audio input and implement Audio-rate value recalls, the value samp in my example goes to a Selector to change from the OSC input to the loading values)

Going to brainstorm on this but any suggestions are welcome

lucasparis

unread,
Aug 17, 2012, 3:00:09 PM8/17/12
to pyo-d...@googlegroups.com

So finally I found a solution using trigfunc to set the value after the trig arrives
Reply all
Reply to author
Forward
0 new messages