TooTallNate / node-speaker

Output PCM audio data to the speakers
648 stars 145 forks source link

Switch the backend from mpg123 to libao #111

Open ezequielgarcia opened 6 years ago

ezequielgarcia commented 6 years ago

As already discussed in RFC #101 , here is my proposal to ditch mpg123 and use libao instead. Carrying mpg123 meant maintaining it as a dependency, tracking down fixes, and worrying about potential upstreaming of changes or API changes.

On the other hand, with libao as backend we can keep it as an external binary dependency, and not worry about maintaining it. libao is a good match for node-speaker given its multiplatform support. Also, the API is very simple, which also matches node-speaker simple needs.

This PR removes some module exported functions, which are no longer meaningful with libao as backend:

Speaker.api_version
Speaker.description
Speaker.module_name
Speaker.getFormat
Speaker.isSupported

Tested with pulseaudio plugin on Archlinux. All tests passes:

$ npm test
  exports
    ✓ should export a Function

  Speaker
    ✓ should return a Speaker instance
    ✓ should be a writable stream
    ✓ should emit an "open" event after the first write()
    ✓ should emit a "close" event after end()
    ✓ should only emit one "close" event

  6 passing (34ms)
ezequielgarcia commented 6 years ago

@LinusU @TooTallNate @MexXxo Bringing this to your attention. Any help testing is much appreciated. Sorry for the delay, I had to take care of merging proper dlopen support for libao plugins to work everywhere. It happened in https://github.com/nodejs/node/pull/12794, and got included in node 9.

TooTallNate commented 6 years ago

This is pretty cool @ezequielgarcia, great work!

LinusU commented 6 years ago

Haven't had time to look at it properly, but it seems awesome 👍

Flowr-es commented 6 years ago

Hi, I will try it this weekend and provide some feedback

Flowr-es commented 6 years ago

@ezequielgarcia finally I have tested your PR. I integrated it into a working system that used the speaker with mpg123 and the only diffenrence is now that the sound sometimes has a minimal delay (100ms) <--- I guess this is related to the not available (internal) method to flush the speaker. I actually found this a lack of the current module that it is not possible to immediatly stop the speaker, is it possible to include a method in this module?

Things I have found: the links for Bugs and Homepage in the package.json are not pointing to the destination repo ;) That needs to be changed for accepting the PR.

Also I would suggest to add a contributors array of LinusU and you, as you both are taking care of this, you deserve some props 👍

I tested it with node 6 on a raspberry pi. The package gets not installed if libao has not been installed before. Is it possible to improve the error message? Currently the only meaningful in the 50 lines of error is one line that says "no package ao found".

Flowr-es commented 6 years ago

Also an entry in the history.md is missing

Flowr-es commented 6 years ago

So I have your libao PR now since a month in use on my raspi. What I could observe that there is sometimes (not very often) a short loud noise (like 1 second). Maybe it is related to some internal methods I'm using of the speaker module or that some audio chunks are somehow misinterpretet. Nevertheless with the same code using the mpg123 speaker module I had not such issues.

Till now I have not observed any reproducible way for this issue. Once I know more I will let you know.

ezequielgarcia commented 6 years ago

Hi guys @LinusU @TooTallNate @MexXxo !

Sorry for the huge delay: new job, lots to do. I have spent quite a bit of time re-considering this PR, and re-considering libao in particular. Leaving aside @MexXxo's issues, I am now changing my mind regarding libao.

My biggest concern is that it seems kind of dead, kind of unmaintained. Last official release was v1.2.0 - January 27, 2014. There is some activity on github, last commit was in January, 2018. I am under the impression that mpg123 is slightly more maintained (although since we are bundling here, it means manual syncing is required).

In the end, it seems nor mpg123, neither libao is super maintained, and that both come with their own set of issues.