Is there any way to compensate for drift between the css event.elapsedTime with the time passed in the play method of an AudioContext note?Sound effects in JavaScript / HTML5Best way to play/pause/seek large audio files with precision in Web Audio APIHalf speed AudioContext from microphone when written to serverJavascript timer memory leakmost efficient way to generate sound with web audio apiIn web audio, when is AudioContext.currentTime updated?HTML5 audio streaming: precisely measure latency?Loading audio files through URLs from remote locations (Opera)?Is there a better solution than setInterval when I need the interval to be very precise over time?AudioContext how to play the notes in a sequence

Where Does VDD+0.3V Input Limit Come From on IC chips?

Algorithm that spans orthogonal vectors: Python

Is it true that, "just ten trading days represent 63 per cent of the returns of the past 50 years"?

Temporarily moving a SQL Server 2016 database to SQL Server 2017 and then moving back. Is it possible?

What did the controller say during my approach to land (audio clip)?

Is this a Sherman, and if so what model?

Minimize taxes now that I earn more

Repeat elements in list, but the number of times each element is repeated is provided by a separate list

Nanomachines exist that enable Axolotl-levels of regeneration - So how can crippling injuries exist as well?

I feel like most of my characters are the same, what can I do?

Manager encourages me to take day of sick leave instead of PTO, what's in it for him?

The 100 soldier problem

Do the villains know Batman has no superpowers?

Paradox regarding phase transitions in relativistic systems

Pseudo Game of Cups in Python

Can planetary bodies have a second axis of rotation?

Is there an in-universe reason Harry says this or is this simply a Rowling mistake?

How would a native speaker correct themselves when they misspeak?

Simulate a 1D Game-of-Life-ish Model

Are there hydrocarbons on the Moon?

As an employer, can I compel my employees to vote?

Is there a builtin function to turn selective Echos off?

Social leper versus social leopard

Is there any reason nowadays to use a neon indicator lamp instead of an LED?



Is there any way to compensate for drift between the css event.elapsedTime with the time passed in the play method of an AudioContext note?


Sound effects in JavaScript / HTML5Best way to play/pause/seek large audio files with precision in Web Audio APIHalf speed AudioContext from microphone when written to serverJavascript timer memory leakmost efficient way to generate sound with web audio apiIn web audio, when is AudioContext.currentTime updated?HTML5 audio streaming: precisely measure latency?Loading audio files through URLs from remote locations (Opera)?Is there a better solution than setInterval when I need the interval to be very precise over time?AudioContext how to play the notes in a sequence






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















From my tests, and from searching to find out more about the problem, my best guess is that css animations may be using a different physical clock from the one used to stream audio. If so perhaps the answer to this is that it can't be done, but am asking in case I am missing anything.



It is for my online metronome here.



It is able to plays notes reasonably accurately in response to an event listener for the css animationiteration event. The eventlistener is set up using e.g.
x.addEventListener("animationstart",playSoundBall2);



See here.



However if I try to synchronize the bounce with the sample precise timing of the AudioContext method that's when I run into problems.



What I do is to use the first css callback just to record the audio context time for the css elapsed time of 0. Then I play the notes using the likes of:



oscillator.start(desired_start_time);



You can try it out with the option on the page: "Schedule notes in advance for sample-precise timing of the audio" on the page here.



You can check how much it drifts by switching on "Add debug info to extra info" on the same page.



On my development machine it works fine with Firefox. But on Edge and Chrome it drifts away from the bounce. And not in a steady way. Can be fine for several minutes and then the bounce starts to slow down relative to the audio stream.



It is not a problem with browser activity - if I move the browser around and try to interrupt the animation the worst that happens is that it may drop notes and if the browser isn't active it is liable to drop notes. But the ones it plays are exactly in time.



My best guess so far, is that it might be that the browser is using the system time, while the audiocontext play method is scheduling it at a precise point in a continuous audio stream. Those may well be using different hardware clocks, from online searches for the problem.



Firefox may for some reason be using the same hardware clock, maybe just on my development machine.



If this is correct, it rather looks as if there is no way to guarantee to precisely synchronize html audio played using AudioContext with css animations.



If that is so I would also think you probably can't guarantee to synchronize it with any javascript animations as it would depend on which clocks the browser uses for the animations, and how that relates to whatever clock is used for streaming audio.



But can this really be the case? What do animators do who need to synchronize sound with animations for long periods of time? Or do they only ever synchronize them for a few minutes at a time?



I wouldn't have noticed if it weren't that the metronome naturally is used for long periods at a time. It can get so bad that the click is several seconds out from the bounce after just two or three minutes.



