Android 10: Issues with Sound - AUDIO_OUTPUT_FLAG_FAST

Anything libgdx related goes here!

Android 10: Issues with Sound - AUDIO_OUTPUT_FLAG_FAST

Postby imagnity » Sun Feb 16, 2020 3:32 am

Hi all,

Depending on android device, some reported before issue with audio rate sampling mismatch where the issue log would read - "AUDIO_OUTPUT_FLAG_FAST denied by client". This issue was mostly hardware related and if you could match hardware rate (e.g. 48000hz, 44100hz), things would have been fine.

Currently in Android 10, similar issue happens except the log reads "createTrack_l(0): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 14063". Note, it reads 'server', not 'client'. I tested some other games from libgdx showcase like Magic Potion as I exhausted efforts on my WIP game. Note almost all search results on this subject you would find in web, I am already aware of, and no, those won't resolve the problem. Been trying to fix this issue for 3 weeks and I am just baffled. So, converting to device rate, or different audio format like wav, mp3, ogg won't help either. Even if you have just 1 sound playing, you will have this and every time, you will have a brief stutter. Try playing a recent libgdx made game with frequent sound playing, try running that game with device connected to Android Studio or any IDE where you can see the log, and you will see the issue mentioned above.

Devices I tried with: Galaxy S10, Sony Xperia 5. Both on Android 10. Does anyone have any other phone to try this with? Game you can try is : https://play.google.com/store/apps/deta ... tion&hl=en (No, not my game or any affiliation)

Lag can be noticeable if you play a runner type game. This issue in not occurring non-libgdx game. Note this is not an issue on IOS as I tested mine.

Previous issue that was reported in libgdx for reference: https://github.com/libgdx/libgdx/issues/3042

Issue that was fixed in Android Oboe (feels relevant): https://github.com/google/oboe/issues/179
Check out my games - http://www.imagnity.com/games/
imagnity
 
Posts: 197
Joined: Mon Mar 25, 2013 6:27 pm

Re: Android 10: Issues with Sound - AUDIO_OUTPUT_FLAG_FAST

Postby obigu » Sun Feb 16, 2020 2:19 pm

If your game plays frequent sounds, the only fix I've found for the stutters/lag is to play them on a separate thread (AndroidHandler). Try this game in which A Lot of sounds can play at the same time https://play.google.com/store/apps/deta ... rick&hl=en to see results.
obigu
 
Posts: 147
Joined: Fri Aug 02, 2013 4:47 pm

Re: Android 10: Issues with Sound - AUDIO_OUTPUT_FLAG_FAST

Postby imagnity » Tue Feb 18, 2020 11:32 pm

obigu wrote:If your game plays frequent sounds, the only fix I've found for the stutters/lag is to play them on a separate thread (AndroidHandler). Try this game in which A Lot of sounds can play at the same time https://play.google.com/store/apps/deta ... rick&hl=en to see results.


Thank you for the response! I tried both 'One More Brick' and also your 'Dash till Puff 2' (This is very similar to my 2013 title - Rebel Chick (I deleted as it was a flop)). What I would love to find out - why in 'One More Brick' despite many sounds, you do not have 'AUDIO_OUTPUT_FLAG_FAST denied by server' issue; however, you have the exact same problem I explained in your 'Dash till Puff 2', although latter has a couple of sounds compared to your 'One More Brick' title.

I am more curious to know what causes this and why it's not happening in your One More Brick game or other non-libgdx games.

As for threading, I tried creating an Android Manager class, something like-

Code: Select all
    private boolean playSound(final Sound sfx, final float volume, final boolean isLoop){

        try {

            Gdx.app.postRunnable(new Runnable() {

                @Override
                public void run() {
                    if (isLoop) {
                        sfx.loop();
                    } else{
                        sfx.play(volume);
                    }
                }
            });

        } catch (Throwable ex) {
            ex.printStackTrace(); // TODO
        }
        return true;
    }

    private boolean playSound(Sound sfx){
        return playSound(sfx, 1.0f, false);
    }

    public void coinHit() {
        playSound(Assets.coinHitSfx);
    }


Doesn't work, still get the 'denied by server' error (which is expected) but still lags every time that shows up. If I turn off sound, all good obviously. How did you implement threading? Possible to share a bare-minimum sample? I think my implementation is poor.
Check out my games - http://www.imagnity.com/games/
imagnity
 
Posts: 197
Joined: Mon Mar 25, 2013 6:27 pm

Re: Android 10: Issues with Sound - AUDIO_OUTPUT_FLAG_FAST

Postby obigu » Wed Feb 19, 2020 2:14 pm

Dash till Puff 2 doesn't run sounds on a separate thread.

This is a simplified version of the code of the Android implementation of my SoundService (the other platforms implementations simply play the sound).

You can ignore the Playable interface and assume it's a libGDX Sound.

Code: Select all
public class HandlerAndroidSoundService implements SoundService {

   private final HandlerThread handlerThread;
   private final Handler handler;

   public HandlerAndroidSoundService() {
      // Create a new background thread for processing messages or runnables sequentially
      handlerThread = new HandlerThread("libGDX Sound Management");
      // Starts the background thread
      handlerThread.start();
      // Create a handler attached to the HandlerThread's Looper
      handler = new Handler(handlerThread.getLooper()) {
         @Override
         public void handleMessage(Message msg) {
            // Process received messages here!
         }
      };
   }

   @Override
   public void play(final Playable playable) {
      handler.post(new Runnable() {
         @Override
         public void run() {
            playable.play();
         }
      });
   }

   @Override
   public void onDestroy() {
      handlerThread.quit();
   }
}

obigu
 
Posts: 147
Joined: Fri Aug 02, 2013 4:47 pm

Re: Android 10: Issues with Sound - AUDIO_OUTPUT_FLAG_FAST

Postby imagnity » Sat Feb 22, 2020 1:33 am

I still get the 'denied by server' error. If I use Android's HandlerThread, yes, you are very right on getting rid of most lags. Thank you for the snippet. Would you please check in your brick game if most sounds are at least a second long? If I made mine all 2 seconds long with silence at end, that error disappears.
Check out my games - http://www.imagnity.com/games/
imagnity
 
Posts: 197
Joined: Mon Mar 25, 2013 6:27 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest