Skip to content

Audio quality issue #327

Open
Open
@Seezov

Description

@Seezov

Describe the bug

Hi, I have audio quality issues on devices with Android 8 and 9 and some Android 10 devices. If I use default settings for AudioRecord I get distorted and choppy sound when streaming from the device.

To Reproduce

Stream from devices with Android 8 or 9

Expected behavior

Quality should be good

Version

0.14.1

Smartphone info.

Any device with Android 8 or 9, OPPO device with Andorid 10

Additional context

I've made temporary fix by coping your AudioRecordSource file and setting sampleCount to 2048 instead of default 1024, and it helped, the quality got better but it brought another issue. Now on newer devices (Android 11 and above and some Android 10) there is a crash when trying to stream

2025-01-10 16:25:49.887 AndroidRuntime           E  FATAL EXCEPTION: com.haishinkit.codec.AudioCodec (Ask Gemini)
                                                    Process: com.kidslox.app, PID: 14414
                                                    java.nio.BufferOverflowException
                                                    	at java.nio.ByteBuffer.put(ByteBuffer.java:1035)
                                                    	at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:285)
                                                    	at com.haishinkit.codec.AudioCodecBuffer.render(AudioCodecBuffer.kt:29)
                                                    	at com.haishinkit.codec.AudioCodec.onInputBufferAvailable(AudioCodec.kt:68)
                                                    	at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1923)
                                                    	at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1851)
                                                    	at android.os.Handler.dispatchMessage(Handler.java:109)
                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                    	at android.os.Looper.loop(Looper.java:317)
                                                    	at android.os.HandlerThread.run(HandlerThread.java:85)

So I guess, setting a 2048 sample count is not an ideal solution and I have a question. PLUS the problem is NOT Android version specific, because I've tested multiple devices with Android 10 and for some of them there are sound quality issues and for some, there are not.

  1. How can I increase sound quality on older devices?
  2. Maybe if increasing sampleCount IS the solution then can you add throws BufferOverflowException to onInputBufferAvailable or smth so I can catch the exception? Or maybe you could set sampleCount value based on the device (if it supports 2048 - set 2048)

Screenshots

No response

Relevant log output

2025-01-10 16:25:49.887 AndroidRuntime           E  FATAL EXCEPTION: com.haishinkit.codec.AudioCodec (Ask Gemini)
                                                    Process: com.kidslox.app, PID: 14414
                                                    java.nio.BufferOverflowException
                                                    	at java.nio.ByteBuffer.put(ByteBuffer.java:1035)
                                                    	at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:285)
                                                    	at com.haishinkit.codec.AudioCodecBuffer.render(AudioCodecBuffer.kt:29)
                                                    	at com.haishinkit.codec.AudioCodec.onInputBufferAvailable(AudioCodec.kt:68)
                                                    	at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1923)
                                                    	at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1851)
                                                    	at android.os.Handler.dispatchMessage(Handler.java:109)
                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                    	at android.os.Looper.loop(Looper.java:317)
                                                    	at android.os.HandlerThread.run(HandlerThread.java:85)

Metadata

Metadata

Assignees

No one assigned

    Labels

    deviceIndicates that an issue cannot be addressed due to the lack of access to the required device.good first issueIndicates that an issue for newcommers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions