Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

ONSP cuts off beginning of sound in Unity (5.4.0b18)

SvenVikingSvenViking Posts: 298
Art3mis
Using the Oculus Native Spatializer in Unity (tested in 5.4.0b18), when playing a sound via AudioSource.Play(), the very beginning of the sound is skipped. Calling SetParameters() before or after Play() doesn't make a difference to this. Changing the Buffer Size didn't seem to make a difference.

Example project here. Load AlternateBetweenSounds.unity and hit Play. Two sounds will play alternately. The left sound is a very short click. The right sound is exactly the same except with 1/20th of a second of silence added to the start.

The initial click should be missing from the left sound in-game. Both sounds play normally via Unity's standard sound system. You can uncomment the SetParamters() line/s in AlternateBetweenSounds.cs if you want. 
Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux)
Jungle Juice
Sven Co-op

Comments

  • petergiokarispetergiokaris Posts: 170 Oculus Staff
    Hi Sven, was this problem occurring in Unity 5.3 versions to do you recall?
    Peter Giokaris
    Senior Software Engineer
  • SvenVikingSvenViking Posts: 298
    Art3mis
    edited May 2016
    Hi Peter,

    I just tried the example project in 5.3.4p5 and the results were the same. Unfortunately I don't know about older versions as I had been using the non-Native plugin previously. If the issue existed with that, I failed to notice it.

    Edit: This is to be expected, but in case it's convenient to have it confirmed, just mentioning that the issue remains unchanged in 5.4.0b19.
    Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux)
    Jungle Juice
    Sven Co-op
  • SvenVikingSvenViking Posts: 298
    Art3mis
    edited June 2016
    This has changed in 5.4.0b20, but is not fixed. If anything it's arguably worse.

    In b19, whether you called SetParameters() before or after Play(), or both, or not at all, the sound with a click right at the beginning would play with the click skipped, while the sound with some silence at the beginning would play as expected.

    Since b20, the above is only true if SetParameters() is called after Play(). If it's called before Play() or not at all, the sound with the click at the beginning plays with the click skipped as above, but the sound with some silence at the beginning isn't audible at all for some reason.

    (Edit: b21 is the same as b20.)
    Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux)
    Jungle Juice
    Sven Co-op
  • petergiokarispetergiokaris Posts: 170 Oculus Staff
    Hi SvenViking,

    I've isolated the issue to the following line in SetParameters():

        public void SetParameters(ref AudioSource source)
        {
    #if ENABLE_SPATIALIZER_API

            // Check to see if we should disable spatializion
            if ((Application.isPlaying == false) ||
                (AudioListener.pause == true) ||
                (source.isPlaying == false) ||   <<<<<<<<<<<
                (source.isActiveAndEnabled == false)
               )
    ...

    Removing this check solves the issue. These checks were put in place to reduce CPU load (since a paused sound is not handled as well as they can be via the native Unity SDK; the process loop continues to process if the sound is not playing). You might want to check to see what happens to the audio load when you comment out that line above (it would be great to get an idea if things get bad CPU-wise :) ).

    Best,
    Peter
    Peter Giokaris
    Senior Software Engineer
  • SvenVikingSvenViking Posts: 298
    Art3mis
    edited June 2016
    Hi Peter,

    That does seem to solve the problem for AudioSources that are already present in the scene, though CPU usage is substantially increased if many stopped/completed AudioSources exist. Once you reach 64 stopped/completed sounds, new sounds become inaudible, presumably because the stopped sounds are taking up all voice slots. (They no longer use CPU or voice slots if the AudioSource component is disabled.)

    Unfortunately this still doesn't solve the skipping problem for newly-instantiated sounds. I've updated my test project to demonstrate that.

    Download the new version here and play the "AlternateBetweenInstantiatedSounds" scene. Results are like before even with the (source.isPlaying == false) line commented out. (These sounds are Play()ed from code after calling SetParameters(), but the results are the same with instantiated sounds set to Play On Awake, if that matters.)

    You can use the same scene to test CPU usage -- just watch the profiler as the number of finished AudioSources increases. Once they reach 64, sound will no longer be heard.
    Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux)
    Jungle Juice
    Sven Co-op
Sign In or Register to comment.