Search Unity

Selecting the audio output device

Discussion in 'Audio & Video' started by KBergauer, Mar 4, 2015.

  1. KBergauer

    KBergauer

    Joined:
    Aug 27, 2014
    Posts:
    6
    Hi everyone,

    it always infuriates me when I cannot set a game's audio output device aside from changing my system default. Is there a way to set the audio device Unity is playing to from script (using C#, native plugins or some other method) to enable players to choose a device other than their system default? I have not been able to find any Unity API methods to change the device, only the current configuration (see AudioSettings). Using basic C# I haven't been able to find anything useful yet either. I would be very thankful for any hints on how to accomplish this.

    Yours sincerely,
    KB
     
  2. KBergauer

    KBergauer

    Joined:
    Aug 27, 2014
    Posts:
    6
    Is it simply not possible to change the playback device Unity is using in any way? Games like Guild Wars 2 and programs like Media Player Classic can do it, then again that's neither Unity nor C#. I've yet to discover any way to change the audio device Unity is using. All I ever find are references on how to change Window's default audio device which is certainly not the behaviour I am looking for.

    I appreciate every hint or tip you can provide!
     
  3. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    Are you talking about the ability to have a selection screen with the different devices for your users? I know portaudio and rtaudio both have that ability for listing the devices and setting them, but to be honest, I'm not sure unity exposes that. I too would be interested as I have multiple devices as well.
     
  4. KBergauer

    KBergauer

    Joined:
    Aug 27, 2014
    Posts:
    6
    Yes, it's exactly what I'm looking to do: something like a combobox containing all possible audio devices with the ability to select one to use for Unity audio output. I will look into portaudio and rtaudio, thanks for mentioning them. Maybe they can be incorporated into Unity as a plugin.
     
  5. dshankar

    dshankar

    Joined:
    Feb 28, 2015
    Posts:
    21
    Did you find a solution?

    I need to list the audio output devices in Unity, and let the user chose which device Unity should use for audio output (i.e. NOT the default audio output device selected in Windows)

    Worst case, I assume I have to write a C++ native plugin and do some Windows API calls, and hook that up to a Unity UI in C#.
     
    forestrf likes this.
  6. P_W_Studios

    P_W_Studios

    Joined:
    May 24, 2013
    Posts:
    3
    Any word on a solution to this? There's not too much documentation out there, seems like it really hasn't been done with Unity yet??
     
  7. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,084
    Hi all,

    I did some preliminary testing with the FMOD package I'm using in AudioStream ( link in my signature ) and it seems to be correctly playing the audio on an user selected device/output present in the system.

    Note since Unity atm always outputs to system's default device, it's not possible to play on selected device (other than default) via AudioSource - meaning you'll loose all capabilities of manipulating the sound such as changing volume, pitch, spatialization, effecting etc. from the Editor/scripts - it completely sidesteps the Unity audio system.

    I'd have to also come up with some kind of Editor integration since for FMOD to report all devices/drivers the system has to be initialized first - - as a workaround the user might be able to choose the output device only in runtime for now.

    Simple playback of a single file or a stream ( which was the package originally intended for ) should work without problems.

    I'd have to allocate some time for this, but PM me if you are interested in testing and seeing whether things would work with your setup.
     
  8. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    63
    Nice @r618 !
    I'm struggling to understand how to select and initialize audio devices with low level api within unity in c#. Do you have a little reference for that?

    Thank you, Christian
     
  9. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,084
    look for setDriver call

    edit: also look for the examples for low level API which come with FMOD Studio install

    Cheers!
     
    Last edited: Aug 5, 2016
  10. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,084
    Hi,
    so if anybody is interested the new version of AudioStream got approved on the store with the ability to use any available audio output present in the system (for non AudioSource audio/streams EDIT: can handle AudioSource now, too).
    Maybe somebody will find it useful.
     
    Last edited: Jun 20, 2017
    sonofbryce likes this.
  11. babgoy77

    babgoy77

    Joined:
    May 20, 2016
    Posts:
    1
  12. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    63
    Fyi we solved the problem of "selecting audio device on linux platform" using FMod and bypassing Unity's audio system.
     
    sonofbryce and r618 like this.
  13. Taylor-Libonati

    Taylor-Libonati

    Joined:
    Jan 20, 2013
    Posts:
    15
    2018 and still don't see a solution for this in the Unity API
     
    Ony, D3m0n, horatiu665 and 1 other person like this.
  14. horatiu665

    horatiu665

    Joined:
    Nov 22, 2012
    Posts:
    12
    I'm on Unity 2018.2.12f1 and it finally works to change default audio device in windows from toolbar icon => sound output in unity changes to that device. I still don't know API that does this, but I'm happy that this basic thing finally works (it didn't use to)
     
  15. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,084
    Yes, Unity now properly responds to notifications about system default audio device changes
    but note this is something rather different than the OP was about
     
  16. khoowaikeong

    khoowaikeong

    Joined:
    Jun 13, 2013
    Posts:
    18
    does unity allow non-default device with current build? i could manually changing output in the new windows 10 mixer works, but once the app is restarted then it goes back to default device and had to be manually set again... this is very streamer unfriendly... it would be great if there is a way to make a select device in game option... :-\
     
  17. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    198
    So there is still no solution to that problem other then using a completely different api? That is somewhat sad...
     
  18. paulksi

    paulksi

    Joined:
    Nov 9, 2015
    Posts:
    25
unityunity