Cabbage Logo
Back to Cabbage Site

CsoundUnity Package (UPM) development

I rewrote the way CsoundUnity reads the csd, the idea is this: as you drag the file in the inspector, store a reference of the csd code as a string. Then recompile and reparse just when the file is changed on disk (I have a reference of the filepath and I can look with a FileWatcher when its hash changes).
On build the string should be saved by the editor.
So the problem about csd obfuscation is solved!
Also the channels should be saved, and maybe also their values.
And so also the channel values saving could be solved!
But for now I still have some problems, and no sound at all.

Now Csound starts like this:

    //instead of this
    //int ret = Csound6.NativeMethods.csoundCompile(csound, 4, runargs);
    Csound6.NativeMethods.csoundSetOption(csound, $"--sample-rate={AudioSettings.outputSampleRate}");
    Csound6.NativeMethods.csoundSetOption(csound, "--ksmps=32");
    Csound6.NativeMethods.csoundSetOption(csound, "-n");
    // csdFile now holds the csd code
    int ret = Csound6.NativeMethods.csoundCompileCsdText(csound, csdFile);

    compiledOk = ret == 0 ? true : false;

I’m not sure how to set the sample-rate and ksmps, I have lots of warnings. But it compiles, so I think I am on the right track!

You might have started with this bombshell!! :laughing: But I like where this is going. Nice one.

I just finished the rewrite, if you’re ok with this I can push the new branch to the repo so that you can help me find what’s wrong!
I think the performance ends too soon, I have this message at the end:

Score finished in csoundPerformKsmps() with 2.

Before that 4 Warnings:

system constants can only be set once

The editor inspector works, at least visually, then later when we have sound we can see if it sets values correctly.

Can you run

git checkout -d dev2

from your current branch, and then push that. It might be simpler, I can take a look now then.

error: unknown switch `d’


Sorry -b

I’m just checking out now…

…I’m making a copy of my current dev test first!

I did a backup too before branching :sweat_smile:

The score stops, so that’s why we are not hearing anything. What’s the tl;dr on this? Have you changed any of the audio processing methods, or the calls to csoundCompile or that?

The main change is how csound starts and compiles the csd. Now I pass the csd code as a string to CsoundUnityBridge, that then starts csound like I was writing in the first post.
The channels of CsoundUnity are created in the editor as soon as you drop the csd in the drop area.

Right, gotcha…

[edit] I think the clue is in the ‘Skipping CsOptions’ message. In Cabbage I use the CSOUND_PARAMS object to set up the CsOptions. I guess we can’t use setOption in this case? Any chance you want to have a go at implementing these?

        // PUBLIC void csoundSetParams (CSOUND *csound, CSOUND_PARAMS *p)

        // PUBLIC void csoundGetParams (CSOUND *csound, CSOUND_PARAMS *p)

Ok after my pasta with tuna I’ll see if I can find them already implemented in csound6net :joy:
EDIT: done! (copypasting like there was no tomorrow)

1 Like

That must have been a very large bowl of tuna! :laughing:

You know, pasta with tuna is an institution in italy :sunglasses:
Btw, I managed to get sound, but it’s more like a noisy hiss :scream:
I tried the setParams function an it seems to work. But first I have to get the params and then modify sr, ksmps and 0dbfs, or I have errors.
Now it’s like this (I’ll paste the whole CsoundUnityBridge constructor, without logs and env settings)

    public CsoundUnityBridge(string csoundDir, string csdFile)
        csound = Csound6.NativeMethods.csoundCreate(System.IntPtr.Zero);
        int systemBufferSize;
        int systemNumBuffers;
        AudioSettings.GetDSPBufferSize(out systemBufferSize, out systemNumBuffers);
        Csound6.NativeMethods.csoundSetHostImplementedAudioIO(csound, 1, 0);
        Csound6.NativeMethods.csoundCreateMessageBuffer(csound, 0);
        Csound6.NativeMethods.csoundSetOption(csound, "-n");
        var parms = GetParams();
        parms.control_rate_override = 32;
        parms.sample_rate_override = AudioSettings.outputSampleRate;
        parms.e0dbfs_override = 1;
        int ret = Csound6.NativeMethods.csoundCompileCsdText(csound, csdFile);
        compiledOk = ret == 0 ? true : false;
        Debug.Log("csoundCompile: " + compiledOk);

The systemBufferSize and SystemNumBuffers are not used. Maybe they’re the key?

Can you push to dev2? Ok my phone right now, but will be back at my PC in a bit…

It’s there!

Call csoundStart() after you compile the csd text. Works for me here now. Great, that’s another things done!

    int ret = Csound6.NativeMethods.csoundCompileCsdText(csound, csdFile);

No more errors here, but still no sound :thinking:

Do you still see a “Skipping CsOptions” message?

No, I see “Creating options”