Android Oboe library is laggy on a few devices












1















In my Android app, I use the Oboe library and the Vorbisfile library to extract, process and redirect audio samples to the audio output.



To keep it simple, here is a quick overview of what I've been doing (using the hello-oboe example here) :



oboe::DataCallbackResult PlayAudioEngine::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames)
{
// init:
if (mBufferSizeSelection != kBufferSizeAutomatic && audioStream->getBufferSizeInFrames() != mBufferSizeSelection * mFramesPerBurst)
{
audioStream->setBufferSizeInFrames(mBufferSizeSelection * mFramesPerBurst);
}

// audio extraction:
if (audioStream->getFormat() == oboe::AudioFormat::Float)
{
// extract audio samples using vorbisfile...
// put the extracted audio samples in audioData...
}
else
{
// extract audio samples using vorbisfile...
// put the extracted audio samples in audioData...
}
return oboe::DataCallbackResult::Continue;
}


This code works like a charm on most devices (I tested it on 10+ devices, including low-end devices like Galaxy S3 mini, or Nokia 1), without any lag.



The problem is: On some devices (Archos 55 Cobalt (API 23) and OnePlus One (API 23)), the sound is quite laggy, especially if I extract 2 audio files at the same time (so I can play them simultaneously), while the very same code works without any problem on less powerful devices like the Nokia 1.



I also tried by setting mBufferSizeSelection to 4 or even 8, but there is no change at all.



Has anyone experienced something similar? Did I miss something?



Thanks for your help.










share|improve this question





























    1















    In my Android app, I use the Oboe library and the Vorbisfile library to extract, process and redirect audio samples to the audio output.



    To keep it simple, here is a quick overview of what I've been doing (using the hello-oboe example here) :



    oboe::DataCallbackResult PlayAudioEngine::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames)
    {
    // init:
    if (mBufferSizeSelection != kBufferSizeAutomatic && audioStream->getBufferSizeInFrames() != mBufferSizeSelection * mFramesPerBurst)
    {
    audioStream->setBufferSizeInFrames(mBufferSizeSelection * mFramesPerBurst);
    }

    // audio extraction:
    if (audioStream->getFormat() == oboe::AudioFormat::Float)
    {
    // extract audio samples using vorbisfile...
    // put the extracted audio samples in audioData...
    }
    else
    {
    // extract audio samples using vorbisfile...
    // put the extracted audio samples in audioData...
    }
    return oboe::DataCallbackResult::Continue;
    }


    This code works like a charm on most devices (I tested it on 10+ devices, including low-end devices like Galaxy S3 mini, or Nokia 1), without any lag.



    The problem is: On some devices (Archos 55 Cobalt (API 23) and OnePlus One (API 23)), the sound is quite laggy, especially if I extract 2 audio files at the same time (so I can play them simultaneously), while the very same code works without any problem on less powerful devices like the Nokia 1.



    I also tried by setting mBufferSizeSelection to 4 or even 8, but there is no change at all.



    Has anyone experienced something similar? Did I miss something?



    Thanks for your help.










    share|improve this question



























      1












      1








      1








      In my Android app, I use the Oboe library and the Vorbisfile library to extract, process and redirect audio samples to the audio output.



      To keep it simple, here is a quick overview of what I've been doing (using the hello-oboe example here) :



      oboe::DataCallbackResult PlayAudioEngine::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames)
      {
      // init:
      if (mBufferSizeSelection != kBufferSizeAutomatic && audioStream->getBufferSizeInFrames() != mBufferSizeSelection * mFramesPerBurst)
      {
      audioStream->setBufferSizeInFrames(mBufferSizeSelection * mFramesPerBurst);
      }

      // audio extraction:
      if (audioStream->getFormat() == oboe::AudioFormat::Float)
      {
      // extract audio samples using vorbisfile...
      // put the extracted audio samples in audioData...
      }
      else
      {
      // extract audio samples using vorbisfile...
      // put the extracted audio samples in audioData...
      }
      return oboe::DataCallbackResult::Continue;
      }


      This code works like a charm on most devices (I tested it on 10+ devices, including low-end devices like Galaxy S3 mini, or Nokia 1), without any lag.



      The problem is: On some devices (Archos 55 Cobalt (API 23) and OnePlus One (API 23)), the sound is quite laggy, especially if I extract 2 audio files at the same time (so I can play them simultaneously), while the very same code works without any problem on less powerful devices like the Nokia 1.



      I also tried by setting mBufferSizeSelection to 4 or even 8, but there is no change at all.



      Has anyone experienced something similar? Did I miss something?



      Thanks for your help.










      share|improve this question
















      In my Android app, I use the Oboe library and the Vorbisfile library to extract, process and redirect audio samples to the audio output.



      To keep it simple, here is a quick overview of what I've been doing (using the hello-oboe example here) :



      oboe::DataCallbackResult PlayAudioEngine::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames)
      {
      // init:
      if (mBufferSizeSelection != kBufferSizeAutomatic && audioStream->getBufferSizeInFrames() != mBufferSizeSelection * mFramesPerBurst)
      {
      audioStream->setBufferSizeInFrames(mBufferSizeSelection * mFramesPerBurst);
      }

      // audio extraction:
      if (audioStream->getFormat() == oboe::AudioFormat::Float)
      {
      // extract audio samples using vorbisfile...
      // put the extracted audio samples in audioData...
      }
      else
      {
      // extract audio samples using vorbisfile...
      // put the extracted audio samples in audioData...
      }
      return oboe::DataCallbackResult::Continue;
      }


      This code works like a charm on most devices (I tested it on 10+ devices, including low-end devices like Galaxy S3 mini, or Nokia 1), without any lag.



      The problem is: On some devices (Archos 55 Cobalt (API 23) and OnePlus One (API 23)), the sound is quite laggy, especially if I extract 2 audio files at the same time (so I can play them simultaneously), while the very same code works without any problem on less powerful devices like the Nokia 1.



      I also tried by setting mBufferSizeSelection to 4 or even 8, but there is no change at all.



      Has anyone experienced something similar? Did I miss something?



      Thanks for your help.







      android android-ndk audio-player oboe






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 7 '18 at 11:42









      donturner

      7,60353258




      7,60353258










      asked Nov 17 '18 at 13:21









      thenaohthenaoh

      260416




      260416
























          1 Answer
          1






          active

          oldest

          votes


















          1














          First thing is you shouldn't be doing your extraction and decoding inside the audio callback because this will block the audio callback until decoding has occurred which will be causing constant underruns.



          Instead do the decoding after you set up your stream (after calling AudioStreamBuilder::openStream). That way your PCM data will be ready immediately when the audio callback occurs.



          Secondly, what do you mean by "quite laggy"? There are a number of sources of lag in the signal path which include:




          • Time taken for touch events to reach the app

          • Time taken for the first audio callback to start if you're starting your stream from another thread

          • Time taken for the vorbis decoding to occur

          • Time taken for audio frames to arrive at the audio device

          • Time taken for the rendered audio to reach the speaker or headphones (there can be DSP on the output path to improve acoustic qualities e.g. noise cancellation, bass boost etc)


          I realise that this question is quite old so highly likely no longer relevant but would be interested to hear how you got on.






          share|improve this answer
























          • Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

            – thenaoh
            Dec 20 '18 at 12:49













          • Bluetooth is a whole other story. Feel free to ask another question about that.

            – donturner
            Dec 20 '18 at 18:55











          • Yes, that what I did here: stackoverflow.com/questions/53871191/…

            – thenaoh
            Dec 20 '18 at 22:01











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351657%2fandroid-oboe-library-is-laggy-on-a-few-devices%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          First thing is you shouldn't be doing your extraction and decoding inside the audio callback because this will block the audio callback until decoding has occurred which will be causing constant underruns.



          Instead do the decoding after you set up your stream (after calling AudioStreamBuilder::openStream). That way your PCM data will be ready immediately when the audio callback occurs.



          Secondly, what do you mean by "quite laggy"? There are a number of sources of lag in the signal path which include:




          • Time taken for touch events to reach the app

          • Time taken for the first audio callback to start if you're starting your stream from another thread

          • Time taken for the vorbis decoding to occur

          • Time taken for audio frames to arrive at the audio device

          • Time taken for the rendered audio to reach the speaker or headphones (there can be DSP on the output path to improve acoustic qualities e.g. noise cancellation, bass boost etc)


          I realise that this question is quite old so highly likely no longer relevant but would be interested to hear how you got on.






          share|improve this answer
























          • Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

            – thenaoh
            Dec 20 '18 at 12:49













          • Bluetooth is a whole other story. Feel free to ask another question about that.

            – donturner
            Dec 20 '18 at 18:55











          • Yes, that what I did here: stackoverflow.com/questions/53871191/…

            – thenaoh
            Dec 20 '18 at 22:01
















          1














          First thing is you shouldn't be doing your extraction and decoding inside the audio callback because this will block the audio callback until decoding has occurred which will be causing constant underruns.



          Instead do the decoding after you set up your stream (after calling AudioStreamBuilder::openStream). That way your PCM data will be ready immediately when the audio callback occurs.



          Secondly, what do you mean by "quite laggy"? There are a number of sources of lag in the signal path which include:




          • Time taken for touch events to reach the app

          • Time taken for the first audio callback to start if you're starting your stream from another thread

          • Time taken for the vorbis decoding to occur

          • Time taken for audio frames to arrive at the audio device

          • Time taken for the rendered audio to reach the speaker or headphones (there can be DSP on the output path to improve acoustic qualities e.g. noise cancellation, bass boost etc)


          I realise that this question is quite old so highly likely no longer relevant but would be interested to hear how you got on.






          share|improve this answer
























          • Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

            – thenaoh
            Dec 20 '18 at 12:49













          • Bluetooth is a whole other story. Feel free to ask another question about that.

            – donturner
            Dec 20 '18 at 18:55











          • Yes, that what I did here: stackoverflow.com/questions/53871191/…

            – thenaoh
            Dec 20 '18 at 22:01














          1












          1








          1







          First thing is you shouldn't be doing your extraction and decoding inside the audio callback because this will block the audio callback until decoding has occurred which will be causing constant underruns.



          Instead do the decoding after you set up your stream (after calling AudioStreamBuilder::openStream). That way your PCM data will be ready immediately when the audio callback occurs.



          Secondly, what do you mean by "quite laggy"? There are a number of sources of lag in the signal path which include:




          • Time taken for touch events to reach the app

          • Time taken for the first audio callback to start if you're starting your stream from another thread

          • Time taken for the vorbis decoding to occur

          • Time taken for audio frames to arrive at the audio device

          • Time taken for the rendered audio to reach the speaker or headphones (there can be DSP on the output path to improve acoustic qualities e.g. noise cancellation, bass boost etc)


          I realise that this question is quite old so highly likely no longer relevant but would be interested to hear how you got on.






          share|improve this answer













          First thing is you shouldn't be doing your extraction and decoding inside the audio callback because this will block the audio callback until decoding has occurred which will be causing constant underruns.



          Instead do the decoding after you set up your stream (after calling AudioStreamBuilder::openStream). That way your PCM data will be ready immediately when the audio callback occurs.



          Secondly, what do you mean by "quite laggy"? There are a number of sources of lag in the signal path which include:




          • Time taken for touch events to reach the app

          • Time taken for the first audio callback to start if you're starting your stream from another thread

          • Time taken for the vorbis decoding to occur

          • Time taken for audio frames to arrive at the audio device

          • Time taken for the rendered audio to reach the speaker or headphones (there can be DSP on the output path to improve acoustic qualities e.g. noise cancellation, bass boost etc)


          I realise that this question is quite old so highly likely no longer relevant but would be interested to hear how you got on.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 7 '18 at 11:51









          donturnerdonturner

          7,60353258




          7,60353258













          • Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

            – thenaoh
            Dec 20 '18 at 12:49













          • Bluetooth is a whole other story. Feel free to ask another question about that.

            – donturner
            Dec 20 '18 at 18:55











          • Yes, that what I did here: stackoverflow.com/questions/53871191/…

            – thenaoh
            Dec 20 '18 at 22:01



















          • Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

            – thenaoh
            Dec 20 '18 at 12:49













          • Bluetooth is a whole other story. Feel free to ask another question about that.

            – donturner
            Dec 20 '18 at 18:55











          • Yes, that what I did here: stackoverflow.com/questions/53871191/…

            – thenaoh
            Dec 20 '18 at 22:01

















          Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

          – thenaoh
          Dec 20 '18 at 12:49







          Thanks for your answer. Now I extract and process audio on a separate thread. It adds some latency, but it's not a problem in my project, and at least, I don't have underruns anymore. And yes, by "laggy", I meant underruns. That said, even with that solution, I still have underruns on some device, when I play the sound using a bluetooth loudspeaker (and I have no idea why...).

          – thenaoh
          Dec 20 '18 at 12:49















          Bluetooth is a whole other story. Feel free to ask another question about that.

          – donturner
          Dec 20 '18 at 18:55





          Bluetooth is a whole other story. Feel free to ask another question about that.

          – donturner
          Dec 20 '18 at 18:55













          Yes, that what I did here: stackoverflow.com/questions/53871191/…

          – thenaoh
          Dec 20 '18 at 22:01





          Yes, that what I did here: stackoverflow.com/questions/53871191/…

          – thenaoh
          Dec 20 '18 at 22:01


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351657%2fandroid-oboe-library-is-laggy-on-a-few-devices%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini