# CsoundUnity Package (UPM) development

**URL:** <https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916>\
**Category:** Csound for Games\
**Created:** [6 May 2020 14:57 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916 "2020-05-06T14:57:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [6 May 2020 14:57 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/1 "2020-05-06T14:57:30Z")

</div>

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");
    Csound6.NativeMethods.csoundStart(csound);
    // 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!

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [6 May 2020 15:10 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/2 "2020-05-06T15:10:15Z")

</div>

> [@giovannibedetti](#):
>
> But for now I still have some problems, and no sound at all.

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

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [7 May 2020 19:33 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/3 "2020-05-07T19:33:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [7 May 2020 19:42 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/4 "2020-05-07T19:42:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [7 May 2020 19:47 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/5 "2020-05-07T19:47:39Z")

</div>

> [@rorywalsh](#):
>
> git checkout -d dev2

error: unknown switch `d’

☹

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [7 May 2020 19:48 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/6 "2020-05-07T19:48:20Z")

</div>

Sorry -b

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [7 May 2020 20:00 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/7 "2020-05-07T20:00:36Z")

</div>

I’m just checking out now…

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

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [7 May 2020 20:02 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/8 "2020-05-07T20:02:50Z")

</div>

I did a backup too before branching 😅

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [7 May 2020 20:22 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/9 "2020-05-07T20:22:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [7 May 2020 20:26 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/10 "2020-05-07T20:26:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [7 May 2020 20:32 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/11 "2020-05-07T20:32:48Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [7 May 2020 20:49 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/12 "2020-05-07T20:49:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [8 May 2020 08:10 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/13 "2020-05-08T08:10:17Z")

</div>

That must have been a very large bowl of tuna! 😆

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [8 May 2020 11:57 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/14 "2020-05-08T11:57:11Z")

</div>

You know, pasta with tuna is an institution in italy 🕶  
Btw, I managed to get sound, but it’s more like a noisy hiss 😱  
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)
    {            
        Csound6.NativeMethods.csoundInitialize(1);
        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;
        SetParams(parms);
        Csound6.NativeMethods.csoundStart(csound);
        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?

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [8 May 2020 13:43 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/15 "2020-05-08T13:43:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [8 May 2020 14:01 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/16 "2020-05-08T14:01:23Z")

</div>

It’s there!

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [8 May 2020 14:27 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/17 "2020-05-08T14:27:22Z")

</div>

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);
    Csound6.NativeMethods.csoundStart(csound);
```

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [8 May 2020 14:47 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/18 "2020-05-08T14:47:15Z")

</div>

No more errors here, but still no sound 🤔

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [8 May 2020 14:49 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/19 "2020-05-08T14:49:32Z")

</div>

Do you still see a “Skipping CsOptions” message?

---

<div class="post-metadata">

**Author:** ![giovannibedetti](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/giovannibedetti/32/4146_2.png) [@giovannibedetti](https://forum.cabbageaudio.com/u/giovannibedetti)\
**Post date:** [8 May 2020 14:54 UTC](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916/20 "2020-05-08T14:54:24Z")

</div>

No, I see “Creating options”

[Next page](https://forum.cabbageaudio.com/t/csoundunity-package-upm-development/1916.md?page=2)