At other times - well while writing this I've had the metronome going for ten minutes in my Windows 10 app and it has drifted, but only by 20-30 ms relative to the bounce. So it is very irregular, so you can't hope to solve this by adding in some fixed speed up or slow down to get them in time with each other.



I am writing this just in case there is a way to do this in javascript, anything I'm missing. I'm also interested to know if it makes any difference if I use other methods of animation. I can't see how one could use the audio context clock directly for animation as you can only schedule notes in the audio stream, can't schedule a callback at a particular exact time in the future according to the audio stream.










share|improve this question
































    1















    From my tests, and from searching to find out more about the problem, my best guess is that css animations may be using a different physical clock from the one used to stream audio. If so perhaps the answer to this is that it can't be done, but am asking in case I am missing anything.



    It is for my online metronome here.



    It is able to plays notes reasonably accurately in response to an event listener for the css animationiteration event. The eventlistener is set up using e.g.
    x.addEventListener("animationstart",playSoundBall2);



    See here.



    However if I try to synchronize the bounce with the sample precise timing of the AudioContext method that's when I run into problems.



    What I do is to use the first css callback just to record the audio context time for the css elapsed time of 0. Then I play the notes using the likes of:



    oscillator.start(desired_start_time);



    You can try it out with the option on the page: "Schedule notes in advance for sample-precise timing of the audio" on the page here.



    You can check how much it drifts by switching on "Add debug info to extra info" on the same page.



    On my development machine it works fine with Firefox. But on Edge and Chrome it drifts away from the bounce. And not in a steady way. Can be fine for several minutes and then the bounce starts to slow down relative to the audio stream.



    It is not a problem with browser activity - if I move the browser around and try to interrupt the animation the worst that happens is that it may drop notes and if the browser isn't active it is liable to drop notes. But the ones it plays are exactly in time.



    My best guess so far, is that it might be that the browser is using the system time, while the audiocontext play method is scheduling it at a precise point in a continuous audio stream. Those may well be using different hardware clocks, from online searches for the problem.



    Firefox may for some reason be using the same hardware clock, maybe just on my development machine.



    If this is correct, it rather looks as if there is no way to guarantee to precisely synchronize html audio played using AudioContext with css animations.



    If that is so I would also think you probably can't guarantee to synchronize it with any javascript animations as it would depend on which clocks the browser uses for the animations, and how that relates to whatever clock is used for streaming audio.



    But can this really be the case? What do animators do who need to synchronize sound with animations for long periods of time? Or do they only ever synchronize them for a few minutes at a time?



    I wouldn't have noticed if it weren't that the metronome naturally is used for long periods at a time. It can get so bad that the click is several seconds out from the bounce after just two or three minutes.



    At other times - well while writing this I've had the metronome going for ten minutes in my Windows 10 app and it has drifted, but only by 20-30 ms relative to the bounce. So it is very irregular, so you can't hope to solve this by adding in some fixed speed up or slow down to get them in time with each other.



    I am writing this just in case there is a way to do this in javascript, anything I'm missing. I'm also interested to know if it makes any difference if I use other methods of animation. I can't see how one could use the audio context clock directly for animation as you can only schedule notes in the audio stream, can't schedule a callback at a particular exact time in the future according to the audio stream.










    share|improve this question




























      1












      1








      1








      From my tests, and from searching to find out more about the problem, my best guess is that css animations may be using a different physical clock from the one used to stream audio. If so perhaps the answer to this is that it can't be done, but am asking in case I am missing anything.



      It is for my online metronome here.



      It is able to plays notes reasonably accurately in response to an event listener for the css animationiteration event. The eventlistener is set up using e.g.
      x.addEventListener("animationstart",playSoundBall2);



      See here.



      However if I try to synchronize the bounce with the sample precise timing of the AudioContext method that's when I run into problems.



      What I do is to use the first css callback just to record the audio context time for the css elapsed time of 0. Then I play the notes using the likes of:



      oscillator.start(desired_start_time);



      You can try it out with the option on the page: "Schedule notes in advance for sample-precise timing of the audio" on the page here.



      You can check how much it drifts by switching on "Add debug info to extra info" on the same page.



      On my development machine it works fine with Firefox. But on Edge and Chrome it drifts away from the bounce. And not in a steady way. Can be fine for several minutes and then the bounce starts to slow down relative to the audio stream.



      It is not a problem with browser activity - if I move the browser around and try to interrupt the animation the worst that happens is that it may drop notes and if the browser isn't active it is liable to drop notes. But the ones it plays are exactly in time.



      My best guess so far, is that it might be that the browser is using the system time, while the audiocontext play method is scheduling it at a precise point in a continuous audio stream. Those may well be using different hardware clocks, from online searches for the problem.



      Firefox may for some reason be using the same hardware clock, maybe just on my development machine.



      If this is correct, it rather looks as if there is no way to guarantee to precisely synchronize html audio played using AudioContext with css animations.



      If that is so I would also think you probably can't guarantee to synchronize it with any javascript animations as it would depend on which clocks the browser uses for the animations, and how that relates to whatever clock is used for streaming audio.



      But can this really be the case? What do animators do who need to synchronize sound with animations for long periods of time? Or do they only ever synchronize them for a few minutes at a time?



      I wouldn't have noticed if it weren't that the metronome naturally is used for long periods at a time. It can get so bad that the click is several seconds out from the bounce after just two or three minutes.



      At other times - well while writing this I've had the metronome going for ten minutes in my Windows 10 app and it has drifted, but only by 20-30 ms relative to the bounce. So it is very irregular, so you can't hope to solve this by adding in some fixed speed up or slow down to get them in time with each other.



      I am writing this just in case there is a way to do this in javascript, anything I'm missing. I'm also interested to know if it makes any difference if I use other methods of animation. I can't see how one could use the audio context clock directly for animation as you can only schedule notes in the audio stream, can't schedule a callback at a particular exact time in the future according to the audio stream.










      share|improve this question
















      From my tests, and from searching to find out more about the problem, my best guess is that css animations may be using a different physical clock from the one used to stream audio. If so perhaps the answer to this is that it can't be done, but am asking in case I am missing anything.



      It is for my online metronome here.



      It is able to plays notes reasonably accurately in response to an event listener for the css animationiteration event. The eventlistener is set up using e.g.
      x.addEventListener("animationstart",playSoundBall2);



      See here.



      However if I try to synchronize the bounce with the sample precise timing of the AudioContext method that's when I run into problems.



      What I do is to use the first css callback just to record the audio context time for the css elapsed time of 0. Then I play the notes using the likes of:



      oscillator.start(desired_start_time);



      You can try it out with the option on the page: "Schedule notes in advance for sample-precise timing of the audio" on the page here.



      You can check how much it drifts by switching on "Add debug info to extra info" on the same page.



      On my development machine it works fine with Firefox. But on Edge and Chrome it drifts away from the bounce. And not in a steady way. Can be fine for several minutes and then the bounce starts to slow down relative to the audio stream.



      It is not a problem with browser activity - if I move the browser around and try to interrupt the animation the worst that happens is that it may drop notes and if the browser isn't active it is liable to drop notes. But the ones it plays are exactly in time.



      My best guess so far, is that it might be that the browser is using the system time, while the audiocontext play method is scheduling it at a precise point in a continuous audio stream. Those may well be using different hardware clocks, from online searches for the problem.



      Firefox may for some reason be using the same hardware clock, maybe just on my development machine.



      If this is correct, it rather looks as if there is no way to guarantee to precisely synchronize html audio played using AudioContext with css animations.



      If that is so I would also think you probably can't guarantee to synchronize it with any javascript animations as it would depend on which clocks the browser uses for the animations, and how that relates to whatever clock is used for streaming audio.



      But can this really be the case? What do animators do who need to synchronize sound with animations for long periods of time? Or do they only ever synchronize them for a few minutes at a time?



      I wouldn't have noticed if it weren't that the metronome naturally is used for long periods at a time. It can get so bad that the click is several seconds out from the bounce after just two or three minutes.



      At other times - well while writing this I've had the metronome going for ten minutes in my Windows 10 app and it has drifted, but only by 20-30 ms relative to the bounce. So it is very irregular, so you can't hope to solve this by adding in some fixed speed up or slow down to get them in time with each other.



      I am writing this just in case there is a way to do this in javascript, anything I'm missing. I'm also interested to know if it makes any difference if I use other methods of animation. I can't see how one could use the audio context clock directly for animation as you can only schedule notes in the audio stream, can't schedule a callback at a particular exact time in the future according to the audio stream.







      javascript audiocontext






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 15:12







      Robert Walker

















      asked Mar 28 at 15:04









      Robert WalkerRobert Walker

      1063 bronze badges




      1063 bronze badges

























          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400882%2fis-there-any-way-to-compensate-for-drift-between-the-css-event-elapsedtime-with%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400882%2fis-there-any-way-to-compensate-for-drift-between-the-css-event-elapsedtime-with%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript