Csound Csound-dev Csound-tekno Search About

[Csnd] csound timing accuray

Date2019-01-13 18:59
FromRichard
Subject[Csnd] csound timing accuray
i have a metronome instrument that sounds every half second.

I also have a bass instrument where i send events to - they are 
scheduled via cs.sendEvent(), also half second apart

When I start the csd, the metronome and my instrument are in sync, but 
after a few seconds the bass instrument starts lagging behind the 
metronome. How can this be?

Richard

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-01-13 19:31
FromTarmo Johannes
SubjectRe: [Csnd] csound timing accuray
Hi, 

Csound is extremely accurate timewise -  if you use very high samplerates you 
could theoretically achieve preciseness of nanoseconds (If I am correct) -  
but this is not what a human listener needs. I guess there could be something 
in your code (or maybe some hidden bug... ).

Can you send how you use the metronome and how the sounds are started?

tarmo

On pühapäev, 13. jaanuar 2019 20:59.21 EET you wrote:
> i have a metronome instrument that sounds every half second.
> 
> I also have a bass instrument where i send events to - they are
> scheduled via cs.sendEvent(), also half second apart
> 
> When I start the csd, the metronome and my instrument are in sync, but
> after a few seconds the bass instrument starts lagging behind the
> metronome. How can this be?
> 
> Richard
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-01-13 20:08
FromRichard
SubjectRe: [Csnd] csound timing accuray
Attachmentstemp.csd  
Here is the csd. The Python program using it is getting quite complex, 
it is going to be a 4 channel DAW with PySimpleGUI.

The csd is started with ctcsound. When starting the csd, also the 
following function is called:

def createScore():
     s='11,% 3.2f,0.10,41,91'
     for t in range(0,500,1):
         print(s % (t/2.0,))
         cs.scoreEvent('i', eval(s % (t/2.0,)))

Pressing play in the GUI does this:

     if event=='Play' and not recording:
         print('Play pressed')
         pulse('metroon')    # sends a 1, then a 0 to the 'metroon' channel
         createScore()

So the events are all queued and csound should handle the timing.

On 13/01/2019 20:31, Tarmo Johannes wrote:
> Hi,
>
> Csound is extremely accurate timewise -  if you use very high samplerates you
> could theoretically achieve preciseness of nanoseconds (If I am correct) -
> but this is not what a human listener needs. I guess there could be something
> in your code (or maybe some hidden bug... ).
>
> Can you send how you use the metronome and how the sounds are started?
>
> tarmo
>
> On pühapäev, 13. jaanuar 2019 20:59.21 EET you wrote:
>> i have a metronome instrument that sounds every half second.
>>
>> I also have a bass instrument where i send events to - they are
>> scheduled via cs.sendEvent(), also half second apart
>>
>> When I start the csd, the metronome and my instrument are in sync, but
>> after a few seconds the bass instrument starts lagging behind the
>> metronome. How can this be?
>>
>> Richard
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>          https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-01-13 20:39
FromTarmo Johannes
SubjectRe: [Csnd] csound timing accuray
Hi,

I did not test and don't have a definite answer yet but I think the problem is 
that it takes some time from a command to arrive from Python to Csound:

pulse('metroon')  

happens first and when this is done you call

createScore()

Also in the score loop of createScore
for t in range(0,500,1):
         print(s % (t/2.0,))
         cs.scoreEvent('i', eval(s % (t/2.0,)))
cs.ScoreEvent may take some time thus every next event arrives to Csound one 
or several k-cycles later, hence the shift.

I think it is much better to make the score generation happen also in csound 
side (have an instrumente createScore that starts also the metronome 
instrument) OR you should add some design that the new events may be started 
only on metronomes trigger (schedkwhen in Csound -  but you cannot send this 
directly from host to csd, since it is k-time opcode, so you need some kind of 
wrapper instrument in between anyway).

Hope if it is of any help...

tarmo


On pühapäev, 13. jaanuar 2019 22:08.31 EET you wrote:
>  pulse('metroon')    # sends a 1, then a 0 to the 'metroon' channel
>          createScore()

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-01-13 20:58
FromRichard
SubjectRe: [Csnd] csound timing accuray
But it starts ok (in sync), only after 10 seconds or so it starts to 
deviate.

Also, the events are queued much faster than they should execute (.5 
seconds apart),so even if it takes a few k -cycles for them to arrive at 
csound, that should not matter.

On 13/01/2019 21:39, Tarmo Johannes wrote:
> Hi,
>
> I did not test and don't have a definite answer yet but I think the problem is
> that it takes some time from a command to arrive from Python to Csound:
>
> pulse('metroon')
>
> happens first and when this is done you call
>
> createScore()
>
> Also in the score loop of createScore
> for t in range(0,500,1):
>           print(s % (t/2.0,))
>           cs.scoreEvent('i', eval(s % (t/2.0,)))
> cs.ScoreEvent may take some time thus every next event arrives to Csound one
> or several k-cycles later, hence the shift.
>
> I think it is much better to make the score generation happen also in csound
> side (have an instrumente createScore that starts also the metronome
> instrument) OR you should add some design that the new events may be started
> only on metronomes trigger (schedkwhen in Csound -  but you cannot send this
> directly from host to csd, since it is k-time opcode, so you need some kind of
> wrapper instrument in between anyway).
>
> Hope if it is of any help...
>
> tarmo
>
>
> On pühapäev, 13. jaanuar 2019 22:08.31 EET you wrote:
>>   pulse('metroon')    # sends a 1, then a 0 to the 'metroon' channel
>>           createScore()
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-01-13 21:38
FromRichard
SubjectRe: [Csnd] csound timing accuray
I found a nice workaround, I now trigger the metronome also via 
cs.ScoreEvent() and that seems to work..

On 13/01/2019 21:39, Tarmo Johannes wrote:
> Hi,
>
> I did not test and don't have a definite answer yet but I think the problem is
> that it takes some time from a command to arrive from Python to Csound:
>
> pulse('metroon')
>
> happens first and when this is done you call
>
> createScore()
>
> Also in the score loop of createScore
> for t in range(0,500,1):
>           print(s % (t/2.0,))
>           cs.scoreEvent('i', eval(s % (t/2.0,)))
> cs.ScoreEvent may take some time thus every next event arrives to Csound one
> or several k-cycles later, hence the shift.
>
> I think it is much better to make the score generation happen also in csound
> side (have an instrumente createScore that starts also the metronome
> instrument) OR you should add some design that the new events may be started
> only on metronomes trigger (schedkwhen in Csound -  but you cannot send this
> directly from host to csd, since it is k-time opcode, so you need some kind of
> wrapper instrument in between anyway).
>
> Hope if it is of any help...
>
> tarmo
>
>
> On pühapäev, 13. jaanuar 2019 22:08.31 EET you wrote:
>>   pulse('metroon')    # sends a 1, then a 0 to the 'metroon' channel
>>           createScore()
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here