Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Audio iOS: How to get audio data generated in Unity

Discussion in 'Audio & Video' started by maweibezahn, Jul 25, 2022.

  1. maweibezahn

    maweibezahn

    Joined:
    May 17, 2022
    Posts:
    2
    Hi,

    we are working on an audio app in Unity which targets, among other platforms, iOS devices (and macOS later). For iOS, we are using the "Unity as a library"-approach, so we have a native app part which is written in Swift.

    Everything works great, except for one feature we would really like to implement but can't find out how.
    We want to send the audio data generated with our app to another app ("inter-app audio"). To do so, we of course need access to that data (and then feed it into an AVAudioUnit in our native iOS app). But we can not find any information about where to grab that data. It is not clear at all to us how Unity sends the audio to the hardware/low level audio system.

    Here is a little diagram which shows our use case:

    So we have our native iOS app with all the Unity stuff as a framework. Unity sends the audio data directly to the system (down arrow). But we want to feed it to another iOS audio processing app ("Host Audio App") which pulls data from an AVAudioUnit in our native app. The little dashed arrow basically is our problem area: how to get the audio data to the AVAudioUnit, ideally *instead* sending it to the system.

    Any help or advice is appreciated!

    Marc-André

    PS. Because we are basically stuck right now, we are thinking about a very raw solution using a shared buffer (NativeArray<Float>) which will be written to on the Unity side and then read on the iOS side. But this seems kind of brittle, especially for timing reasons… So this is kind of a last resort ;)
     
    Last edited: Sep 2, 2022
  2. janusl

    janusl

    Unity Technologies

    Joined:
    Aug 8, 2018
    Posts:
    24
  3. maweibezahn

    maweibezahn

    Joined:
    May 17, 2022
    Posts:
    2
    Hi, thank you for your reply! I tested the approach of sending data from OnAudioFilterRead.
    Unfortunately there seems to be a fundamental conflict with this when using this data in an instance of iOS's AVAudioEngine, because Unity blocks the audio output.
    Next I will try to send the data data manually to the host app (without AVAudioEngine) using older ObjC system calls. If that does not work, I will look at the Native Audio SDK and might be back with more questions :)