dheijl / swyh-rs

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

Stuttering every 30 seconds on Sonos One #84

Closed pandronic closed 1 year ago

pandronic commented 1 year ago

Attached system information from Sonos app and log from the app:

Configuration { server_port: Some(5901), auto_resume: false, sound_source: "Speakers (Realtek High Definition Audio)", sound_source_index: None, log_level: Info, ssdp_interval_mins: 1.0, auto_reconnect: true, disable_chunked: false, use_wave_format: true, bits_per_sample: Some(24), streaming_format: Some(Wav), monitor_rms: false, capture_timeout: Some(2000), inject_silence: Some(false), last_renderer: "Sonos One Living Room - Sonos One Media Renderer", last_network: "192.168.0.169", config_dir: "<removed>", config_id: Some("") }
Setup audio sources
Now running at ABOVE_NORMAL_PRIORITY_CLASS
Capturing audio from: Speakers (Realtek High Definition Audio)
Default audio SupportedStreamConfig { channels: 2, sample_rate: SampleRate(48000), buffer_size: Range { min: 0, max: 4294967295 }, sample_format: F32 }
Discover networks
Starting SSDP discovery
The streaming server is listening on http://192.168.0.169:5901/stream/swyh.wav
Streaming sample rate: 48000, bits per sample: 24, format: WAV
The wave_reader is now receiving samples
AV Start playing on Sonos One - Sonos One Media Renderer host=192.168.0.156 port=1400 from 192.168.0.169 using AvTransport Play
AV Stop playing on Sonos One - Sonos One Media Renderer host=192.168.0.156 port=1400
Received request /stream/swyh.wav from 192.168.0.156:34560
Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, disable chunked=false to 192.168.0.156:34560

Windows 10 Home v10.0.19044 Build 19044

Let me know if you need anything else.

Screenshot_20221208-124033

dheijl commented 1 year ago

Could you try to

and see if it changes anything?

Also older Sonos devices (Play 5 gen 1) had very limited buffer space and are very sensitive to network delays (wifi).

pandronic commented 1 year ago

No change unfortunately.

My current config:

[Configuration]
ServerPort = 5901
AutoResume = true
SoundCard = "Speakers (Realtek High Definition Audio)"
LogLevel = "INFO"
SSDPIntervalMins = 10.0
AutoReconnect = true
DisableChunked = true
UseWaveFormat = true
BitsPerSample = 24
StreamingFormat = "Wav"
MonitorRms = false
CaptureTimeout = 2000
InjectSilence = false
LastRenderer = "Sonos One Sonos One - Sonos One Media Renderer"
LastNetwork = "192.168.0.169"
ConfigDir = "<removed>"
ConfigId = ""
dheijl commented 1 year ago

Could you try 16 bits per sample? If it reduces stuttering then it is most likely to be a lack of buffering capacity in the Sonos. And I would also disable autoresume and autoreconnect.

pandronic commented 1 year ago

No change. Still 30 sec.

dheijl commented 1 year ago

Can you upload the complete debug log file here after running with autoresume and autoreconnect disabled for a couple of minutes? And you don't have anything running on the PC that causes cpu or network spikes at a 30 seconds interval when looking in the task manager?

pandronic commented 1 year ago

I've closed everything except the Spotify app. There are no spikes in Task Manager, the CPU is under 10%.

I've attached the log - Log Level: Debug, Autoresume and Autoreconnect disabled.

log.txt

dheijl commented 1 year ago

Thanks for the log and your patience! Your device is a Sonos One Gen 2 with 1 GB of SDRAM, so it can't be a lack of buffer space. So it is either something on the network that causes delays, or something on the PC that is interfering with the sound capture or with the network streaming. If you don't mind spending some additional time on this problem, you could exclude the sound capturing as the source of the problem by installing vb-audio hifi cable and using that as the audio source for playback and capture. I certainly have no idea what could be the problem here...

pandronic commented 1 year ago

I've tried with vb-audio hifi. There's no change. I also made a recording so you can see what I mean by stuttering (0:14, 0:44, 1:14). I'll try from a different computer on the same network and report back.

dheijl commented 1 year ago

The exactly 30 seconds interval is strange. Perhaps the Sonos has a problem with the audio format (wav/lpcm). It's a shame that Sonos does not do FLAC (AFAIK).

pandronic commented 1 year ago

I've connected the Sonos via Ethernet directly to the router and lo and behold the stuttering is gone - also with autoresume, autoreconnect and 24bit enabled. I have on idea why it happened on wifi, especially considering that I have a pretty decent router and the speaker was 2 meters away in the same room.

dheijl commented 1 year ago

Good to hear that the stuttering is gone with an ethernet connection, but still wifi should not cause stuttering...

pandronic commented 1 year ago

I've discovered something very intriguing. When I scan the network with the Fing app for Android, playback (on wifi) stutters badly (even stops for a few seconds) while the phone is scanning for other devices connected to the network.

dheijl commented 1 year ago

Apparently Sonos can have issues with wifi: https://en.community.sonos.com/speakers-229128/troubleshooting-sonos-on-wifi-6856334. I guess the root of the problem is that they do not have a configurable buffering (latency) setting to cope with network latency.

pandronic commented 1 year ago

I moved the speaker from my 2.4ghz network to the 5ghz one and it works perfectly now. No more stutters every 30 seconds, in fact no more stutters at all. I can even scan the network with Fing and nothing happens. Does this make any sense?

dheijl commented 1 year ago

It does, as you are probably avoiding interference on the crowded 2.4 ghz band that has a much lower throughput anyway.

pandronic commented 1 year ago

Thanks for your time helping me debug my problem and great job on the app BTW! Things would be a lot easier if only my Sonos would support standard Bluetooth or have a headphone jack. I guess it's by design because without paid subscriptions my speaker is pretty much a paper weight.

dheijl commented 1 year ago

One last question (because I don't have access to a Sonos): did you ever try flac?

pandronic commented 1 year ago

Nothing happens when I select FLAC or LPCM.

dheijl commented 1 year ago

Thanks for confirming what I suspected. Flac is not supported when using dlna/upnp.