AudioStream - {local|remote media} → AudioSource|AudioMixer → {outputs}

Note: If you’re looking only after simple streaming of common internet sources, please have a look at AudioStreamIce which has also e.g. superior iOS integration and better playlists support.
This package also contains simple peer to peer (server/client) audio components - for more robust and scalable solution based on NetCode for GameObjects (formerly MLAPI / UNET), please have a look at AudioStreamNetCode
- so both of the above released later replace some functionality originally in this asset, while being more focused and having more features and less dependencies.

Originally the main motivation behind this asset was Unity suboptimal streaming capabilities of Unity on mobiles, especially on iOS. - the audio stream there was stored in memory in its entirety during streaming, which led to out of memory crashes after very short period of time.
UnityWebRequest also needs to download media in full before it can be processed -
these lead to poor user experience among other things so I decided to look for a proper solution. Since I couldn’t find any, this asset was made.

Apart form original streamed playback, main focus of this grew over time into more advanced streaming/downloading, accessing system audio inputs and outputs, and 3D.

Some of the capabilities:

  • AudioStream plays network streams, as well as local and remote single audio files (such as podcasts)
  • Supported are all audio formats FMOD can handle including, e.g. FLAC or modules and MIDI files
  • handles direct stream links to audio as well as M3U/8 and PLS playlists - which are common distribution format of virtually all webstreaming radio stations.
  • Uses FMOD Studio low level API for streaming, decoding and - optionally - playback and recording.
  • any available system audio output device (not just a system default one) can be used for output - this component can be used independently for any Unity AudioSource, and can target even just a specific channel of the output
  • includes ‘AudioStreamOutputDevice’ Unity AudioMixer native effect which enables redirection right from the mixer/group to user selected output device - (Windows x64 and macOS only currently)
  • supports recording/streaming from any connected input of the machine, including virtual inputs and loopback interfaces
  • support for proper 3D and ambisonic audio playback using Google Resonance libraries provided via FMOD integration
  • including any system input (but it’s possible to use any other external spatialization library)
  • supports multichannel input devices
  • on Windows ASIO support was added
  • can act as a source for Icecast server in PCM and OGGVORBIS formats.
  • streaming over LAN between two instances (1- and 2- channel OPUS encoding, using NetMQ for transport)

Tested so far on Windows, OS X ( still OS X ), iOS and Android.

AssetStore link: https://assetstore.unity.com/packages/tools/audio/audiostream-65411
(semi)current docs should be here: GitHub - r618/AudioStreamDocs: Public documentation for Unity engine asset AudioStream

There is single package with all source code included and demo scenes showing the components usage and handling of events.

NOTICE: supports FMOD Studio Unity Integrations 2.02.08 and up.

NOTICE: -* AAC format *-
there’s no special setup or any special considerations regarding this format. The ONLY actual difference compared to other formats is that the media must be played on an actual physical device (e.g. iOS/Android phone) which has hardware decoding capability for this format. That means that you will not be able to test it in e.g. Editor or standalone builds.

NOTICE: although FMOD Studio does support WebGL/WASM, this uses parts which rely on threading support, so this platform is not supported currently.

NOTE Asset Store sales: this asset is very rarely on sale

3 Likes

V 1.0 is live.

1 Like

Damn i did only find this today! Sadly spent some money on other solutions using naudio in the back… terrible performance… So found this one about 10 minutes ago : D haha Asset store is getting to big … : d Cant find what you need … hehe

Anyway. im using the 5.4 rc works fine. only thing you need to do is nuke experimental in UnityWebRequest : )

right, thanks @nrlnd
will adjust for the beta soon, haven’t looked at it yet

Unitys regular stream seams to perform better on standalone. But then again there is some weird stuff going on with 5.4.
Like… I think it has something to do with unitys editor to do., If i run both streams the minimal and standard. it’s on around 71 ish fps. If i only run minimal it’s around 71 as well. Ok now to the freaky stuff. If i run the standard stream and got it selected in the editor it runs around 157 fps. ok… If i select some other object like the camera. It drops down to 75. EH …So…I run the minimal stream. But Select the standard asset in the editor. it’s not running now. the minimal stream is up in 157. haha… If i run both streams … select the standard asset in the editor it’s up on 157. If i fold down the standard editor. not visible… the streams are back to 75 : d think this is some general freaky stuff going on in the 5.4 editor. About to kickstart 5.3.

for more consistent fps in the demo scene in the editor you can remove

[ExecuteInEditMode()]

attribute of the AudioStreamDemo script

you will loose just the nice preview in the game view while not running
apparently editor has some trouble with immediateGUI stuff always running for some reason

as for the performance compared to unity stream : there might be some unnecessary mutex locking required only for releasing the channel, i’ll look into it
AudioStreamMinimal is more performant than ‘standard’ one, but has less control, so is unfortunately not suited for all circumstances

