Search Unity

Unite for accurate audio! The bug can't escape, script attached.

Discussion in 'iOS and tvOS' started by gregzo, Jul 21, 2012.

  1. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi to all!

    Audio on iOS has suffered way too long from terrible inaccuracy : Play(offsetInSamples) will randomly, but often, be late by as much as 500 samples. On the device, not in the editor...

    Source of many headaches and endless frustration, we need this to be taken care of now! Unity 4.0 is soon to arrive, and I for one am not upgrading my license if this is not solved.

    Please join, reproduce the bug on your devices and file a bug report, rant, scream, rebel.

    To reproduce the bug, attach the following script to the main camera in an empty scene. Audio set to best latency doesn't solve it.

    Code (csharp):
    1. #pragma strict
    2.  
    3. private var testClip : AudioClip;
    4. private var clipLength : int = 44100;
    5. private var frequency : int = 44100;
    6.  
    7. private var sources : AudioSource[];
    8. private var testData : float[];
    9.  
    10. private var bugAppeared : boolean;
    11.  
    12. function Start ()
    13. {
    14.     testData = new float[256];
    15.    
    16.     sources = new AudioSource[2];
    17.    
    18.     for(sample in testData)
    19.     {
    20.         sample = .5;
    21.     }
    22.    
    23.     testClip = AudioClip.Create("TestClip",clipLength,1,frequency,true,false);
    24.    
    25.     testClip.SetData(testData,0);
    26.    
    27.     for(source in sources)
    28.     {
    29.         source = gameObject.AddComponent(AudioSource);
    30.         source.loop = true;
    31.         source.dopplerLevel = 0;
    32.         source.clip = testClip;
    33.     }
    34.    
    35.     sources[0].Play();
    36.    
    37.     yield;
    38.    
    39.     StartTest();
    40. }
    41.  
    42.  
    43. function StartTest()
    44. {
    45.     while(!bugAppeared)
    46.     {
    47.         yield PlayClipInSync(sources[1],sources[0]);
    48.     }
    49.    
    50. }
    51.  
    52. function PlayClipInSync(source : AudioSource, refSource : AudioSource) : IEnumerator
    53. {
    54.     source.Play(refSource.clip.samples-refSource.timeSamples);
    55.    
    56.     while(source.timeSamples==0)
    57.     {
    58.         yield;
    59.     }
    60.    
    61.     if(source.timeSamples!=refSource.timeSamples)
    62.     {
    63.         Debug.LogWarning("This is the bug. refSource.timeSamples : "+refSource.timeSamples+" source.timeSamples : "+source.timeSamples);
    64.         bugAppeared = true;
    65.     }
    66.     else
    67.     {
    68.         Debug.Log("refSource : "+refSource.timeSamples+" source : "+source.timeSamples);
    69.     }
    70. }
     
  2. AdbC99

    AdbC99

    Joined:
    Jan 18, 2012
    Posts:
    53
    I've paid $3000 dollars for licenses, I'm soon going to have to pay $1500 to upgrade and when it comes to audio support I am being utterly ripped off by Unity, the iOS package has so many random quirks and undocumented short fallings that I really don't believe the Unity people are up to the job of providing a sound triggering system. I admit your attempts at unifying people to get some work done on this for Unity 3 users; but personally I think it would be easier just to go elsewhere and accept that the $3000 I spent on Unity Pro licenses has resulted in me receiving a pile of junk. If Unity Basic had audio filters then the expense of $400 would just about have been palatable. I have already reproduced such bugs, they are really easy to see if you use white noise. I think I am willing to stake money that I could do better than Unity, and I think it is worth doing a CoreAudio package and avoid Unitys sound system altogether, just not up to the task on iOS.
     
  3. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi to all.

    Following my bug report, I'm in contact with Zbignev from Unity's team.

    It would be of great help if others reproduced the bug and filed a report, as Zbignev apparently cannot reproduce it.

    I have tested on iPad1, iPad3 and iPhone4, with iOS 3.2, 5.1 and 5.1 respectively, and tried iOS targets 3.2, 5.0 and 5.1, reproducing the bug every time (it is slower to come on new iPad running iOS 5.1).

    The only setting I change from a default Unity 3.5.2 scene is Edit->Project Settings ->Audio ->Latency -> best latency. My test scene is empty except for the default main camera to which the script above is attached.

    Many thanks for your help! I know not many devs out there need that kind of precision, but believe me for any kind of music apps it simply is not acceptable.

    Cheers,

    Gregzo
     
  4. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi.

    Zdegnev was able to reproduce the bug, passed on to devs.

    Hopefuly Unity 4 will correct it.

    Advice for now is to not use best latency for iOS, but to stick to default settings.

    G
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You will need to file a bug report in order to protect your investment. Sometimes people like yourself push the engine far in a production environment and until god starts to program there will always be a bug or two - human error :) So reporting them will help us all, and thank you.
     
  6. Panik-Studios

    Panik-Studios

    Joined:
    Aug 4, 2012
    Posts:
    3
    They need a buffering system. Even professional DAWs have such delays. Most of them come with an audio buffering called ASIO. Distortion and latency is especially prevalant on usb input devices. Like if you have a usb mic and go to record a song .. ur vocals come in late. They should really contact ASIO on this for help. it's all about buffering. the only problem is how to you keep audio slightly buffered in a game with out sacrificing game-play. I assume it would be memory hoarder. Don't knock on them too hard this engine has capabilities here and there that others don't. Why I picked it...Everything is gonna have it's ups and downs.. Unities down is audio.
     
  7. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Nothing that uses ASIO can be considered professional. ;-P
     
  8. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi,

    I've started a new thread here to try to constructively list audio issues in Unity. The goal is to save new users some time, as well as to centralize the state of audio misbehaviours in one thread. Already 6 quirks/bugs listed, all of them acknowledged by Unity. Do contribute if you have time! Bashing the engine isn't very useful, but detailed descriptions of bugs / quirks surely can be.
     
  9. AdbC99

    AdbC99

    Joined:
    Jan 18, 2012
    Posts:
    53
    already sent plenty, no response, sent to support, sent through the Unity bugs system, support say there is an audio developer; but they don't seem to have made any progress since Unity 3.4.2
     
  10. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    3.5 added AudioClip.Get/SetData, AudioClip.Create, audio buffer access (OnAudioFilterRead()), and a Microphone class. All of which were much needed and constitute, in my opininion, a new phase in Unity's audio capabilities. Before 3.5, you could only play AudioClips, not much else... Now, on the fly synthesis/filters are possible, as well as sample accurate sequencers.

    So, Unity's on the right track, it's just a shame Soren, the previous auio programmer, left before ironing out 3.5's newly introduced classes and functions...

    The new guy, Wayne Johnson, is from Firelight (makers of FMOD). I'm sure he needs time to dig in Soren's work, so let's be hopeful and help him in the process. That's also why I started the mentioned thread.

    I'm just as impatient as you are, but that won't help much...

    Precise scripts that demonstrate bugs and shortcomings need to be posted and submitted. The main problem I see is that we live in a visual age, and few give a damn about audio... Check on the forums, very very few Unity devs out there even use AudioClip.Get/Set data.

    So, let's remember Unity's priorities are mostly visual, and let's stay active on these forums to try to show there are some audio oriented devs out there using the engine, and there surely would be more if it was more polished in that regard.

    Cheers,

    Gregzo
     
  11. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Probably FMOD related?
     
    Last edited: Aug 26, 2012
  12. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Maybe...
    Maybe not...

    Would you care to elaborate?