FirstLegoLeague / clock

Countdown clock for competition area
GNU General Public License v3.0
3 stars 15 forks source link

Playing sound delayed #48

Closed gwgorman closed 4 years ago

gwgorman commented 5 years ago

This may be related to one that I put on the server side of Tournament - we are seeing the clock hit 0:00 and then the sound plays a noticeable time later. Looking at the code in server/sounds.js it looks like this: function playSound (file) { logger.debug(Playing sound file: ${file}) return player.playAsync(file) }

What is the time delay / response of logger? We are using networked computers so there is some finite response time, and this could be the source of the perceived delay. Not sure the best way to test this, but at our next tournament I'll disable logging completely. Might even be good to initiate the sound first (since it's async) and then call logger.

alanggreen commented 5 years ago

Thanks for looking at the code and pointing this out as a possible source of the problem. My feeling is that the source of the problem is somewhere else. As far as we can see, node.js requires an external player to play sounds, and it seems to me the delay is a result of the time it takes to spawn this process. We are using mplayer.exe and the time taken is related to how long it takes the OS to run mplayer. @2roy999 do you agree? We have a development task open aimed at looking for a better solution.

Putting the logger after the play command is a good idea in any case.

Unfortunately because of the way our components/modules handle logs, changing the level to INFO or WARN will not reduce the effort involved in processing the log.

gwgorman commented 5 years ago

hey Alan, thanks for the update. Yeah I was wondering, especially since it's always a network operation. And yes there is a pretty significant overhead when starting a process, especially on Windows. I'll keep my ears open about other solutions as well, I've got a similar issue on a RPi project I'm working on.

alanggreen commented 5 years ago

It's a network operation, kind of, because the button press happens in the browser and the timer is in the backend. But we have noticed the same behavior when it's all on the same PC. The fact that the sound is delayed with respect to the countdown display leads me to think it's the process issue. Any solutions you can suggest , especially about playing sounds in node.js natively, would be most welcome.

2roy999 commented 5 years ago

Yes, It will help for now. A broader solution would be to redesign the logger to log the message asynchronously.

On Wed, Dec 12, 2018, 16:09 Alan Green <notifications@github.com wrote:

Thanks for looking at the code and pointing this out as a possible source of the problem. My feeling is that the source of the problem is somewhere else. As far as we can see, node.js requires an external player to play sounds, and it seems to me the delay is a result of the time it takes to spawn this process. We are using mplayer.exe and the time taken is related to how long it takes the OS to run mplayer. @2roy999 https://github.com/2roy999 do you agree? We have a development task open aimed at looking for a better solution.

Putting the logger after the play command is a good idea in any case.

Unfortunately because of the way our components/modules handle logs, changing the level to INFO or WARN will not reduce the effort involved in processing the log.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FirstLegoLeague/clock/issues/48#issuecomment-446600274, or mute the thread https://github.com/notifications/unsubscribe-auth/ACxO-chMoz5SY5_LbG6sBQZhtlAFJB2Qks5u4Q43gaJpZM4ZONLP .

gwgorman commented 5 years ago

Polled my developer advocates (some of whom are contributors to Node) and they pointed me to https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

I'll fiddle with this a little unless you guys have already thrown this out as a solution.

gwgorman commented 5 years ago

the other package they suggested is this https://www.npmjs.com/package/node-mp3-player which looks like it uses the Audio API at the bottom. It does spawn processes but the way it looks to me is that it is done at instantiation so that it can respond pretty quickly.

alanggreen commented 5 years ago

I'll fiddle with this a little unless you guys have already thrown this out as a solution.

Any help would be most welcome. We're a very small team Remember that we generate the audio in the backend. I'll take a look at your links later on today.

gwgorman commented 4 years ago

I think you have solved this - seems to be working pretty well now in the 2019 version. Nice job!