Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

AudioStream - an audio streaming solution for all and everywhere

Discussion in 'Assets and Asset Store' started by r618, Jun 19, 2016.

  1. Butok

    Butok

    Joined:
    Dec 6, 2017
    Posts:
    2
    I just looked over the thread and saw you answering the similar question before. Just was wondering if you added this possibility in any updates after that.
    Anyway, thanks for the reply!
     
  2. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Ah right, it never came up after that somehow; I'll have a look at it next
     
  3. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    method mentioned in this post works with AudioStream and with Unity audio in general: https://forum.unity.com/threads/how...unning-in-background-ios.319602/#post-3084784

    (this means you don't need my plugin for this to work with 'normal' Unity audio - I will mention all steps in greater detail in the documentation, but that is the general idea)

    Remote control events - i.e. control center functionality / notifications from user controlling the audio - do not currently seem to be working properly and I'm not sure it's possible with Unity audio session at all.

    note I don't have currently good solution for Android tested.
     
  4. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hello @hebi1977 ,
    this issue was resolved - contact me via PM if you want/need this sooner than update will be available on the store.
    Sorry for the delay
     
  5. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    v 1.7.2 122017 update is live:

    - checked FMOD Studio 1.10.02 compatibility
    - FMOD version used is available now and displayed in demo scenes
    - updated automatic upgradable sources for Unity 2017.2
    - added separate input gain for audio input sources
    - Fix for available recording devices on Android
    - removed editor resources to have directivity texture computed instead of being textures composed for GoogleVR 3D sound
    - new connectivity and starvation influencing advanced parameters for AudioStream* ( 'Initial Connection Retry Count' and 'Starving Retry Count' )
    - AudioStream component - will now try to mute on starvation
    - updated README, iOS/Android background audio guides
     
  6. plascu

    plascu

    Joined:
    May 31, 2017
    Posts:
    1
    Hello,

    I just wanted to confirm this could do what I need before purchasing, but it looks great. I'd like to stream audio input from my computer through an object that appears in a mobile version of the app and have the audio be positional. Will I be able to accomplish this with your plugin? Thanks!
     
  7. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi,

    For networking:
    only via Icecast currently - i.e. you will have to point all your mobile clients to a streaming server url which will stream your input audio - this part works now.
    Note that latency will be thru the roof ( very high ) this way, even though AudioStreamInput2D can be used with this.

    I'm hoping to release at least local peers / direct IP connected clients via UNET (PCM, Vorbis or Opus encoded) in couple of days hopefully -

    Do you plan to use this on general public network ? That won't probably work for some time yet on UNET - networking should go via Matchmaking in that case which I don't have ready yet.

    3D Audio:
    3D positional sources will work in general. I recommend using Google Resonance plugin for this - you just add AudioStream with proper url on Resonance enabled GO and it will get properly spatialized.

    There is support for GoogleVR/Resonance in FMOD directly too (i.e. in AudioStream, and without using separate Google Resonance/GoogleVR plugin), but needs some changes with latest version of FMOD on iOS.
    Android should work automatically when using AudioStream's own GVRSource.

    Note: GoogleVR will get deprecated eventually and be replaced by Resonance in FMOD itself, too.

    Don't hesitate to ask if you have further questions and/or if you need help setting things up as well.
     
  8. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Just addendum to the previous: I forgot to mention that you can of course use common AudioStream/AudioSource with 3D spatial blend enabled - you'd get Unity - horizontal + doppler - spatialization this way on client/s.
     
  9. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    when a stream ends, I get errors like
    Code (CSharp):
    1. [ERROR][2017-12-19T09:21:02] [PCMReaderCallback] ERR_FILE_EOF - End of file unexpectedly reached while trying to read essential data (truncated?).
    2.  
    I'm streaming files from s3 buckets with signed urls, but this worked before without error. Actually, I'm not sure if anything is really broken (it does play, and will replay after barfing a bunch of these errors), or if it's just spamming the console. Happens on mobiles and standalone. Using the latest 1.7.2 and fmod 1.10.2. Any ideas? For now I'm going to just suppress that error...
     
  10. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    at first glance I'd say that it is harmless and is safe to ignore it - I'll make some testing to see if it's possible to ignore it altogether - it's definitely not nice
    the cause might be that fmod changed error reporting meanwhile, but it's definitely harmless when playback is ending
     
  11. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    Thanks! I'm just filtering out 'truncated' errors....
     
  12. Chemeleon

    Chemeleon

    Joined:
    Feb 5, 2014
    Posts:
    2
    I need to be able to play audio via a byte array received over a socket, but haven't been able to find anything definitive on if AudioStream can handle this or not. Does it support that, and if so, can it do so spatially when using oculus?
     
  13. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi, in the next update in the form of local direct IP peers via UNET (so no .NET sockets as such) - you could change the implementation for .NET sockets, but I will not provide it most likely.
    I use encoding, but I guess I might include just PCM exchange.

    As for Oculus - in general yes these are independent systems, i.e. AudioStream just provides audio data for Unity/Oculus - you can spatialize either at source (server), or on clients.
     
    Last edited: Jan 18, 2018
  14. m_mov_sia3

    m_mov_sia3

    Joined:
    Apr 28, 2013
    Posts:
    3
    hi r618
    we wanna test your unitypackage for playing stream music in our game
    but fast response is so important to us. can you give a trial or demo of your plugin before purchase?
    thanks in advance
     
  15. Chemeleon

    Chemeleon

    Joined:
    Feb 5, 2014
    Posts:
    2
    So there's no way to just feed raw byte array audio data to it? In my case I'm trying to get audio going between Unity and a non-unity app (winforms atm, probably would change in the future) so I don't think UNET is likely to work for me.
     
  16. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Yes and no.
    It can accept and play arbitrary raw audio data when properly setup. You can provide this data e.g. to an Ice/Shoutcast instance and then point AudioStream to the stream link. ( Effectively you just chose proper - in this case RAW - codec for the stream if you don't encode it )
    The other way you can make it to push the audio to an Icecast (and consume Icecast stream in whatever way you see fit).

    But AudioStream doesn't act as generic standalone audio server which would accept any arbitrary connection and send/receive audio (in unknown format).
     
  17. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    About to submit 1.7.3 with changelog:

    - AudioStream: fix for redundant buffer allocation (should fix playback with Best Latency setting)
    - AudioStream/Minimal: improved playback finishing for finite files
    - fixed spatializers demo scenes to be audible
    - AudioSourceOutputDevice: availability bugfix
    - AudioSourceOutputDevice: reduced latency and increased buffer availability to play more nicely with other packages such as AVPro
    - AudioStreamInput/2D: exposed dsp buffer size and count for better latency adjusting
    - AudioSourceOutpuDevice: exposed dsp buffer size and count for better latency adjusting
    - more and hopefully more explanatory comments throughout the code and README
    - new components for distributed LAN audio playback using Opus codec and using UNET at the moment: AudioStreamUNETSource and AudioStreamUNETClient

    So, plethora a fix and LAN audio finally !
    Networking is currently built on top of UNET LLAPI since it was easier to start with, and clients need IP address to connect to (auto discovery coming later).
    UNET network processing is tied to framerate ( needs to be on main thread ) - so that would be main drawback - but I found it to be rather reliable so far, mobile platforms included (although those need to adjust the update loop for some reason).

    Audio processing and networking are conceptually split however and open for possible plain .NET TCP sockets implementation in the future.

    ( Now that I'm thinking about it UnityEvents notifications are probably missing currently, so those will come later, everything should be automatic enough, though )
     
  18. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Forgot to mention: latency of network exchange is acceptable for realtime so you can e.g. distribute multichannel (*) microphone input to many clients. Was a pain to work everything out but it should be hopefully worth it.

    (*) well 1, or 2 - those are permitted for the encoder currently.
     
  19. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Thanks to very quick review the update is live already ~
     
  20. victor_unity813

    victor_unity813

    Joined:
    Oct 20, 2017
    Posts:
    1
    Hi r618,

    This seems like a really powerful tool. However, I'm curious if it supports multiple audio listeners for separate audio outputs?
    I'm working on an asynchronous local VR multiplayer game, and I need separate audio listeners for each player as well as separate audio outputs for each listener, so the person in VR gets their own audio and the person using the computer display has their own audio on their respective devices.

    Cheers!
     
  21. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi @victor_unity813
    you'd have to research multiple audio listeners separately - I know it's 'kind of' possible, but never worked with such setup (or needed one, for that matter).
    (AudioStream plugs into Unity audio where possible (i.e. except one separate component - AudioStreamMinimal), so any setup you will come up you can use AudioStream with in a scene)

    That being said I'm not entirely sure you need multiple listeners actually -

    If I understood the question correctly - you have one scene which is shared with both the players right

    In that case the spatialization you use should be able to position the audio relative to each player transform/camera and you should then be able to use AudioStreamOutputDevice to direct each respective properly positioned audio source to different system output.
    - you might need two spatializer instances (and/or audio sources) - one for each player
    - you'd have to setup each spatial source to be relative to each players camera and one of them would never reach current AudioListener in the scene ( since it gets sent to different system output above )

    I'm not sure this setup will work - you'd have to try it out practically with spatialization first, then possibly redirect one output with AudioStreamOutputDevice.

    That's probably all I can think of right now - let me know if you have further questions
     
  22. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    126
    Just checking back in to say I did manage to get 2-channel microphone input working using this asset. The developer was very helpful and I highly recommend this asset. I have to say Unity audio in general is not for the neophyte. The terminology is pretty non-standard and it gets worse from there, however given time it can be made to work. This asset is a great starting point and reference for a complex audio project.
     
    r618 likes this.
  23. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Thanks, Med, and thanks for stopping by !

    Just FYI (if you didn't happen to know, and to clarify things) - there's also AudioMixer https://docs.unity3d.com/Manual/AudioMixer.html - with more 'industry familiar' concepts, UX and terminology, but has one drawback currently in that it can come into play only *after* the signal has been acquired / which is where you used AudioStream ( and I'm glad successfully at that !) /

    It is possible to customize AudioMixer in more direct and straightforward way, the work involved is (much) more substantial too, however ( I would have to essentially replicate all current functionality in a native plugin, per platform ), while having all functionality ( except FMOD bits ) in user scripts allowed me to simply don't care about any platform issues (and also allowed the usage of common AudioSource user script functionality such as access to signal/spectrum buffers, for example).

    That has its downside though in that AudioStream is more scripting oriented and currently not necessarily aimed at beginner user as you pointed out.
     
  24. Ecocide

    Ecocide

    Joined:
    Aug 4, 2011
    Posts:
    292
    Hi r618,

    today I purchased AudioStream. Could you tell me if I would be able to achieve the following:

    We are running our software on machines that are always equipped with headphones and also an Oculus Rift (and its headphones). We want to make sure a user can switch between audio output devices in the Unity application. Unfortunately this does not seem to be possible with Unity out of the box and that's why I purchased your asset today. I tried the demo scene "OutputDeviceDemo", but the sine sound is not playing very well. Lots of cracks and pauses between and the pitch is also wrong. And when clicking on play, it always takes some time to start which I assume is the latency you mentioned in the readme? If so, I can probably not use it for car sound for example.

    My idea was to add the output script to all audio sources in the scene and then change the output drive ID as I need to change the output device from speaker to headphones etc.
     
  25. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi, I will make sure to take a look properly later today - meanwhile please have a look as DSP Buffer Size in Audio Settings of Unity - try to run the scene with different size settings -,
    buffer size and count ( potentially connected to the issues you experience ) for native part of AudioStream are also set via 'DSP Buffer Size' and 'DSP buffer Count' of AudioSourceOutpuDevices component itself
    (I had it originally working with 64/2, but that wouldn't produce error free results on macOS, for example, the defaults should be currently 128/4 which seem to be ok on mac and depending on your platform/sound drivers might need adjustment, too).

    As for your intended setup - yes, that should work. The only concern I have is about total count of audio sources involved which would need redirection - you might hit some limit with 10 or so currently - let me know if you hit it and need more - I'd have to provide an update for that.
     
  26. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    @Ecocide I've just tested the demo scene on a new windows machine, everything seems to be in order ( with all Unity AudioManager DSP buffer settings as well )

    Do the discrepancies happen on the Oculus output only ? I think there's a bug with selecting wrong samplerate ( would explain also wrong pitch you're getting ) - I *thought* this was fixed some time ago, but well :/

    Since I unfortunately don't have any Oculus device here you might want to try modify source until I update this.
    Please PM me for instructions and to iterate if possible.
    Thank you, and apologies for the troubles.
     
  27. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Just an update to previous if anyone's interested -

    currently there's no easy way of switching to different output if device characteristics of Unity default output differ from desired/redirected output device significantly, e.g. in speaker setup.

    It is enough to set correct speaker setup in Unity's AudioManager to match the (desired) output, though.

    This implies that all involved devices would have to have the same speaker setup, though - unless you setup Unity's output at runtime via AudioSettings.Reset(AudioConfiguration config) - ( which should work, although I haven't tested it for speaker setup change thoroughly )

    As I've realized 2018/beta/+ should at least pick up default device change at runtime, which might help to determine device changes and possibly speaker setup.
    AudioStream configures its output dynamically, so for it the correct device id should be all that's needed.
     
  28. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,396
    I found on this thread from a couple of years ago that:

    However, this is not the case in the current version of AudioStream. I can switch the computer's primary audio output device all day and the only time AudioStream will not change output devices. The only time it changes output devices is if the device it's using gets disconnected.

    Do you know how we would get our desired behavior (e.g. to always use the system's primary output device)?

    PS: In other things I've tried, I also do not get any callbacks from the following code. (The lack of sample code online makes it tough to know where to start) Start() is being executed, but ChangeDeviceList is never called when I connect or disconnect devices.
    Code (csharp):
    1.  
    2. public class AudioSourceTest : MonoBehaviour {
    3.     FMOD.System system;
    4.     public void Start () {
    5.         FMOD.Factory.System_Create (out system);
    6.         system.setCallback(ChangeDeviceList, SYSTEM_CALLBACK_TYPE.DEVICELISTCHANGED);
    7.         QuickLog.Log ("System created");
    8.  
    9.      
    10.     }
    11.  
    12.     public RESULT ChangeDeviceList(IntPtr systemraw, SYSTEM_CALLBACK_TYPE type, IntPtr commanddata1, IntPtr commanddata2, IntPtr userdata) {
    13.         QuickLog.Log("ChangeDeviceList({0}, {1}, {2}, {3}, {4}, {5})", systemraw, type, commanddata1, commanddata2, userdata);
    14.         return RESULT.OK;
    15.     }
    16.  
    17. }
     
  29. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi @StarManta ,
    the redirection - or playing Unity AudioSource / AudioStreamMinimal source on other than default audio output - is still there all along - nothing has changed since the time the post you cited was written.

    The system devices change notification is different thing - I will test later to see if I can get it working with FMOD Unity Integrations - but yes the idea is roughly the same as you tried, but I think you have to call System.Init, too.

    What you're observing is but correct / standard behaviour - the default output device is always the first one ( index 0 ) and device list will change when physically unplugged or due to manual / software default device change (i.e. setting default output in playback devices properties ) while when the latter FMOD keeps the opened device even when it changes its index/ID after it was opened ( you'd have to close and reopen again with 0 after the change to play on new default).
     
  30. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077

    this is complete script using FMOD callback for detecting when audio devices get enabled/disabled

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public class DeviceListChangedNotification : MonoBehaviour
    5. {
    6.     FMOD.System system;
    7.     FMOD.RESULT result = FMOD.RESULT.OK;
    8.     IntPtr extradriverdata = IntPtr.Zero;
    9.  
    10.     FMOD.SYSTEM_CALLBACK devicesChangedNotification;
    11.  
    12.     void Start()
    13.     {
    14.         result = FMOD.Factory.System_Create(out system);
    15.         ERRCHECK(result, "Factory.System_Create");
    16.  
    17.         result = system.init(10, FMOD.INITFLAGS.NORMAL, extradriverdata);
    18.         ERRCHECK(result, "system.init");
    19.  
    20.         // device change notification handler
    21.         this.devicesChangedNotification = new FMOD.SYSTEM_CALLBACK(this.DevicesChangedNotificationCallback);
    22.         result = system.setCallback(this.devicesChangedNotification, FMOD.SYSTEM_CALLBACK_TYPE.DEVICELISTCHANGED | FMOD.SYSTEM_CALLBACK_TYPE.DEVICELOST);
    23.     }
    24.  
    25.     FMOD.RESULT DevicesChangedNotificationCallback(IntPtr systemraw, FMOD.SYSTEM_CALLBACK_TYPE type, IntPtr commanddata1, IntPtr commanddata2, IntPtr userdata)
    26.     {
    27.         Debug.LogFormat("ChangeDeviceList({0}, {1}, {2}, {3}, {4})", systemraw, type, commanddata1, commanddata2, userdata);
    28.         return FMOD.RESULT.OK;
    29.     }
    30.  
    31.     void Update()
    32.     {
    33.         if (system.hasHandle())
    34.         {
    35.             result = system.update();
    36.             ERRCHECK(result, "system.update", false);
    37.         }
    38.     }
    39.  
    40.     void OnDisable()
    41.     {
    42.         if (system.hasHandle())
    43.         {
    44.             result = system.close();
    45.             ERRCHECK(result, "system.close", false);
    46.  
    47.             result = system.release();
    48.             ERRCHECK(result, "system.release", false);
    49.  
    50.             system.clearHandle();
    51.         }
    52.     }
    53.  
    54.     public void ERRCHECK(FMOD.RESULT result, string customMessage, bool throwOnError = true)
    55.     {
    56.         if (result != FMOD.RESULT.OK)
    57.         {
    58.             var m = string.Format("{0} {1} - {2}", customMessage, result, FMOD.Error.String(result));
    59.  
    60.             if (throwOnError)
    61.                 throw new Exception(m);
    62.             else
    63.                 Debug.LogError(m);
    64.         }
    65.     }
    66. }
    just attach it to any game object and try to enable/disable any audio output;
    note I didn't properly test removing and physically unplugging a device from the system, but it should work the same; if not let me know
    (it's good to check for returned error codes in general, and system should be updated continuously)

    Unfortunately there does not seem to be any notification type when the default device is changed
    (FMOD generally does not care about this, only about the device index as described earlier)

    Unity might have something up to its sleeve according to https://issuetracker.unity3d.com/is...hange-audio-output-device-in-editor-and-build - so that might help with default device change detection if/when the issue is resolved
     
  31. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,396
    If there's no notification, is there at least a way to find out what the primary audio device is via polling, and switch to it then? I assume it has to be possible somehow, since it does correctly set the output to the primary audio device on startup.
     
  32. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Listen to a change in the device list with the above method and remember - the default device always sits at index 0 - so I'd compare some of its characteristics such as name and simply restart on new default if needed.
    Let me know if this makes sense, or if you have troubles making it work.
    You can have a look at AvailableOutputs method used in several places on how to query current device list.
     
  33. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,396
    I have the system set up now to detect when the device changes, and this seems to work (at least most of the time) - this is the main part I'm having trouble with now. How do I restart the audio system as a whole? Or do I need to loop through every AudioStream object and restart each one?
     
  34. tengkufathullah

    tengkufathullah

    Joined:
    Apr 3, 2017
    Posts:
    14
    Hi I just buy your plugin, Is it possible for the audio stream to be able to seek? I have no issue for seeking the mp3 that already downloaded, but is it possible for streaming ? like spotify where we can drag the slider for audio playback.
     
  35. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Yes, you should stop/play on each AudioStream separately as needed - each uses its own FMOD instance currently and there's no central manager for this.
    I understand that might not be ideal - I was trying to keep things as simple as possible since start, but this allows you e.g. having different AudioStream instances streaming to different outputs - which would be harder to manage centrally.
    I understand that user has to do more work to customize everything though.

    Hope that makes sense!

    I am curious about this though:
    mainly the (at least most of the time) part -
    enabled/disabled notification is probably not enough to capture all relevant state changes in the system - I'd maybe try querying available devices continuously in Update ( the call shouldn't be too expensive ) and acting based on that, skipping the notification setup entirely.
    ( I'm not _entirely_ sure it would be hassle free, but it is an option worth to test )

    Please let me know if there's something I can help with still

    Thanks!
     
    Last edited: Feb 22, 2018
  36. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi Tengku,
    this is unfortunately not possible currently -
    ( note also the description on the Asset Store:
    "being streaming oriented it does not provide typical offline audio processing such as advanced clip offline signal manipulation or selective time precise playback." )

    You got errors when trying to set clip's time since internally that clip has just very small looping buffer just for immediate playback.

    I might look into it in time - maybe small range seeking wold be possible for AudioSource variant.
     
    tengkufathullah likes this.
  37. tengkufathullah

    tengkufathullah

    Joined:
    Apr 3, 2017
    Posts:
    14
    I see, I am really sorry that i miss that note, since I don't really understand "selective time precise playback", Is it possible to get refund ? because that the main purpose for us to buy the plugin.
     
  38. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    No problem - just PM Asset Store invoice no.
    I'll look into it as time permits, so watch updates, it might appear some day :)
    Cheers
     
  39. tengkufathullah

    tengkufathullah

    Joined:
    Apr 3, 2017
    Posts:
    14
    Wow, thanks a lot. This is the order no : 18966691218373 ,
    Date: 2018-02-22 04:36:38 (UTC), I will keep on eye on your plugin. All the best
     
  40. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,396
    I've been trying to get this to work for several days now and have only come across more and more frustrations as nothing seems to work.... at least, not on AudioStreamBase.

    For context on the following code: AudioManager.checkFmodResult is basically the same as ERRCHECK, QuickLog is our own logging system similar to Debug.LogFormat, and EpisodePlayer.Instance.moviePlayer.audioSource is the AudioStreamBase-derived class. Notifications when the device changes works. The class at the top of it is probably not relevant as that part of it, as far as I consider it, works fine. It's in the ResetToPrimaryDevice method where I have problems.

    The issue is in the ResetToPrimaryDevice method included in the code below. It's important to note that this is just one of literally dozens of permutations of this method, including one that was basically just Stop() then Play(), with and without setDriver calls, and there was one where I reached deeper into the class and manipulated the FMOD channel directly. But no matter what I do, it will. not. pick up on the new primary output device, and I am at my wit's end.

    Code (csharp):
    1.  public class AudioOutputDeviceMonitor : MonoBehaviour
    2. {
    3.     FMOD.System system {
    4.         get {
    5.             return AudioManager.instance.interactiveSoundSystem;
    6.         }
    7.     }
    8.  
    9.     private System.Guid lastDriverGuid;
    10.  
    11.     void Update()
    12.     {
    13.         if (system.hasHandle())
    14.         {
    15.             AudioManager.checkFmodResult( system.update() , this);
    16.  
    17.             System.Guid guid = new Guid();
    18.             FMOD.SPEAKERMODE spmode = new FMOD.SPEAKERMODE();
    19.             int srate, spmodechan;
    20.             Profiler.BeginSample ("getDriverInfo");
    21.             AudioManager.checkFmodResult( system.getDriverInfo (0, out guid, out srate, out spmode, out spmodechan) , this);
    22.             if (lastDriverGuid == null || guid != lastDriverGuid) {
    23.                 PlaySoundAction[] allPSA = FindObjectsOfType<PlaySoundAction> ();
    24.  
    25.                 QuickLog.Log ("Audio driver changed from GUID {0} to {1} - reinitializing {2} sounds to pick up the new device.", lastDriverGuid, guid, allPSA.Length);
    26.                 EpisodePlayer.Instance.moviePlayer.audioSource.ResetToPrimaryDevice ();
    27.  
    28.                 foreach (var psa in allPSA) {
    29.                     psa.ResetToPrimaryDevice ();
    30.                 }
    31.                 AudioManager.checkFmodResult( system.setDriver(0) , this);
    32.                 lastDriverGuid = guid;
    33.             }
    34.             Profiler.EndSample ();
    35.         }
    36.     }
    37.  
    38. }
    39.  
    40. // The problematic function
    41.         public void ResetToPrimaryDevice() {
    42.             QuickLog.Log ("AudioStreamSeekable.ResetToPrimaryDevice()", this);
    43.             if (system.hasHandle ()) {
    44.                 AudioManager.checkFmodResult (system.close (), this);
    45.                 AudioManager.checkFmodResult (system.release (), this);
    46.                 system.clearHandle ();
    47.                 system.init (10, FMOD.INITFLAGS.NORMAL, System.IntPtr.Zero);
    48.             }
    49.         }

    Any help you can give at this point would be appreciated.
     
  41. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi @StarManta ,

    the approach is sound, FMOD but needs more nudging to pick up the change -
    I've used AudioStream/Minimal OnDisable and Start() to reinitialize completely ( Init is apparently not enough )

    tested on the basic AudioStreamDemo scene with just this Update method added:

    Code (CSharp):
    1.     void Update()
    2.     {
    3.         if (this.audioStreams[0].ready && this.audioStreams[1].ready)
    4.         {
    5.             this.availableOutputs = this.audioStreams[0].AvailableOutputs();
    6.  
    7.             if (this.defaultDeviceName != this.availableOutputs[0])
    8.             {
    9.                 this.defaultDeviceName = this.availableOutputs[0];
    10.  
    11.                 Debug.LogFormat("Detected default device change to: {0}", this.defaultDeviceName);
    12.  
    13.                 foreach (var _as in this.audioStreams)
    14.                 {
    15.                     _as.playOnStart = true;
    16.                     _as.OnDisable();
    17.                     StartCoroutine(_as.Start());
    18.                 }
    19.             }
    20.         }
    21.     }
    22.  
    ( all it took was to change OnDisable and Start base and derived signatures to be public, and set playOnStart to start again automatically - you might want to play with this, but hopefully you get the idea)

    It then reacts to any device list change as it should
    (note it will pick up whatever (output) device ID is set on each component respectively, which is 0 by default, so it will always pick the default if not changed)
    ( This startup/teardown is probably worth refactoring to separate public methods )

    Hope this helps - let me know if you manage to make this work!
    Thanks :)
     
    Last edited: Feb 27, 2018
  42. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,396
    Still having trouble. Now, when I switch outputs, the sound stops entirely, and I get
    Code (csharp):
    1.  
    2. MovieScreen [ERROR][2018-02-27T12:02:45] In startup - will not Play again.
    3.  
    Looking at the component in the inspector shows that inStartup is stuck at "true" indefinitely. Also, outputting the value of inStartup at the top of Play() shows that the first time it's being called (from this code), inStartup is false, so somewhere within Play(), it's failing silently and not resetting inStartup. (the second time it's called is from our other code trying to restart it and sync to its own time, and is relevant only in that it revealed that inStartup was getting stuck)
     
  43. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Would it be possible to set Log Level to 'DEBUG' on relevant component and send me the log ?
    (you can e.g. 'Open Editor Log' from Console context menu) - I think I can see a bug in error handling.

    ( btw the 'In startup - will not Play again.' error message should probably be just informative since it's meant as such and should not signal error condition - I'll fix that )
    I was getting it too while testing - it takes some time to start playback and if checked esp. from Update the 'isPlaying' flag is not yet set.
     
  44. hellowill89

    hellowill89

    Joined:
    Jan 8, 2013
    Posts:
    42
    When I use audioStreamInput.AvailableInputNames(), I only get the microphone. Is there a way to get the system audio on Android using AudioStream?
     
  45. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Are you trying to capture system audio output ? That works - after necessary setup - only on desktops, mobile operating systems - deliberately - don't support that.
    (Due to how audio drivers are currently implemented there)
     
    Last edited: Mar 14, 2018
  46. jessekirbs

    jessekirbs

    Joined:
    Apr 4, 2014
    Posts:
    16
    Martin,

    Very interested in the plugin. I'm trying to stream live audio input into Unity from a DAW (Ableton, Pro Tools etc.) and have it appear as a spatialized audio source in Unity using the Google Resonance plugin or something similar. Is this possible with your asset? What kind of latency can I expect in this case? Thanks so much.
     
  47. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Hi @jessekirbs - technically it's possible, although I've never tested this:
    - have listening enabled on your sound card ( https://forum.unity.com/threads/aud...all-and-everywhere.412029/page-3#post-3120495 )
    - have AudioStreamInput* point to this system output with google resonance component enabled

    As for latency - it's hard to tell - it should be better than using Unity's own spatializer though

    I'll look into building a testing scene like this and make a demo build in 2018.1 which should be released on GDC - it'll take a couple of days. / 2018.1 supports desktop il2cpp builds /

    Just a note about spatializers: FMOD itself includes its own version of Google Resonance for now (which is currently being used in one of the demo scene ( not with input )) and it is different from the one unity provides.
    Unity's solution requires google resonance package to be imported separately (same for oculus) so that's one of the reasons I'm not building on top of those
    It's not hard to setup AudioSource using either of them and add AudioStream component if needed though.
    Hope this helps.
     
  48. rekka3000

    rekka3000

    Joined:
    Feb 9, 2014
    Posts:
    46
    Bought this plugin today, love the demo scenes.

    Mainly interested in using the plugin to route audio to different hardware devices. However, I can’t for the life of me figure out how to route audio clips in the timeline to different devices. Looking at the demo scenes it works with audio sources but can’t figure out how how to get it working with timeline based audio stuff. Any help would be appreciated!
     
  49. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,077
    Thank you @rekka3000, it's always very enjoyable when user likes your stuff !

    Now for the timeline: I haven't touched it yet, but from quick glance it'd say this might be.. complicated -
    although it should be possible to write a custom Playable, AudioStream uses an AudioClip as a very small looping buffer only for immediate playback so this would probably never work with Timeline currently anyway.

    But the redirection component you're trying to use is quite independent of this - it should be possible to write a custom playable, having AudioSourceOutputDevice with desired output ID attached in the scene and having its AutoStart on (to leave the redirection running regardless of current audio output), but you'd have to customize / figure out when to call AudioSource.Play() / Stop() in it - i.e. respond to Timeline changes in custom playable (including e.g. audio position changes probably and so on... )

    Have a look at output device demo scene - audioclip and redirection are decoupled and driven independently there - I'd say you might at least more easily get partial support for this - i.e. invoke an event from timeline where you'd handle at least starting/stopping the playback on requested output set on component.

    Let me know it this makes sense.
     
  50. rekka3000

    rekka3000

    Joined:
    Feb 9, 2014
    Posts:
    46
    Thanks for the awesome quick and detailed response!

    As you say, I’d really want the ability to scrub through the audio track on the timeline (in 2018.2 you’ll be able to scrub through in real-time without playing but currently it’s only able to be scrubbed through while playing the scene).

    Partial support basically means setting a trigger on the timeline and this trigger would tell the audio source clip or something to play the track. It’s workable but not really what I want to do...

    What I’m trying to do is use the timeline to sync playback of a music file and an SMPTE LTE sound file that can be used to sync external devices and hardware (real stage lighting etc)

    LTC i would want to come out of one output device on my pc (mini jack) to lighting hardware and music come out of my monitor (for example) via HDMI.

    So far I’m doing this with virtual audio cable and sending SMPTE LTC audio in the left channel and music in the right channel and balancing it later but it’s complicated and messy.

    Doing what you’re suggesting would require more programming experience I think than I’m comfortable with. Do you think you’d be able to take a look at integrating timeline support? It’s probably something people would love to have.
     
unityunity