[Csnd] Question about ctcsound and .performKsmps()

Hi everyone,

I asked this on the Csound forum but didn’t get any takers, so I thought I’d ask the question to the mailing list.

I’m reading through Yi/Kaufman’s ctcsoundAPIExamples cookbook to try to wrap my head around the different ways to control Csound in Python. While I’ve had some success at using ctcsound, I’m still struggling to get a mental model of how elements like the Csound class, CsoundPerformanceThread class, .perform(), .performKsmps(), and the various methods of compilation and score insertion work together.

Can you break down how .performKsmps() actually works? I see that you can run it in a while loop to perform a score one k-frame at a time:

while (c.performKsmps() == 0):
pass

Does this mean that Python is telling Csound to perform the next k-frame each time Python passes through the while loop? If so, how is the timing synchronized between Python’s while loop and the k-frames in Csound? I assume Python’s while loop isn’t running at exactly the same rate as the k-rate.

Clearly, I don’t have a good mental model of what’s going on with .performKsmps(). Thanks for your help clarifying this!

Jason

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

Hi Jason,
As you suspected, calling performKsmps() asks Csound to perform one k-pass: setting k-rate variables and generating one audio vector of length ksmps.
It is synchronized with Python, so that whenever you call performKsmps(), Python will wait until the k-pass has completed, and Csound then give control back to Python.
All best
Øyvind

lør. 23. jan. 2021 kl. 21:17 skrev Jason Hallen <hallenj@gmail.com>:

Hi everyone,

I asked this on the Csound forum but didn’t get any takers, so I thought I’d ask the question to the mailing list.

I’m reading through Yi/Kaufman’s ctcsoundAPIExamples cookbook to try to wrap my head around the different ways to control Csound in Python. While I’ve had some success at using ctcsound, I’m still struggling to get a mental model of how elements like the Csound class, CsoundPerformanceThread class, .perform(), .performKsmps(), and the various methods of compilation and score insertion work together.

Can you break down how .performKsmps() actually works? I see that you can run it in a while loop to perform a score one k-frame at a time:

while (c.performKsmps() == 0):
pass

Does this mean that Python is telling Csound to perform the next k-frame each time Python passes through the while loop? If so, how is the timing synchronized between Python’s while loop and the k-frames in Csound? I assume Python’s while loop isn’t running at exactly the same rate as the k-rate.

Clearly, I don’t have a good mental model of what’s going on with .performKsmps(). Thanks for your help clarifying this!

Jason

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

Thanks for the response, Øyvind! I’ll keep this in mind as I continue working with ctcsound.

Best,
Jason