Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Documentation bug for AudioClip.GetData() ?

Discussion in 'Documentation' started by Matexyu, Mar 15, 2017.

  1. Matexyu

    Matexyu

    Joined:
    Feb 22, 2017
    Posts:
    13
    Hi

    From the AudioClip.GetData() Unity documentation:
    "If the read length from the offset is longer than the clip length,
    the read will wrap around and read the remaining samples from the
    start of the clip."

    However, when running the following code:

    (audioClip previously loaded from a single channel audio asset)

    8< - - - - - -

    audioClipSamples = new float[audioClip.samples + 1];

    audioClip.GetData(audioClipSamples, 0);

    Assert.IsTrue(audioClipSamples[0] == audioClipSamples[audioClipSamples.Length - 1]);


    8< - - - - - -

    The assertion fails, and in the console, the following warning is printed:

    Data longer than the AudioClip: IG2 - Drums4. 176400 sample(s) copied
    UnityEngine.AudioClip:GetData(Single[], Int32)
     
    tinaaaaalee likes this.
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Hi Matexyu, I'll get a documentation bug submitted for you. Probably won't be instantly fixed. Just saying.
     
    Matexyu likes this.
  3. Matexyu

    Matexyu

    Joined:
    Feb 22, 2017
    Posts:
    13
    Thank you Graham :)
     
  4. flip_the_unflappable

    flip_the_unflappable

    Joined:
    Jul 9, 2020
    Posts:
    9
    I am getting the same warning in a similar context.

    Code (CSharp):
    1.  
    2. // get the sample length from the audio clip and create a new array from it
    3. float[] samples = new float[m_audioClip.samples * m_audioClip.channels]
    4. Debug.Log(m_aduioClip.samples); // prints out 7639823
    5. m_audioClip.GetData(samples, 0)
    6.  
    From the Console:

    Data longer than the AudioClip: testAudioClip. 7639822 sample(s) copied
    UnityEngine.AudioClip:GetData(Single[], Int32)

    What is going on here? Just a bug?
     
    DDAAACCC likes this.
  5. tinaaaaalee

    tinaaaaalee

    Joined:
    Jan 14, 2020
    Posts:
    4
    still having this problem
     
unityunity