Ctcsound and .performKsmps() questions

Hi again,

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 help me clarify my mental model? Here are a couple questions.

  1. 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?

  2. Example 4 in the cookbook says “CsoundPerformanceThread has some convenient methods for handling events, but does not have features for doing regular processing at block boundaries. In general, use CsoundPerformanceThread when the only kinds of communication you are doing with Csound are through events, and not using channels.” Are using CsoundPerformanceThread and .performKsmps() mutually exclusive? I’m working on a project where I’ll want to trigger real-time score events and also send control messages through channels.

  3. The ctcsoundAPIExamples cookbook seems to advocate for processing control channel signals with .performKsmps(). In the PySimpleGUI/Csound cookbook they change control channel values using .setControlChannel() in the GUI event loop rather than a while loop executing .performKsmps(). What are the important differences between these two approaches?

Hopefully this can be helpful to any other people trying to figure these things out. Thanks!
Jason

For future reference, here’s Øyvind’s response from the mailing list:

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

1 Like