No problem. I’ve love out of range indices
CsoundUnity Package (UPM) development
OK it’s there
Oh btw, I was thinking, it would be really cool if we could use a dropdown list of available channels in our CsoundUnityNode component to select which channel to access :thinking
So after a user adds a CsoundUnityNode, they can just click and select from a list of available channels…
OK so just one can be used at a time! Now I understand
I’ll add the dropdown as a custom editor
But first I’m waiting for you to solve the IndexOutOfRangeException
The out of range is because our buffers are mono…
They are dsp buffer (1024) in size, yet there are 1024*2 samples passed to the OnAudioFilterRead()…
Ok fine, so the CsoundUnityNode should be aware of that!
Can we get somehow the number of channels of the AudioChannel from Csound?
Then when the CsoundUnityNode is added some initialization is needed.[EDIT:-> set its channel number]
And of course also when updating the namedAudioChannelDataDict[chanName] array
It’s always 1. , they only contain a single channel…
This works fine…
foreach (var node in csoundUnityNodes)
{
foreach (var chanName in node.GetChannelNames())
{
//Debug.Log(namedAudioChannelDataDict[chanName].Length + "-> i + channel: " + ((i/numChannels)));
namedAudioChannelDataDict[chanName][i/numChannels] = namedAudioChannelTempBufferDict[chanName][ksmpsIndex];
}
}
But yeah, what if we are sending two audio channels to our child node, do we mix or pass them to left and right?
[edit] I guess mixing should really be done on the Csound end. Why send two channels of audio to CsoundUnity to mix, when a simple + in Csound will do the trick.
Also, I think it would be fair to assume that 2 channels should be spaced left and right?
Ok better! I was already sweating
Yes I also think so!
Yes so if the node has just one audioChannelName is mono, if it has 2 it is stereo.
So the OnAudioFilterRead of the node should behave differently in the 2 cases
EDIT: Technically it could support 1, 2, 4, or more channels? It’s not possible to set the number of the channels of a single AudioSource, just of the whole project. Or I think we can try with a fake audioClip
Yeah, I’m just working on that now… give me a sec…
I’ll push what I have…
[edit] So it works fine with two channels now - From CsoundUnityNode:
public void ProcessBlock(float[] samples, int numChannels)
{
for (int i = 0; i < namedAudioChannelNames.Length; i++)
{
namedAudioChannelData[i] = csoundUnity.namedAudioChannelDataDict[namedAudioChannelNames[i]];
}
for (int i = 0, sampleIndex = 0; i < samples.Length; i += numChannels, sampleIndex++)
{
for (uint channel = 0; channel < numChannels; channel++)
{
if(namedAudioChannelNames.Length == 1)//mono
samples[i + channel] = (float)(namedAudioChannelData[0][sampleIndex] / zerodbfs);
else if (namedAudioChannelNames.Length == 2)//stereo
samples[i + channel] = (float)(namedAudioChannelData[(int)channel][sampleIndex] / zerodbfs);
}
}
}
I guess that could be:
for (uint channel = 0; channel < numChannels; channel++)
{
samples[i + channel] = (float)(namedAudioChannelData[namedAudioChannelNames.Length == 0 ? 0 : (int)channel][sampleIndex] / zerodbfs);
}
This is starting to look good now. What about the name? I think it’s technically correct, but would CsoundUnityChild
be more accessible to end users? I’m easy with either approach? I’m going to try a few more experiments here and see how this scales up!
I have some problem with the repo, now even online it shows updates until 9th of may
I’m recloning
Shit, my bad I think. If you haven’t done already, don’t reclone…
OK I cloned in a clean project
Strange, CsoundUnityNode is not even there, but when I try to push everything from my local repo it says it’s all up to date?
maybe I made too many commits!
Oh crap, I’m on the wrong branch!!
Today is not a git day