KRTirtho / spotube

๐ŸŽง Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
https://spotube.krtirtho.dev/
Other
29.82k stars 1.23k forks source link

Intermittent Distorted Audio #571

Closed OfficialMuffin closed 7 months ago

OfficialMuffin commented 1 year ago

Is there an existing issue for this?

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

KRTirtho commented 1 year ago

Sorry but v3.0.0 was never released on F-Droid ๐Ÿคจ

OfficialMuffin commented 1 year ago

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 commented 1 year ago

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 commented 11 months ago

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 commented 11 months ago

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.

hackerb9 commented 11 months ago

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

jriano commented 11 months ago

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 commented 11 months ago

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

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

jriano commented 11 months ago

I am using the Google version of Android.

On Sat, Nov 4, 2023, 22:19 hackerb9 @.***> wrote:

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

@jriano https://github.com/jriano Are you running the Google version of Android or something like GrapheneOS?

โ€” Reply to this email directly, view it on GitHub https://github.com/KRTirtho/spotube/issues/571#issuecomment-1793611061, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD364YSZT3DRCXVB33YUR3YC3ZSRAVCNFSM6AAAAAA2GLAH2OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJTGYYTCMBWGE . You are receiving this because you were mentioned.Message ID: @.***>

hackerb9 commented 11 months ago

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 commented 8 months ago

I have a same issue on those environments:

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 commented 8 months ago

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 @ https://github.com/KRTirtho/spotube/issues/663#issuecomment-1718793706

martiperez commented 8 months ago

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:

olivier2 commented 8 months ago

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.

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 commented 8 months ago

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

https://github.com/KRTirtho/spotube/assets/1408881/d97e4531-0528-4f23-90d6-b2653aa25451

https://github.com/KRTirtho/spotube/assets/1408881/838abc7b-87d3-401f-a77d-569ce1c39085

KRTirtho commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

sappho192 commented 7 months ago

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

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 commented 7 months ago

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 commented 7 months ago

Closing it as it's fixed. Massive

Thanks

to @olivier2