Cabbage Logo
Back to Cabbage Site

Unity channel limit with Csound

Just grab the latest CsoundUnity source and then update the processBlock method so that it looks like this:

public void processBlock(float[] samples, int numChannels)
{
    if (compiledOk)
    {
        for (int i = 0; i < samples.Length; i += numChannels, ksmpsIndex++)
        {
            for (int channel = 0; channel < numChannels; channel++)
            {
                    if ((ksmpsIndex >= ksmps) && (ksmps > 0))
                    {
                        performKsmps();
                        ksmpsIndex = 0;
                    }

                    if (processClipAudio)
                    {
                        setInputSample(ksmpsIndex * numChannels + channel, samples[i + channel]);
                    }

                    samples[i + channel] = 0.0f;//(float)(getOutputSample(ksmpsIndex, channel) / zerdbfs);
            }
        }
    }
}

Don’t forget to add a -odac to your CsOptions section. You may also need to specify the device. For example, on OSX I have to do:

-+rtaudio=coreaudio -odac1

After that you should be up and running. Don’t output any sound with Unity or you might have issues. Let me know if you have any problems.

thank you!