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

Intermittent Distorted Audio #571

Closed
1 task done
OfficialMuffin opened this issue Jul 11, 2023 · 23 comments · Fixed by #1247
Closed
1 task done

Intermittent Distorted Audio #571

OfficialMuffin opened this issue Jul 11, 2023 · 23 comments · Fixed by #1247
Labels
bug Something isn't working

Comments

@OfficialMuffin
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When screen backlight times out and locks screen automatically and audio continues to play in tbe background, audio distorts at random times throughout. Even with other songs in the playlist.
E.g. suddenly voices and instruments turn high pitched and back to normal.

Expected Behavior

Audio to play with no issues when screen timeout expires and phone locks automatically.

Steps to reproduce

  1. Play audio from playlist
  2. Wait for screen timeout to expire.
  3. Audio will then distort at random times

Operating System

Android (GrapheneOS)

Spotube version

3.0.0

Installation source

F-Droid (Android)

Additional information

GrapheneOS build version:
TQ3A.230705.001.2023070500

@OfficialMuffin OfficialMuffin added the bug Something isn't working label Jul 11, 2023
@KRTirtho
Copy link
Owner

Sorry but v3.0.0 was never released on F-Droid 🤨

@OfficialMuffin
Copy link
Author

Apologies, I did download the APK from the GitHub releases. Strangely, it doesnt seem to be having audio issues at the moment. Ill reopen this issue if it returns.

@hackerb9
Copy link

Please re-open as I am having the exact same issue: audio is distorted when left playing in the background and the screen turns off.

I am using Spotube 3.1.1 from F-droid. I double checked the app battery settings and it is set to "unrestricted".

My OS is Android OSP 13 (GrapheneOS) on a Google Pixel 6 Pro.

@OfficialMuffin
Copy link
Author

Not sure if this is related to updating to Android 14 or not but updating to 3.2.0 seems to bring this issue back. 3.1.x was working fine for me until now.

Anyone else having the same issue?

@hackerb9
Copy link

I just tried both 3.1.2 and 3.2.0 and neither works for me. After a minute of being idle, the sound starts glitching. The only "workaround" I've found is to run some other program that keeps the CPU from going into a low power state.

@KRTirtho KRTirtho moved this to Backlog in Spotube Board Oct 29, 2023
@KRTirtho KRTirtho moved this from Backlog to Discussion in Spotube Board Oct 29, 2023
@hackerb9
Copy link

By the way, harmonoid does not have this problem on my phone.

@jriano
Copy link

jriano commented Nov 2, 2023

I have this issue on a Pixel 6a / Android 14 using both the current version on the Google store (3.2.0) and the current version on F-Droid.
For me, the distorted sound does not happen when using my bluetooth headphones, it happens when I am using the phone speaker.

@hackerb9
Copy link

hackerb9 commented Nov 5, 2023

I have this issue on a Pixel 6a / Android 14

@jriano Are you running the Google version of Android or something like GrapheneOS?

@jriano
Copy link

jriano commented Nov 5, 2023 via email

@hackerb9
Copy link

hackerb9 commented Nov 12, 2023

I am using the Google version of Android.

Thanks. So now we know that the problem occurs on Pixel 6 devices regardless of OS.

Additionally, another app which uses the same Flutter library for playing sound (Harmonoid) does not have the same issue, so the bug is almost certainly in Spotube.

@sappho192
Copy link
Contributor

I have a same issue on those environments:

  • Galaxy Fold 3 5G / Android 13 / Samsung One UI 5.1
  • Galaxy Note 20 5G / Andrdid 13 / Samsung One UI 5.1

Both have a same version of Spotube (3.4.0) and installed via Google Play appstore, and battery optimization is off for the app.

Currently I'm listening music via Bluetooth earbud (Galaxy Buds 2 Pro) and maybe this can be a reason...?

I'm going to use the app via wired earphones today to find out whether wireless earphones makes the problem.

@OfficialMuffin
Copy link
Author

OfficialMuffin commented Jan 31, 2024

Strangely, I've noticed recently that this only happens without any Bluetooth devices connected, and audio is playing directly through the phones speakers.

Having tested audio on two bluetooth headsets for a couple hours, there has been no distorted audio through them.
Almost like Bluetooth keeps the CPU awake or something like along the lines. Thats if the problem is the device being "CPU starved". See comment @
#663 (comment)

@martiperez
Copy link

I am also experimenting intermittent distorted audio on my Pixel 6, running Android 14 (Official Build UQ1A.240105.002), specifically when playing content directly through the phone speakers (no distortions occur when using Bluetooth audio devices). I've tried to troubleshoot the issue, but unfortunately, I have been successful. Here's a list of what I've tried so far in case it can provide any insights for debugging:

  • Adjusted audio qualities to medium/low
  • Switched audio source to Piped or Jiosaavn
  • Granted unrestricted battery usage permissions to the app
  • Kept the app open, preventing the phone from going to sleep

olivier2 added a commit to olivier2/spotube that referenced this issue Feb 8, 2024
…s off. Not familiar with libmpv, but seems to favor audiotrack audio output over opensles. KRTirtho#571
@olivier2
Copy link
Contributor

olivier2 commented Feb 8, 2024

I looked into this issue and into Harmonoid as suggested by @hackerb9. Here's what I found. Please correct me on any inaccuracy.

