GithubHelp home page GithubHelp logo

Comments (13)

dheijl avatar dheijl commented on August 30, 2024

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.

stewartsiu avatar stewartsiu commented on August 30, 2024

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.

dheijl avatar dheijl commented on August 30, 2024

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.

stewartsiu avatar stewartsiu commented on August 30, 2024

from swyh-rs.

stewartsiu avatar stewartsiu commented on August 30, 2024

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.

dheijl avatar dheijl commented on August 30, 2024

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.

stewartsiu avatar stewartsiu commented on August 30, 2024

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.

dheijl avatar dheijl commented on August 30, 2024

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.

stewartsiu avatar stewartsiu commented on August 30, 2024

... 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.

dheijl avatar dheijl commented on August 30, 2024

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.

dheijl avatar dheijl commented on August 30, 2024

I'll close this now, but feel free to reopen if you have new information.

from swyh-rs.

stewartsiu avatar stewartsiu commented on August 30, 2024

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.

dheijl avatar dheijl commented on August 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.