Think this is an 5.4 issue. Fps runs fine in 5.3. Oh… And congratulations! Most important part. Your solution is capable to grab Soundcloud streams with out any issues.

1 Like

cool :slight_smile:

  • but be careful: I’m not entirely sure SoundCloud’s TOS allow streaming for 3rd party applications, but then again I haven’t studied it in detail - it might be perfectly fine

Nah thats fine using my app id and following the tos.

1 Like

V 1.1 is live

  • update for FMOD Version 1.08.09 - Strongly recommended to update, if previous version was used as it contains a bugfix related to network loss condition
  • update for Unity 5.4
  • improved startup for variable buffer lenght streams
  • improved stream loss detection and recovery
  • improved stream finishing for finite streams ( hosted files ) and locally streamed files for AudioStream component
  • improved state reporting
  • few performance improvements - AudioStream is now even more low profile

Cheers!

As mentioned in Selecting the audio output device - Unity Engine - Unity Discussions
it is possible to use other than system’s default audio output for playback.
There is a catch currently though that Unity’s AudioSource can’t be used this way - therefore it would work only for fmod’s own separate playback - i.e. no usual effects, filters, pitch changes etc. available for scripting on AudioSource/editor - working case would be simple playback of a file / stream on a chosen system device with e.g. volume change available.

I’ll probably look on how to expose this to be as simple as possible, if there is any preliminary interest please do let me know.

Cheers.

Hello,
Thank you for making this asset. I want to use it to stream ogg files on Android (not possible with Unity right now).
I’m making a small android game and I would like to keep the size small as much as possible.
So, I would like to know if adding FMOD studio will increase the size of APK a lot.

Hello @servusdei ,
I have just taken a peek into apk Unity builds with demo scene; for my phone it includes lib/armeabi-v7a and lib/x86 folders with respective fmod binaries in each, armeabi-v7a being ~ 9 MB and x86 ~ 9.7 MB in Packed size. So in total it seems fmod plugins take cca 18.7 MB compressed in the archive.
I hope that helps and best of luck with your game!

The whole apk with demo scene only is approx. 27 MB so that means the engine itself is slightly above 8 MB, which is neat.

Also note that I don’t know exactly how multiarchitecture builds are handled e.g. on the Play store - chances are that arch not corresponding to user device is stripped from the archive, similarly to the Apple’s store, but I am really not sure.

V 1.2 is live on the store

  • audio can be played on any available system output*
  • this is atm restricted to non AudioSource audio only.

Hello,
I’m interested in your plugin but I’m not sure I can do what I want with it.
I have a sound playing on the main output and I want to have a synchronisation signal played on another output every time the sound ends.
The 2 sounds have to be perfectly synchronised and for that I’m using the OnAudioFilterRead() method in Unity to check the position in my generated sound. But for now, i’m unable to play the 2 sounds on 2 different output.

If I understand, with your plugin it’s possible to change the output but only to non AudioSource audio. Does that means, I can’t use the OnAudioFilterRead() method if I want to change the output?
Is there a way to do it with your plugin ?

Thanks

Hi @rekerukuru89 ,

yep that’s unfortunately correct : OnAudioFilterRead is Unity callback and as such Unity still decides what to do with the audio/data if used directly - since it has no option to play it on non default device atm the output always ends up on the same default system device.

You can use FMOD directly for what you describe, I think:

if you know the exact length of the initial sample you you can use setDelay on a manually created fmod channel with itssystem set up to use desired output driver.

if not you can still set up fmod as described above, but play channel directly from OnAudioFilterRead instead at proper time. ( since this would invoke playback not from the main thread, unexpected issues might arise, but it should work ).

another option would be to use fmod studio events, but i have, unfortunatelly, no experience with it; moreover, since you generate the sound it’s even hard to tell overall if its feasible for this.

For the fmod to work in unity you need their Unity package and look for fmod documentation in general - their unity c# wrapper is practically one to one mapping to their c/c++ runtime.interface.

So the functionality you describe is not in my plugin atm; I’ll see whether it is feasible to make it work ‘automagically’ for AudioSource somehow, right now I’m not entirely sure, but I’ll probably do some testing.

Cheers!

Thanks for the complete answer, let me know if you find some way to make it work.
I’ll try with the fmod plugin !

1 Like

so things are looking very optimistic for an output to any present device from AudioSource:

all the usual AudioSource stuff including effects is working like it should, the component has to be last in the chain ( since it silences the original signal and reroutes it - with a necessary slight delay )

will have to actually make it seamlessly work with the streaming part and do proper demo (scene?) for it, but otherwise it seems like it could be submitted very soon!

One fmod bugreport later I’m really glad that it worked and the approach proved to be feasible.

Cheers!

( /cc @rekerukuru89 )