surikov/webaudiofont

noise

Closed this issue · 3 comments

Describe the bug
Annoying sound when running the code

To Reproduce
Steps to reproduce the behavior:

  1. pressing on start

Expected behavior
I am trying to build music that receives the notes information from the API and plays it using the code mentioned in the example on the following link.

https://surikov.github.io/webaudiofont/examples/realtime.html

When I reduce the number of sent notes the problem disappears, but when the charge of my device is low, even if it is a few notes, noise and noise come out.

Screenshots
I will attach a video

Desktop (please complete the following information):

  • Browser [chrome] Version [96.0.4664.4
    code.txt
    5 (Official Build) (64-bit)]

Additional context
I will attach the code and the data sent from the API you can run the code directly and hear the problem, Please change the file extension to HTML
code.txt

bug.mp4

Look to code of original example.

You changed it.
You created endless loop that sends to the player millions notes per second.

Change it back. You need to send notes for next time piece only.

Original function. Look to 'setInterval'

function start() {
  if (started) {
	  console.log('started already');
  } else {
	  started = true;
	  startTime = audioContext.currentTime + 0.1;
	  nextPiece();
	  startTime = startTime + pieceLen;
	  setInterval(function () {
		  if (audioContext.currentTime > startTime - 1 / 4 * N) {
			  nextPiece();
			  startTime = startTime + pieceLen;
		  }
	  }, 20);
  }
}

I see scheduling is too hard task.
I added new class for scheduling, look to WebAudioFontTicker at
https://github.com/surikov/webaudiofont/wiki

Nice. Would be handy to have the ticker functions on the wiki.