question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about the timePosition resolution in AlphaSynth

See original GitHub issue

Your environment

  • Version used: master branch
  • Platform used: JavaScript
  • Rendering engine used: SVG
  • Browser Name and Version: Chrome Version 59.0.3071.115
  • Operating System and version (desktop or mobile): Windows 10

Expected Results

Is there a way to get a more precise result than as.get_TimePosition() ?

I don’t know much about how the sequencer works, so tell be if there is no easy way to do this. However I imagine the timing must be very precise in the sequencer, so the get_TimePosition API call may not be the most precise.

Observed Results

The precision is currently approximately 0.09 second. i.e if we call 100 times the get_timePosition method in a second, we’ll have only 11 or 12 different values.

What I’m trying to do

I’me building a metronome sound. What I’ve done is retrieving the _tempoChanges from the sequencer. I use that to construct an array with all the precise times where a click sound has to be played. (By the way, here is what I’ve done to get the tempo changes: https://github.com/j4kim/alphaTab/commit/6f4eaffff0a0b0533eb9f3df38e9ca9c0e75bf6d, please tell me if there is a simpler way) Then, I need to know where I am in the score to properly progam the next metronome sound (using setTimeout or requestAnimationFrame). For the moment it works but the precision of the AlphaSynth time creates accumulative delay. metronome delay (“retard” means delay)

Possible Solution

If there is no way, I will consider a solution using javascript’s timestamp (performaces.now()).

Of course I’m also listening to your advices if you have other ideas.

Thank’s again for this amazing work !

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Danielku15commented, Jul 17, 2017

My bad. I forgot to handle the new metronome events at the silent processing needed for seeking. 😅 The problem should be solved now…

0reactions
ice-blazecommented, Feb 19, 2018

It’s still in an experimental state but outputLatency is maybe the solution in the future https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/outputLatency

I also wanted to share this very good article about latency https://www.html5rocks.com/en/tutorials/audio/scheduling/

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found