Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioStream.getBufferSizeInFrames() returns 0 on many devices #285

Closed
mregnauld opened this issue Nov 27, 2018 · 4 comments
Closed

AudioStream.getBufferSizeInFrames() returns 0 on many devices #285

mregnauld opened this issue Nov 27, 2018 · 4 comments
Assignees
Labels

Comments

@mregnauld
Copy link

mregnauld commented Nov 27, 2018

I noticed that, suprisingly, the AudioStream.getBufferSizeInFrames() function always returns 0 on many devices, including:

  • Samsung Galaxy S7
  • OnePlus One
  • Archos 55 Cobalt Plus
  • Meizu U10
  • Huawei P8 Lite 2017
  • Motorola Moto E4 Plus
  • Samsung Galaxy S3 Mini
  • Samsung Galaxy Note 2
  • Samsung Tab A (2016)
  • LG Q6

Even if I specify a size using AudioStream.setBufferSizeInFrames(), it still returns 0, and AudioStream.setBufferSizeInFrames() returns the following error: oboe::Result::ErrorUnimplemented

Is it a bug, or did I miss something?
How can I set the buffer size if AudioStream.setBufferSizeInFrames() doesn't work or is not implemented?

EDIT:

I found out that, when I read the Oboe code, I can read, for AudioStreamBuffered::setBufferSizeInFrames() (in the OpenSLES section):
"Only supported when we are not using a callback"
And the problem is: I use a callback so I can redirect my audio samples on the fly to the audio output.

So, how can I set the buffer size on older versions of Android (< API 27) that use OpenSLES, or, if not possible, how can I play sound without using any callback?

Thanks.

@philburk
Copy link
Collaborator

The ability to set the buffer size dynamically is a new AAudio feature. It helps us achieve lower latency by tuning the buffer size at run time.

We cannot implement all of the AAudio features on OpenSL ES but we try. We cannot implement setBufferSizeInFrames(). But I think we could do a better job with getBufferSizeInFrames. I think in this case it might be better to return the fixed buffer size. If our callback buffer is N frames and we have M callback buffers then we could return (N*M). That would be more accurate than zero.

@mregnauld
Copy link
Author

Thank you.

The reason why I asked that is because of the problem mentioned in the issue #286 : on a Galaxy S7, sometimes, the sound is randomly crackled, for a very short period of time when it happens (like a few milliseconds).

It really sounds like there is an underrun, so I tried using the AudioStreamBuffered::setBufferSizeInFrames() function to get a bigger buffer. This fix worked like a charm on a device with Android API 27, but unfortunately, it doesn't work on my Galaxy S7 that has API 23 (using OpenSLES, then), since this function is only supported when we are not using a callback (only for OpenSLES).

This crackling problem is quite a big issue and I have the problem even with the hello-oboe example.

@philburk philburk self-assigned this Nov 29, 2018
@philburk
Copy link
Collaborator

I will address the crackling problem in #286
Let's keep this issue focussed on getBufferSizeInFrames().
The problem in getBufferSizeInFrames() was because Oboe reported zero instead of the actual size. With the fix you will get the actual size. This fix does not change the actual buffer size and will have no impact on crackling.

philburk pushed a commit that referenced this issue Nov 29, 2018
Return the BufferCapacityInFrames instead of zero.

Fixes #285
@mregnauld
Copy link
Author

Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants