Looks right to me. In this case a single channel of audio is coming from Csound. So we give each Unity channel the same sample as we move through the buffer.
As long as it is a submultiple of the āsamplesā length, I see no problem!
It should call the GetAudioChannel method 64 times.
Maybe thereās some problem with Marshal.AllocHGlobal/Marshal.FreeHGlobal on the IntPtr of the buffer??
What kind of audio problem are you hearing?
How do you figure that? Iām calling it each time we run through ksmps worth of samples?
I look at that, but it seems fine to?
The pitch is too high, and there are periodic dropouts.
Iām trying to figure out if this is expected behaviour. My stinct tell me it is. It seems to me that we should only be calling csoundUnity.GetAudioChannel() on each k-boundary. The question is how.
The idea here is that we write a function in our local script, say a cube controller. We then pass this function to csound.SetYieldCallback(). Then on every k cycle our function is called. You can register as many callback functions are you wish.
It would look like this:
private void Awake()
{
csoundUnity = csoundUnityGameObject.GetComponent<CsoundUnity>();
if (!csoundUnity)
Debug.LogError("CsoundUnity was not found?");
}
void Start()
{
csoundUnity.SetYieldCallback(YieldCallback);
}
event csoundcsharp.Csound6.NativeMethods.YieldCallback YieldCallback = new csoundcsharp.Csound6.NativeMethods.YieldCallback((csd) =>
{
Debug.Log($"callback? ");
return 1;
});
[edit] btw, this is just how I have used these kind of functions in C/C++. Iāve no idea if this is feasible with C#, but for me, the callback stuff worked Ok. We just need to make it possible to register the callback outside of CsoundUnityā¦