dheijl / swyh-rs

Stream What You Hear written in rust, inspired by SWYH.
MIT License
352 stars 15 forks source link

Popping sounds near start of playback #87

Closed AtriyaSen closed 1 year ago

AtriyaSen commented 1 year ago

I'm getting popping sounds/skipping during playback (I stream the audio of YouTube videos via UPnP to a streaming DAC connected directly via an ethernet cable to a laptop), but it seems to go away after about 10 seconds.

It may be helpful to know that this is when using WAV output. When using FLAC, the popping is much worse, and doesn't go away (making it unlistenable). LPCM does not work at all with my DAC.

I'm on Windows 11, and here's the log:

Configuration { server_port: Some(5901), auto_resume: false, sound_source: "CABLE Input (VB-Audio Virtual Cable)", sound_source_index: Some(0), log_level: Debug, ssdp_interval_mins: 1.0, auto_reconnect: false, disable_chunked: false, use_wave_format: true, bits_per_sample: Some(16), streaming_format: Some(Wav), monitor_rms: false, capture_timeout: Some(2000), inject_silence: Some(false), last_renderer: "DAC502 DAC502-0541", last_network: "192.168.3.18", config_dir: "C:\\Users\\Atriy\\.swyh-rs", config_id: Some("") }
Setup audio sources
Now running at ABOVE_NORMAL_PRIORITY_CLASS
Capturing audio from: CABLE Input (VB-Audio Virtual Cable)
Default audio SupportedStreamConfig { channels: 2, sample_rate: SampleRate(44100), buffer_size: Range { min: 0, max: 4294967295 }, sample_format: F32 }
Discover networks
Starting SSDP discovery
The streaming server is listening on http://192.168.3.18:5901/stream/swyh.wav
Streaming sample rate: 44100, bits per sample: 16, format: WAV
Received request /stream/swyh.wav from 192.168.3.11:36453
Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=44100, disable chunked=false to 192.168.3.11:36453
Streaming to 192.168.3.11:36453 has ended
The wave_reader is now receiving samples
AV Start playing on DAC502-0541 host=192.168.3.11 port=49152 from 192.168.3.18 using AvTransport Play
AV Stop playing on DAC502-0541 host=192.168.3.11 port=49152
Received request /stream/swyh.wav from 192.168.3.11:36454
Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=44100, disable chunked=false to 192.168.3.11:36454
dheijl commented 1 year ago

Your setup makes the poping sound unavoidable. Usb dacs do not tolerate any buffer underrun because they are designed to minimize latency. From the moment you introduce a network you introduce latency caused by the buffering on various layers.

The only way to overcome this is to add/increase buffering as close to the dac as possible, for instance in your upnp receiver on the laptop (this may be configurable).

This of course introduces latency, which is something you want to avoid when watching movies.

The only media player that can handle this afaik is VLC, it allows you to play the video with a configurable latency to compensate for your audio network latency.

AtriyaSen commented 1 year ago

Thanks. I do know about using VLC to manually configure latency and have been setting it to -0.35 seconds so far.

I'm not sure how to configure the UPnP receiver on my laptop though. Would still be a Windows 11 setting? Or would it require registry edits/special software to configure?

Also in this case isn't the DAC the UPnP receiver and the laptop the transmitter? Sorry if I have this backwards.

dheijl commented 1 year ago

I think I misunderstood you setup completely. I thought the DAC was connected via USB to your laptop, and that you were streaming from another PC to an upnp renderer running on that laptop. After looking at the specs of the Weiss DAC502 I suppose that the DAC is directly connected to your ethernet network and that the laptop is running swyh-rs to stream audio to the DAC. In that case the DAC itself is indeed running the upnp renderer, and there are no configurable settings in the DAC (like receive buffer read-ahead size) according to the Weiss documentation. So I'm afraid you're stuck there. The fact that FLAC is much worse is also easily explained: the FLAC compression increases the time between successive ethernet frames, and the minimal buffering in the DAC causes the inevitable drop-outs. It's unfortunate for you that swyh-rs does not have a configurable output buffering (introducing a fixed delay) either.

AtriyaSen commented 1 year ago

Thanks for taking the time to dig into this! It is indeed a Weiss DAC502 that is connected via ethernet - not USB - to a laptop, and the laptop is running swyh-rs to stream audio to the Weiss.

It’s not that bad: as I said, the popping seems to go away after the first 10 seconds or so when using WAV. I’m not sure if that’s also something explainable, or just a happy happenstance. And with a -0.35s setting in VLC, there is no audio-video mismatch either.

From: dheijl @.> Sent: Friday, February 17, 2023 1:18 PM To: dheijl/swyh-rs @.> Cc: Atriya Sen @.>; Author @.> Subject: Re: [dheijl/swyh-rs] Popping sounds near start of playback (Issue #87)

I think I misunderstood you setup completely. I thought the DAC was connected via USB to your laptop, and that you were streaming from another PC to an upnp renderer running on that laptop. After looking at the specs of the Weiss DAC502 I suppose that the DAC is directly connected to your ethernet network and that the laptop is running swyh-rs to stream audio to the DAC. In that case the DAC itself is indeed running the upnp renderer, and there are no configurable settings in the DAC (like receive buffer read-ahead size) according to the Weiss documentation. So I'm afraid you're stuck there. The fact that FLAC is much worse is also easily explained: the FLAC compression increases the time between successive ethernet frames, and the minimal buffering in the DAC causes the inevitable drop-outs. It's unfortunate for you that swyh-rs does not have a configurable output buffering (introducing a fixed delay) either.

— Reply to this email directly, view it on GitHub https://github.com/dheijl/swyh-rs/issues/87#issuecomment-1435125135 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXGEWCWZ4AOETMMC5YUUHDWX7FIJANCNFSM6AAAAAAU63YTPU . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ACXGEWBRVN4I3F4NOSTUJBLWX7FIJA5CNFSM6AAAAAAU63YTPWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSVRJCY6.gif Message ID: @. @.> >

dheijl commented 1 year ago

Well if you can live with it, so can I :)

As for explaining the 10 seconds: perhaps the DAC uses some adaptive buffering algorithm if it detects buffer underruns ( a wild guess) ?

AtriyaSen commented 1 year ago

Well if you can live with it, so can I :)

As for explaining the 10 seconds: perhaps the DAC uses some adaptive buffering algorithm if it detects buffer underruns ( a wild guess) ?

I suppose it's possible.

It would be great if VLC could stream the audio via UPnP to the DAC directly, but it apparently can't do that.

Thanks for your great little utility that allows me to play videos while streaming the audio to my DAC. The original SWYH didn't work for me at all!