Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Audio Multiple Audio Channels to Multiple Audio Outputs

Discussion in 'Audio & Video' started by louis_unity210, Mar 20, 2018.

  1. louis_unity210

    louis_unity210

    Joined:
    Mar 20, 2018
    Posts:
    1
    Hi There,

    We are trying to establish if it is possible to have 12 audio channels / sources inside unity, each play out of a different audio output on a multi channel sound card.

    We don't want to use any kind of surround or spatialisation, we just want a specific source to come only out of a specific output.

    We are working on Windows 10.

    Can anyone shed any light on whether is is possible and how it would best be achieved?

    Thanks
    Louis
     
  2. Marald

    Marald

    Joined:
    Jan 16, 2015
    Posts:
    31
    Have you tried NAudio? It has little documentation, but it should be able to detect different output devices. So maybe you could use that for routing. It integrates into Unity quite easily by use of a plugin.

    Otherwise, you might look into the Native Audio SDK on Bitbucket from Unity and especially the teleport example. If you reverse that system, you could send audio from unity channels to an external program, which then can route to your different outputs.
    But you would need to do some heavy C++ work to get this done.
     
  3. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    936
    I've spotted this question some time ago but we got around it only recently - in the last update (not yet live on the asset store) I've added new MultichannelOutputDemo demo scene which plays a MONO clip on user selected channel of selected output device - you can test this in demo builds which are linked on the page (the plugin is linked in my signature)
    It uses FMOD Studio in more direct way (not all of its functionality) and this is done by applying a custom mix matrix to the playing channel so it can be customized in various ways -

    One note to 12 sources though: I *think* you will hit FMOD limit with how many systems are allowed to be created at any given time if you try to use them for all channels at the same time (due to how the plugin is currently designed);
    so that's a limitation which I didn't have enough time to pay attention to


    edit: One more thing for completeness: the easiest solution without (too much of) plugins and coding which would make sense would be having external SW handling channel separation (and possibly all audio) communicating with Unity usually via OSC
     
    Last edited: Apr 16, 2018
  4. pyonn

    pyonn

    Joined:
    Jun 25, 2018
    Posts:
    3
  5. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
  6. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Hello ReaktorDave, how did you manage to use Jack-Audio-For-Unity? I'm using Windows 10 and Unity 2019.4.0f1 and everytime I try the demo scenes, both Unity and Jack server crash... I tried the workaround in the repo (disabling the Randomize memory allocations (Bottom-up ASLR)) but it's not working. Thanks.
     
  7. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
    Hi danbg, I'd make sure that your samplerate and buffer size is consistent across all parts (Unity, Jack and ASIO hardware). Also, make sure that the jack version you have installed on your system matches the jack version of the Unity plugin (1.9.11). These are the most common pitfalls.

    EDIT: Have you registered the JackRouter.dll?
     
  8. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Hi, thanks for the reply. Yes, I followed the instructions in Jack Audio https://jackaudio.org/faq/jack_on_windows.html
    • Install Jack v1.9.11_64
    • Register JackRouter.dll using regsvr32 "C:\Program Files (x86)\Jack v1.9.11\64bits\JackRouter.dll"
    • Install ASIO4ALL v2.13
    • Modify Jack PortAudio shortcut using "C:\Program Files(x86)\Jack\jackd.exe" -R -S -d portaudio -d "ASIO::ASIO4ALL v2"
    • Start the Jack PortAudio shortcut (jackaudio server is running)
    • Start the Jack Contro shortcut (ASIO4ALL starts)
    My Jack Audio Connection Kit window is a bit different from the one showed on Github, but I use the same parameters:
    • Driver: portaudio
    • Samplerate: 48000
    • Frames/Period: 1024
    • In Settings > Advanced:
      • Server prefix: jackd -S
      • Everything else in default
    The only inconsistency I see is that while jackaudio uses 48000, my devices use 44000 (I also have an special mic at 16000).

    My main purpose of using jack-audio-for-unity is using multiple USB audio output devices (2x 5.1 systems and 2x 2.1 systems) and 2 different mics (optional) to reroute audio channels to different devices. Thanks again.
     
  9. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
    I'm not 100% sure but I don't think it'll work with different samplerates. Definitely try to be consistent here.

    Is the ASIO4ALL driver running at the same Buffer Size (1024) as the Jack connection kit?

    I'm also not sure if it's going to work with multiple USB output devices. Since you are using ASIO4ALL, I don't think you have a USB audio device capable of syncronization (like wordclock) so they'll drift over time causing dropouts.
     
  10. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    I tried both changing sample rate to 48000 and 44100 and buffer to 1024 and 512 to make them consistent in Unity, Jack and ASIO4ALL, but I always get the same result: Unity just closes (it doesn't even show a crash report window) along ASIO4ALL and Jack server. It happens both in playmode and also in builds. JackAudio is working in every other program but Unity.

    Maybe JackAudio is not the best way to achieve this. I know AudioStream asset, but I'd rather avoid FMOD. Maybe NAudio (not sure if https://code.google.com/archive/p/naudio-with-unity3d/ or https://github.com/WulfMarius/NAudio-Unity is the best way to use it) or even Native Audio SDK (https://bitbucket.org/Unity-Technologies/nativeaudioplugins/src/default/), but I'm not sure how to make them work in Unity to send audio to different output devices.

    I have used multiple output devices with JavaScript and browsers easily, but I wonder why it's so difficult to do it with Unity. Thanks for the help.
     
  11. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
    Weird, all demo scenes work fine here with Unity 2019.3 (not tested with 2019.4, but what are the odds). Did you modify any of the demo scenes? I remember that the Jack plugin can crash if the amount of channels in the mixer or anywhere else doesn't match the setting in the JackMultiplexer script.

    The ASIO4ALL drivers never really worked that well for me. In the context of Jack Audio for Unity, I've successfully used RME Firefaces and RME MADI FX products.

    What other programs are working with Jack Audio on your machine?
    Maybe try to access the output and input device in a different way like WDM, MME or DirectSound? You wouldn't be able to merge your output devices but this could help identify the issue.

    What is the content of your JackRouter.ini?

    Btw., the Jack for Unity plugin uses the Native Audio SDK.
     
  12. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Hi, it didn't work either in Unity 2019.3. I haven't changed anything in the scenes (I have surround 7.1 in my default speaker mode but changed also to Stereo, System Sample both in 0 and 44100, DSP buffer in Best, max virtual in 512 and max real in 32, ) I have LMMS and Ableton working nicely. I've been always using ASIO4ALL for simplicity. I made a fresh install of everything (Jack and ASIO4ALL) just to make sure it's not them. I have multiple USB and virtual devices running, so maybe something else is causing it.

    The idea is to use a simple hardware setup (that's why I'm using 5.1 and 7.1 USB sound cards, RME products go beyond budget) although I had a relatively-complex software setup with 7 Unity Builds running simultaneously, so I could use different audio devices on each one (that worked nicely). Now I want to simplify it for performance in just one Build, but audio devices are being an issue.

    I have 7 different displays with its own speakers and a 5.1 sound system in a room. Each display-speaker has its own sounds and the 5.1 the spatial common sound system. Using 7x USB 2.1 sound cards and 1x USB 5.1 does work now with multiple Builds, but I need a way to reroute the devices using just one Build, or maybe 1x USB 7.1 to reroute channels and send a mono channel to each 7.1 channel for each display, and at the same time using spatial sound in a different 5.1 sound system, even with another build or app. Jack audio is not working for me right now and I don't need to use a DAW so maybe there is an easier way to do it.

    I don't mind having an external app or server to send all my Unity audio to it, and maybe there is a way to mod Native Audio SDK to select devices. This Build is just going to play in a custom setup, so hacking around is admissible.

    Thanks again for your help. (Kommst du übrigens aus Deutschland?)
     
  13. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
    That reminds me of something. Can you disable all your audio devices except for one, make sure it is configured to only use stereo and test if a clean Unity project in play-mode will have two channels of audio per track in the mixer. If that is the case, try the Jack demo scenes again. I remember that Jack for Unity doesn't support multichannel audio, so I had to code that by myself but I didn't get to make a PR for the project, yet. Unity can sometimes lag behind your system configuration setting, so even if you have set your system audio device to stereo, Unity might still try to access it as 7.1 device.

    Also, the device that Unity is accessing for its audio pipeline (your system's default audio input and output device) and the device that Jack is accessing needs to be the same device or you'll run into issues.

    The Native Audio SDK itself has no way of sending audio streams to audio hardware.
    I have never tried this, but Jack has a built in audio-over-network feature. Maybe that would help to decouple Jack from your audio devices. I'd try testing if the crash persists if you make changes to the Jack server (try different audio devices or try the dummy driver) to isolate the problem.

    Ja, ich bin aus Deutschland ;)
     
  14. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Hallo, danke, I will try that this weekend and let you know what I achieve. I will also try it in a vanilla Windows 10 with just Jack and ASIO4ALL. No multichannel could be a problem in my use case... I will also test NAudio. There should be an easy way to do this, although after all the multidisplay's issues all those years, I guess multiple devices is not a thing Unity cares too much :(
     
  15. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
    If it turns out to be a multichannel issue, I can give you our internal version of the plugin which handles multichannel.
     
  16. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Hallo @ReaktorDave , I've been resolving some issues regarding UI these days and I couldn't format the other Windows 10 machine to try it yet. Could you send me your internal version to try it directly? Danke sehr.
     
  17. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    I managed to make Jack for Unity plugin working (not crashing automatically using just the demo scenes) using Unity 2020.1.b12, although it wasn't stable. Testing your version with my hardware would be very useful to see if this is a feasible option.

    Btw, to use Jack, ASIO4ALL, Jack for Unity and Unity (both Editor and Build) in Windows 10 did you need to run any of them as admin?
     
  18. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    121
    I sent you a PM. I'm planning to make a PR to the project, soon.

    Great - what did you do?

    What exactly do you mean by it isn't stable?
     
  19. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Hi David, that is great. I will try it. Thanks.

    To make it work I tried connecting and disconnecting some sound devices I have (including the internal sound card). It worked sometimes, but others it just crashed. The unstability comes from not being able to repeat it in a systematic way. It has been a lot of restarts and handling around, but I haven't found the exact issue. The only thing I'm nearly sure is that it has to do with the Jack setup, and not the plugin. Although my setup worked with other programs nicely.

    I've been forced to update to Unity 2020 due to multidisplay UI problems, and I'm trying to find a reliable setup for everything. I will try your version and the combination of hardware/software I plan to use in a fresh computer.
     
  20. unity_6parsam

    unity_6parsam

    Joined:
    Jul 29, 2020
    Posts:
    1
    I'm a bit late here but in case anyone is interested, Max Msp can be a viable tool for multichannel sound, especially if it's for a live thing like a performance or demo. You can set up OSC communication from Unity to Max, then do the sound stuff in Max ( this is a nice resource https://thomasfredericks.github.io/UnityOSC/ ). As far as I know you can't really bundle the max project with your unity export so this only works for some types of applications. And depending on your project this can involve alot of work in Max. Not a quick and easy solution by any means but it has worked for me before
     
unityunity