Search Unity

Unity 3: get all audio samples

Discussion in 'Scripting' started by cecarlsen, Aug 14, 2010.

  1. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
    [this topic was first posted in the Unity Support forum, but should have been posted here]
    http://forum.unity3d.com/viewtopic.php?t=61105
    ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

    Hi

    I just started playing with Unity 3 and I can't seem to find a way to get all samples from an AudioClip. I need to render a simple waveform in runtime. This was not possible in v.2.6, but how about v.3? ...Søren?

    Best
    ~ce
     
  2. soren

    soren

    Joined:
    Feb 18, 2008
    Posts:
    123
    Hi Carl,
    You can not read out all sample values. Why do you need that runtime? Can't you just extract that looking at the file? Either parse it from script or from a wav- or hex-editor, create a bitmap and show that. You can get the currently *playing* samples though, with GetOutputData on each source or the main output (AudioListener.GetOutputData). Freq. data is available the same way via GetSpectrumData().

    cheers,
    Søren
     
  3. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
    Thanks for the reply Søren.

    Because the final "game" runs as a standalone and the users load their own PCM16 sound content. I use an external application called oggenc to convert the sounds to ogg before loading them into the unity standalone using the WWW class.

    As I needed a runtime solution I wrote a Java application that I call from Unity to extract down-sampled values and save them in a text file ... but this is not exactly a pretty solution.

    Why not give slightly more FMOD access to the sound nerds like myself? FMOD has a lovely method called sound.readData(). Is this a design decision or is Unity limited by the licence agreement they have with FMOD?

    And now that I have your attention, I want to thank you for your great effort on Unity3. The new sound features are truly going transform the game experience.

    ~ce
     
  4. soren

    soren

    Joined:
    Feb 18, 2008
    Posts:
    123
    If you're passing the data around to encoders etc. it should be pretty easy to read out the samples as well. You can easily do that from script (no need for external Java app and text files?). Just read out the size in the WAV header and read away :) (I presume it's 16 bit wav files you get as input)

    Design decision... To keep a stringent API. It's been our strategy from the start to expose audio features in a *unity* way and not expose everything in the (rather bloated) fmod API and it let us strip the fmod library down to a more phone/webplayer friendly size. But if people keep asking for specific API (like readData()/lock()) it would of course make sense to expose it. (but not for 3.0 :))

    Thanks, appreciate your inputs! keep 'em coming :)
     
  5. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
    It could potentially be different formats. I need a sound library to take the pain.

    It makes sense. But I'd still love to have 1) access to the samples, and 2) access to a runtime ogg converter.

    I have a question about the Unity/FMOD licence...
    Say I create a FMOD plugin for Unity (using fmodex.dll). I create scripts that depend on non-Unity FMOD features and I export a standalone player. Then I sell the player as commercial software. Is this legal or does it require a special license from FMOD?

    Thanks
    ~ce
     
  6. DavidPlans

    DavidPlans

    Joined:
    Jul 29, 2009
    Posts:
    39
    Hey Søren. Any chance you could expand on this? As I've just posted here:

    http://forum.unity3d.com/viewtopic.php?t=64782

    We're trying to pass Puredata audio data to/from Unity, and I'm kinda stuck trying to figure out how. We've managed to pass messages and sample data...but don't know what to do about actual audio...

    Totally understand this, this kind of design decision is what makes Unity such a robust, wonderful environment...but if people like us desperately *need* to pass audio to unity's session, is there any chance you could at least give us a hint on how?

    David
     
  7. soren

    soren

    Joined:
    Feb 18, 2008
    Posts:
    123
    Hi,
    Audio buffer access is not available now (and in 3.0). We are aware that this is one of the most wanted audio features - and we are working on it. But again, we want to do it "the right way" to ensure low latency, while still interfacing Mono (think GC, threads etc.)

    If you're running standalones you can use the FMOD plugin from http://www.squaretangle.com/FMODUnity.html.

    cheers,