Both Harmonoid and Spotube use ryanheise/audio_service, but that's only for the background service and lock screen visual. The audio stack are different, at least in Spotube 3.4.

  • Harmonoid uses just_audio which uses Google's ExoPlayer which seems to use AudioTrack.
  • Spotube uses media_kit which uses libmpv which appears to use OpenSL ES by default, but can be configured to use AudioTrack. I've seen some commented code in Spotube player related to just_audio, but not sure if it's a previous implementation or an upcoming transition (@KRTirtho ?).

Maybe we could detect available audio sinks from libmpv and offer the selection in the settings? I didn't look into that.

My change seems fairly safe as OpenSL ES is the fallback if AudioTrack is not available, but it would be nice if someone else with the issue could test on their device.

I'll post video of the issue and the fix when I can.

By the way, when the audio issue occurs, logcat gets spam with a bunch of:
AOC aocd D F1:Irregular FIQ at 19074804: delta 4438 (lb: 4056, ub: 4136, FIQ delta: 341)
I can't tell if the cpu is starved by so much logging output and that's what causing the issue of if the audio issue produces the output. Anyway, the relation between the 2 events are obvious when running logcat. I couldn't find any info on aoc, aocd or Irregular FIQ online.

@olivier2
Copy link
Contributor

olivier2 commented Feb 9, 2024

Here are videos for reference. Sorry for the quality, the issue was not reproducible unless using the speaker

Pixel6.Issue.mp4
Pixel6.Fix.small.mp4

@KRTirtho
Copy link
Owner

Sorry for the really late reply 😓

I've seen some commented code in Spotube player related to just_audio, but not sure if it's a previous implementation or an upcoming transition (@KRTirtho ?).

I used just_audio before, but the desktop support for it wasn't good enough. So I partially started using media_kit for Spotube and eventually media_kit was stable enough for Mobile too, and it generally works better now. (Initially, Spotube was in fact using mpv's IPC to play music in desktop through mpv_dart). So I removed just_audio for all platforms and currently have no plans to add it back

KRTirtho added a commit that referenced this issue Feb 25, 2024
…ion id (#1221 & #1247)

* this change fixes the garbled audio on my Pixel 6a while the screen is off. Not familiar with libmpv, but seems to favor audiotrack audio output over opensles. #571

* get audio session id, send it to AudioTrack in libmpv, broadcast it to other apps. Fixes #1221

---------

Co-authored-by: Kingkor Roy Tirtho <[email protected]>
@KRTirtho
Copy link
Owner

The PR made by @olivier2 has been merged and should be available in nightly (10-20mins after this comment).
Please test this out, and please let us know if it works now in this thread

@mustard007
Copy link

The PR made by @olivier2 has been merged and should be available in nightly (10-20mins after this comment). Please test this out, and please let us know if it works now in this thread

It's not working for me: only black screen after accepted music and audio files on Android 14 Pixel 6 Pro.

Thanks!!

@olivier2
Copy link
Contributor

olivier2 commented Feb 25, 2024

It's not working for me: only black screen after accepted music and audio files on Android 14 Pixel 6 Pro.

I have the same with the nightly. Black screen after permission dialog box.

@olivier2
Copy link
Contributor

olivier2 commented Feb 25, 2024

Didn't feel right to open an issue for a nightly build, so started this discussion with the content of the spotube log.

@sappho192
Copy link
Contributor

sappho192 commented Feb 26, 2024

Hi, I've installed the latest nightly build (~ e6a20b5 ) and it seems that this audio issue has gone so far in my environments:

  • Galaxy Fold 3 5G / Android 13
  • Galaxy Note 20 5G / Andrdid 13
  • Bluetooth earbud (Galaxy Buds 2 Pro)

Thank you @olivier2 so much!

But instead, I've met a new issue. Next track doesn't play after current song ends during the screen is off.
If the app is running in foreground, next song plays well.

(Above cancelled issue seems to be resolved by disabling the battery optimization for this nightly app)

@mustard007
Copy link

Hi, I've installed the latest nightly build (~ e6a20b5 ) and it seems that this audio issue has gone so far in my environments:

  • Galaxy Fold 3 5G / Android 13
  • Galaxy Note 20 5G / Andrdid 13
  • Bluetooth earbud (Galaxy Buds 2 Pro)

Thank you @olivier2 so much!

But instead, I've met a new issue. Next track doesn't play after current song ends during the screen is off. If the app is running in foreground, next song plays well. (Above cancelled issue seems to be resolved by disabling the battery optimization for this nightly app)

Thanks and good job !!

Sound trouble also gone for me with this nightly. Pixel 6 Pro.

@KRTirtho KRTirtho moved this from In progress to Done in Spotube Board Mar 12, 2024
@KRTirtho
Copy link
Owner

Closing it as it's fixed.
Massive

Thanks

to @olivier2

@KRTirtho KRTirtho moved this from Done to Deployed in Spotube Board Mar 12, 2024
thinkingdev9 added a commit to thinkingdev9/spotube that referenced this issue Jan 11, 2025
…ion id (#1221 & #1247)

* this change fixes the garbled audio on my Pixel 6a while the screen is off. Not familiar with libmpv, but seems to favor audiotrack audio output over opensles. KRTirtho/spotube#571

* get audio session id, send it to AudioTrack in libmpv, broadcast it to other apps. Fixes KRTirtho/spotube#1221

---------

Co-authored-by: Kingkor Roy Tirtho <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Deployed
Development

Successfully merging a pull request may close this issue.

8 participants