Comments (13)
I think your best bet is to use VLC to watch youtube, because VLC allows you to specify an offset for the audio in relation to the video. Normally swyh-rs audio will be trailing behind the video, so throwing away audio samples would only make things worse (I think).
from swyh-rs.
VLC: I'd love to use VLC to watch youtube, but Google makes it very difficult, as they wouldn't want to lose ads.
Trailing behind: Yes audio would be trailing behind. Say the video counts 1 to 10 quickly. When the video is at 5, the audio might be at 4. But if we throw away the audio sample for 5, when the video is at 6, the audio would skip from 4 to 6 directly, thus catching up with the video. Makes sense?
from swyh-rs.
If I "throw away" samples, with what should I replace them? The audio stream is embedded in the video stream, the only option would be to delay the video stream. So I'm afraid your idea wouldn't work...
from swyh-rs.
from swyh-rs.
To paraphrase, i’m not suggesting a general way to change the time distance between video and audio - instead I’m proposing a way to catch up when too big of an audio buffer has been built up due to some hiccups. Ideally it should be done on the swyh.wav, but maybe it’d work with the buffer in memory too.
from swyh-rs.
The delay is not built up in memory or in swyh--rs, the delay is built up in the network transmission and in the receiving device, and you have no control over those.
Throwing away bytes will do exactly nothing except cause silence periods. The audio will not arrive faster because you throw some of it away. It arrives in sync with video. You can not speed it up.
from swyh-rs.
Yes, throwing away bytes will only cause silence periods if the delay due to network and receiving device is constant.
My hypothesis on my device is that there is sometimes a spike in latency at program startup that subsequently goes down. Let's say your normal latency is 50ms, but somehow there is a latency spike of 200ms. After the spike, even though the delay due to network and receiving device goes back to 50ms, the audio would still be behind by 200ms, with 150ms of audio built up in a buffer somewhere, so you can improve the sync by removing ~150ms of sample. My hypothesis came partly from the observation that when I have a 200ms+ delay, and the sync would improve if I stop and restart swyh-rs, but I don't want to do that because it causes other problems.
from swyh-rs.
You can never improve the sync by throwing away samples because the samples are provided by the OS at a fixed rate and you can not read them any faster than that rate (that is in sync with the video).
from swyh-rs.
... because the samples are provided by the OS at a fixed rate and you can not read them any faster than that rate (that is in sync with the video).
Hm, I think my hypothesis wouldn't contradict what you wrote above. Let's say we have a perfect setup with no sync latency, now the renderer (that doesn't know anything about video) suddenly stops reading the stream / playing the sound for 200ms, and resumes again from where it stopped. 200ms sync latency would be added by now, and the renderer would be playing each sample 200 ms after the OS provided them. Wouldn't such a situation benefit from some samples being skipped?
I understand that my video sync issue might not be relevant for most swyh users, so I might just try it myself to see what happens. Mr. Heijl, if you could suggest a few places in the source code to implement the sample skipping, I can give it a try in my spare time and report back.
from swyh-rs.
I suppose the best place to drop samples would be at the source as they arrive :
file: src\utils\audiodevices.rs
function: fn wave_reader<T>(..)
.
from swyh-rs.
I'll close this now, but feel free to reopen if you have new information.
from swyh-rs.
My finding is that throwing away samples at various times or inserting samples jiggle the latency around, but the effect seems mostly random, and throwing away too many samples will trigger stuttering. I tried the sample skipping at four different places in the code, one at audiodevices.rs as recommended, one at write() in rwstream.rs, two at read() in rwstream.rs, and the effect is more or less the same. I also played with the interactions with sending_silence. It's easy to throw the latency off balance, but it's very hard to predict what the outcome would be, so it's as if there is some kind of compensation happens when samples are skipped.
from swyh-rs.
Thanks for testing this! But it confirms what I thought: throwing away samples is not a viable solution for reducing latency.
from swyh-rs.
Related Issues (20)
- Volume Setting Question - Sonos Protocol HOT 10
- WAV Duration Limit & RF64 Delay HOT 4
- [QUESTION] How can I achieve best possible lag freee / 0 latency when streaming audio from PC to Wifi Speaker HOT 2
- Changing Audio-Source Index HOT 12
- very high latency streaming to WiiM HOT 5
- Comparison against foo_out_upnp HOT 21
- Text of button overflows outside the button HOT 4
- Source Device is not muted once streaming is started which causing to hear source + Wireless speaker HOT 2
- Sonos no sound HOT 9
- Autoreconnect does not work with multiple Sonos Devices HOT 22
- just a tips for windows proxy user with lagging and stuter problem on sonos HOT 3
- Volume control on Windows HOT 5
- How to configure firewall to run swyh-rs HOT 2
- audio stutters after several minutes of streaming HOT 3
- Distorted and interrupted sound with 24/94 HOT 6
- Streams tops if input delivers no more data HOT 25
- SWYH-SSDP Maximum Interval Question HOT 6
- Missing VCRUNTIME140.ddl HOT 3
- Changing audio output when connecting external monitor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swyh-rs.