reki2000 / mp-audio-stream

Flutter plug-in for multi platform simple audio stream playback with real-time generated audio data streams
MIT License
9 stars 4 forks source link

Volume (randomly?) goes to full zero (Linux, PipeWire only afaict) #25

Open DanielLukic opened 2 months ago

DanielLukic commented 2 months ago

Title says it all. Everything is fine until suddenly no sound. Took me a while to figure out it's the system's volume for the Flutter application. For some weird reason it suddenly goes to zero.

Is there a way to influence this? I briefly looked at miniaudio. But it's unclear how to control the "ma device" volume. Is this possible?

Anyway, maybe someone has an idea how to fix this? I wouldn't mind trying to come up with a fix myself. I'll try to dive into the code. But definitely out of my comfort zone.. :joy: :shrug: :see_no_evil:

Unrelated, but let me know if it's worth creating another issue: Web audio (again Linux only tested, Chrome in this case) has a very noticeable lag compared to desktop. Tried various buffer sizes. But seems inherent.

reki2000 commented 1 month ago

I don't have any Linux bare-metal environment, only WSL2. If anyone can reproduce this, I'd check further.

As for the lagging issue, in the previous version web platform had fixed buffer size though init parameters are specified. it was fixed in the latest 0.2.0.

IntensiCode commented 1 month ago

tried the new version. is there a bug in the web impl for when different values for buffer are passed in? i'm getting a cast exception for 11025 sample rate for some reason.. :thinking: just fyi...

IntensiCode commented 1 month ago
diff --git lib/src/mp_audio_stream_web.dart lib/src/mp_audio_stream_web.dart
index 6228bd9..569f784 100644
--- lib/src/mp_audio_stream_web.dart
+++ lib/src/mp_audio_stream_web.dart
@@ -53,8 +53,8 @@ class AudioStreamImpl extends mpaudio.AudioStream {
       int channels = 1,
       int sampleRate = 44100}) {
     delay((s) => s.init(
-        channels * (bufferMilliSec * sampleRate / 1000) as int,
-        channels * (waitingBufferMilliSec * sampleRate / 1000) as int,
+        (channels * bufferMilliSec * sampleRate ~/ 1000),
+        (channels * waitingBufferMilliSec * sampleRate) ~/ 1000,
         channels,
         sampleRate));
     return 0;

maybe?

reki2000 commented 3 weeks ago

@IntensiCode Thanks. Will fix it!