Cabbage Logo
Back to Cabbage Site

Do I need to use CsoundPerformanceThread...?

Hi Rory

I honestly don’t know if this is the best forum to ask this, but as you are the Csound API guru in my humble opinion, I thought I’d ask you!

I’m experimenting with creating a plugin for Plogue Bidule and I’ve got a plugin up and running, using Spout and making sound. All good, but I get little cpu spikes and glitches in the audio; should I be using a CsoundPerformanceThread?

cheers in advance

No. When using Csound in a plugin you simply call performKsmps() from the plugin’s processBlock function. Messing with other threads will be world of pain. What plugin type are you building? And are you using the SDK directly, or using JUCE/iPlug/etc…

Using the Bidule sdk directly. Have you used it?

Plugin type…in the sense of? I want to make something similar to the csound6~ Pd external. Arguably yes, I could just use Cabbage and make a AU/VST, but it’s kind of a learning exercise and closer integration would be useful. Plus I like making life harder for myself.

void CsoundTest::process(Sample** sampleIn, Sample** sampleOut, MIDIEvents* midiIn, MIDIEvents* midiOut, Frequency*** freqIn, Frequency*** freqOut, Magnitude*** magIn, Magnitude*** magOut, SyncInfo* syncIn, SyncInfo* syncOut){

long sampleFrames = _dspInfo.bufferSize;
unsigned int channels = 2;
Sample* s1 = sampleOut[0];
Sample* s2 = sampleOut[1];

while(--sampleFrames >= 0) {
    if (ksmpsIndex == csound->GetKsmps()) {
        csCompileResult = csound->PerformKsmps();
        if (csCompileResult == 0)
            ksmpsIndex = 0;
    (*s1++) = spout[0 + (ksmpsIndex * channels)];
    (*s2++) = spout[1 + (ksmpsIndex * channels)];

^ that’s the essence of what I have working so far. The process block that is

No, I wasn’t even aware there was one. but I like their stuff.

We should start a club :rofl:

The processing method seems pretty succinct. The dropouts could be coming from elsewhere. Do they get better or worse if you change the ksmps in your .csd file?

Changing ksmps doesn’t seem to affect it, though they seem like 1 sample dropouts/discontinuities. I was convinced that it was when moving windows around or interacting with the computer somehow, but I’m not sure really.


that said, when it was running in the background and I just looking for the emoticon above, it glitched a lot

Do you have csound->SetHostImplementedAudioIO(1, 0); set?

I hadn’t but I just tried and still getting dropouts. I’m gonna keep an eye on it. I probably make out that it’s terrible, but it isn’t, just enough to bait me. I’ll try tomorrow after a fresh restart as it could equally be some other process running that’s pegging the cpu. Definitely graphics related tho


Let me know if you can’t get past it. It’s usually something simple.

p.s. where can I find this sdk?

:+1: cheers

It’s not publicly available on the site. I think he doesn’t want the likes of me sending him annoying questions, which I do anyway. You have to email email_address who’s the lead developer on that product.

I might do, if I need to experience higher levels of pain than usual. I’m going to block out that email address just in case :+1: Don’t want him spammed on account of us :rofl:

ahh yeah thanks for editing that, I did ponder it for a second, but thought nahhh no one does that :rofl:

This morning I’m finding when hitting cmd+s to save something in VS Code (which is running some node processes), that’s a factor that causes hiccups in the audio stream. Seems totally unrelated, but unless it’s a thread issue?

It’s hard to say without seeing the SDK. but for now you might try filling s1 and s2 with a wave table and see if you continue to get dropouts. If you make the sine table = buffer size and sr = 44100, you should hear a tone around 172 Hz. If you get dropouts there you know Csound isn’t to blame :+1:

do you mean a wavetable in Csound, or in place of spout[0 + (ksmpsIndex * channels)]?

I just mean create an array of 256 floats, fill it with a cycle of a sine, and then do:

(*s1++) = table[sampleIndex];
(*s1++) = table[sampleIndex];
sampleIndex = sampleIndex < table_size ? sampleIndex+1 : 0; 

Bypass Csound altogether…

got it thanks!

my sine wave ended up being a ramp (didn’t factor in sin needs radians!) but yeah the tone is 172Hz with no dropouts