Hi. I am sorry if this has been asked before. But I have a unity project that requires around 16 channels of audio playing through premixed multi channel WAVs and I know unity out of the box only supports 8. I was wondering if using Csound would get around this and open up the 16 channels I need?
Unity channel limit with Csound
I don’t think anyone has asked this before, but it should be possible. The only thing is that you would have to use Csound as your main audio IO module, and more or less disable all audio output in Unity. Would that work for you? What OS are you on? Oh, and this would be restricted to desktop applications for now.
I am developing on Mac but the app is going to run on PC. Would I still be able to trigger audio in unity? Don’t mind it not playing audio. I just need a simple way of managing all of the many sounds and music files and set up trigger points in my code in unity to play them?
This shouldn’t be a problem. I can put together a simple project tomorrow and see how well this might work. I only have a stereo card, but if it works Ok in stereo it should work fine in multichannel.
That sounds amazing. I have a guy coming up to see me on Tuesday with his multi channel kit so I’ll let you know how it works. Thank you so much.
Cool. I’ll let you know how it goes!
Here you go. This should work fine. You can now bypass Unity’s audio and use Csound to output to whatever card you want. But you more or less have to give up on using Unity’s spatial audio components because the AudioSource that Csound is set up on is muted. You can trigger clips to play and things like that, but spatalisation ill have to be taken care of in Csound. I’m not sure how familiar you are with the Csound language. These things are not tricky, but it really depends on your level of knowledge.
Regarding this package. There is a simple scene in which a cube is attached a CsoundUnity component. CsoundUnity components required an AudioSource component. In its AudioFilterRead method it get Csound to process blocks of audio. Csound then outputs that audio directly to a device. Looks in CsoundScripts folder for the simple .csd file that is taking care of the Csound behaviour. You would be as well off installing Csound yourself in advance of trying this, as it’s no harm in having a system wide install of it. You’ll need to figure out what sound card to output on and then using that number with the -odac
flag in the CsOptions.
If the fact that Unity’s spatial stuff will be rendered useless isn’t a deal breaker, then I think this could work nicely.
amazing, ill take a look now, basically like you have just said I don’t need to use Unity’s spatial stuff so really this sounds like it could work well, never used or looked at Csound before so ill grab it now and see whats what, sounds very interesting for sure though.
ill hit you up with any questions if thats alright? many many thanks again, Stu
link doesn’t work
Sorry about that, should be Ok now.
amazing, checking it now, thanks so much
hi Rory, so I have taken a look at this, the confusing thing is that its still using the Unity Audio Source component, so I was unsure how it was working at first, but I think I see what its doing now. The problem I have though now is the problem I kind of had anyway, in that I can not even get the sound over to the Csound script as Unity will not entertain even processing the file in the first place so I can not assign the sound to play, here is an example of a 32 channel audio file https://www.lynxstudio.com/downloads/aurora-n/sample-wav-file-zip-encoded-96khz-pcm-24-32-channels-rf64/
thanks again for all the help so far
In this case there AudioSource is there merely to schedule blocks of audio to be processed. The output of the AudioSource is muted. You;ll see this in the OnAudioFilterRead() method.
Ah, I get it now. So in this case you have two options. 1) Continue to use an AudioSource components, merely to schedule blocks of audio to be sent to Csound, or 2) set up a performance thread to run an instance of Csound. 1 can be implemented without any changes to the current scripts. 2 would involve a little bit of a rewrite of the C# stuff and how Csound is called. But reading multichannel audio is simple in Csound. This little bit of code will read all 32 channels of that file, and output the first two:
instr 1
aSignal[] diskin2 "C:\\Users\\rory\\Downloads\\32ch-96000-rf64\\32ch-96000-rf64.wav", 1, 0, 1
outs aSignal[20], aSignal[21]
endin
Btw, I assume these aren’t one-shot samples you’re looking to fire off in quick succession? I imagine performance might be a little sluggish if you’re using 32 channels of audio for a single gunshot for example!
I’m just looking into preparing another simple example for you using option 2 from my previous post. But I’m having problems adding that multichannel file anywhere to my Unity project folder. On my Windows machine it eventually did allow me to add the file, although it reported that it was not supported. On my OSX machine it just seems to hang. This presents a bit of an issue. What is the project you’re working on. If it is an installation, once off kind of thing, then we can use absolute paths to the files but if you need the scene to be able to run on any PC it might be tricky. My OSX machine is pretty old at this point so it might just take a while before Unity imported the audio.
I’ll leave it running while I grab lunch. Hopefully it will have imported when i get back.
hi Rory, yeah its for an installation, I have managed to now get a MaxMSP patch working, so I can send OSC signals over to trigger sounds in that, not ideal but its a working solution so far. But yeah thats the issue I was having where Unity would not process the file in the first place. But I have total control over all of the content so I could put it anywhere if that helped
Ok, try the link again. I just updated the package. The approach this time is to put all multichannel sound files into the streaming assets folder. I’ve updated the Csound file (in CsoundScripts) to read all channels of that sample file and output channels 1 and 2. I don’t have a multichannel card so I can’t test it with more, but it should work.
I’m still using an AudioSource component with the CsoundUnity script, just to schedule Csound to process its blocks of audio. I was going to set up a second thread for this, but this way should work just fine and involves less work.
Exporting the game will still work fine here as CsoundUnity will still provide the correct paths to Csound for all the files. Also note that you can manipulate the channels any way you wish by sending channel message to your Csound instrument. So if you need to control the amplitude of any channel you can easily do so from Unity.
Sorry for the slow reply. Had a hectic week. Thanks for this. Going to try it out this weekend. Sounds ace
Hi Rory,
I’m currently looking into doing the same as Creativewax for an interactive installation where we want to use Unity and 16 channel sound.
The only difference will be that we will have several mono sounds that we will be routing with csound to different channels dynamically.
Could you please kindly sent me the example above project for outputing audio only through CSound?
Thank you.
I’ll have to have a dig around for it. I didn’t realise I removed it from my Dropbox folder. Leave it with me. Maybe @Creativewax have a copy lying around that he could post? I’ll try to find one regardless.
Just to be clear, you’re looking to output 16 channels of audio to your soundcard from Unity?
Yes, exactly.
Thank you!
But if you don’t find it, no worries - I’ll try to go with the csound6net wrapper directly.