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!
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.
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.
[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)
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?