From 1b64652f21cfa8ef47ee44a48bbdc8b6bbea6bfb Mon Sep 17 00:00:00 2001 From: velvettear Date: Wed, 27 Apr 2022 16:10:01 +0200 Subject: [PATCH] removed unnecessary parts of lib 'speaker' --- .gitignore | 3 +- libs/speaker/build/Makefile | 2 +- libs/speaker/examples/sine.js | 60 --------------- libs/speaker/examples/stdin.js | 10 --- libs/speaker/package-lock.json | 39 ---------- libs/speaker/test/test.js | 131 --------------------------------- package-lock.json | 1 + package.json | 4 +- 8 files changed, 7 insertions(+), 243 deletions(-) delete mode 100644 libs/speaker/examples/sine.js delete mode 100644 libs/speaker/examples/stdin.js delete mode 100644 libs/speaker/test/test.js diff --git a/.gitignore b/.gitignore index d2d5986..e63890d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config.json node_modules/ -npm-debug.log \ No newline at end of file +npm-debug.log +libs/speaker/build/ \ No newline at end of file diff --git a/libs/speaker/build/Makefile b/libs/speaker/build/Makefile index 0c3dd35..1770f31 100644 --- a/libs/speaker/build/Makefile +++ b/libs/speaker/build/Makefile @@ -329,7 +329,7 @@ endif quiet_cmd_regen_makefile = ACTION Regenerating $@ cmd_regen_makefile = cd $(srcdir); /home/velvettear/.nvm/versions/node/v18.0.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/home/velvettear/.cache/node-gyp/18.0.0" "-Dnode_gyp_dir=/home/velvettear/.nvm/versions/node/v18.0.0/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/home/velvettear/.cache/node-gyp/18.0.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/home/velvettear/development/nodejs/kannon-client/libs/speaker" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/home/velvettear/development/nodejs/kannon-client/libs/speaker/build/config.gypi -I/home/velvettear/.nvm/versions/node/v18.0.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/home/velvettear/.cache/node-gyp/18.0.0/include/node/common.gypi "--toplevel-dir=." binding.gyp -Makefile: $(srcdir)/binding.gyp $(srcdir)/build/config.gypi $(srcdir)/../../../../../.cache/node-gyp/18.0.0/include/node/common.gypi $(srcdir)/deps/mpg123/mpg123.gyp $(srcdir)/../../../../../.nvm/versions/node/v18.0.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi +Makefile: $(srcdir)/deps/mpg123/mpg123.gyp $(srcdir)/binding.gyp $(srcdir)/build/config.gypi $(srcdir)/../../../../../.cache/node-gyp/18.0.0/include/node/common.gypi $(srcdir)/../../../../../.nvm/versions/node/v18.0.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(call do_cmd,regen_makefile) # "all" is a concatenation of the "all" targets from all the included diff --git a/libs/speaker/examples/sine.js b/libs/speaker/examples/sine.js deleted file mode 100644 index 42e29b3..0000000 --- a/libs/speaker/examples/sine.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict' - -/** - * Code adapted from: - * https://web.archive.org/web/20110816002016/http://blogs.msdn.com/b/dawate/archive/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c.aspx - */ - -const Readable = require('stream').Readable -const bufferAlloc = require('buffer-alloc') -const Speaker = require('../') - -// the frequency to play -const freq = parseFloat(process.argv[2], 10) || 440.0 // Concert A, default tone - -// seconds worth of audio data to generate before emitting "end" -const duration = parseFloat(process.argv[3], 10) || 2.0 - -console.log('generating a %dhz sine wave for %d seconds', freq, duration) - -// A SineWaveGenerator readable stream -const sine = new Readable() -sine.bitDepth = 16 -sine.channels = 2 -sine.sampleRate = 44100 -sine.samplesGenerated = 0 -sine._read = read - -// create a SineWaveGenerator instance and pipe it to the speaker -sine.pipe(new Speaker()) - -// the Readable "_read()" callback function -function read (n) { - const sampleSize = this.bitDepth / 8 - const blockAlign = sampleSize * this.channels - const numSamples = n / blockAlign | 0 - const buf = bufferAlloc(numSamples * blockAlign) - const amplitude = 32760 // Max amplitude for 16-bit audio - - // the "angle" used in the function, adjusted for the number of - // channels and sample rate. This value is like the period of the wave. - const t = (Math.PI * 2 * freq) / this.sampleRate - - for (let i = 0; i < numSamples; i++) { - // fill with a simple sine wave at max amplitude - for (let channel = 0; channel < this.channels; channel++) { - const s = this.samplesGenerated + i - const val = Math.round(amplitude * Math.sin(t * s)) // sine wave - const offset = (i * sampleSize * this.channels) + (channel * sampleSize) - buf[`writeInt${this.bitDepth}LE`](val, offset) - } - } - - this.push(buf) - - this.samplesGenerated += numSamples - if (this.samplesGenerated >= this.sampleRate * duration) { - // after generating "duration" second of audio, emit "end" - this.push(null) - } -} diff --git a/libs/speaker/examples/stdin.js b/libs/speaker/examples/stdin.js deleted file mode 100644 index c9473a4..0000000 --- a/libs/speaker/examples/stdin.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -/** - * Pipe data to stdin and it will be played through your speakers. - */ - -const Speaker = require('../') - -const speaker = new Speaker() -process.stdin.pipe(speaker) diff --git a/libs/speaker/package-lock.json b/libs/speaker/package-lock.json index 82dd32a..ee34905 100644 --- a/libs/speaker/package-lock.json +++ b/libs/speaker/package-lock.json @@ -10,7 +10,6 @@ "license": "(MIT AND LGPL-2.1-only)", "dependencies": { "bindings": "^1.3.0", - "buffer-alloc": "^1.1.0", "debug": "^4.0.0" }, "devDependencies": { @@ -224,25 +223,6 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, - "node_modules/buffer-alloc": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", - "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", - "dependencies": { - "buffer-alloc-unsafe": "^1.1.0", - "buffer-fill": "^1.0.0" - } - }, - "node_modules/buffer-alloc-unsafe": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", - "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==" - }, - "node_modules/buffer-fill": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", - "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=" - }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -3546,25 +3526,6 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, - "buffer-alloc": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", - "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", - "requires": { - "buffer-alloc-unsafe": "^1.1.0", - "buffer-fill": "^1.0.0" - } - }, - "buffer-alloc-unsafe": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", - "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==" - }, - "buffer-fill": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", - "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=" - }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", diff --git a/libs/speaker/test/test.js b/libs/speaker/test/test.js deleted file mode 100644 index 761bb8d..0000000 --- a/libs/speaker/test/test.js +++ /dev/null @@ -1,131 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -/** - * Module dependencies. - */ - -const os = require('os') -const assert = require('assert') -const Speaker = require('../') - -const endianness = os.endianness() -const opposite = endianness === 'LE' ? 'BE' : 'LE' - -describe('exports', function () { - it('should export a Function', function () { - assert.strictEqual('function', typeof Speaker) - }) - - it('should have an "api_version" property', function () { - assert(Object.prototype.hasOwnProperty.call(Speaker, 'api_version')) - assert('number', typeof Speaker.api_version) - }) - - it('should have a "description" property', function () { - assert(Object.prototype.hasOwnProperty.call(Speaker, 'description')) - assert('string', typeof Speaker.description) - }) - - it('should have a "module_name" property', function () { - assert(Object.prototype.hasOwnProperty.call(Speaker, 'module_name')) - assert('string', typeof Speaker.module_name) - }) -}) - -describe('Speaker', function () { - it('should return a Speaker instance', function () { - const s = new Speaker() - assert(s instanceof Speaker) - }) - - it('should be a writable stream', function () { - const s = new Speaker() - assert.strictEqual(s.writable, true) - assert.notStrictEqual(s.readable, true) - }) - - it('should emit an "open" event after the first write()', function (done) { - const s = new Speaker() - let called = false - s.on('open', function () { - called = true - done() - }) - assert.strictEqual(called, false) - s.write(Buffer.alloc(0)) - }) - - it('should emit a "flush" event after end()', function (done) { - const s = new Speaker() - let called = false - s.on('flush', function () { - called = true - done() - }) - assert.strictEqual(called, false) - s.end(Buffer.alloc(0)) - }) - - it('should emit a "close" event after end()', function (done) { - this.slow(1000) - const s = new Speaker() - let called = false - s.on('close', function () { - called = true - done() - }) - assert.strictEqual(called, false) - s.end(Buffer.alloc(0)) - }) - - it('should only emit one "close" event', function (done) { - const s = new Speaker() - let count = 0 - s.on('close', function () { - count++ - }) - assert.strictEqual(0, count) - s.close() - assert.strictEqual(1, count) - s.close() - assert.strictEqual(1, count) - done() - }) - - it('should accept a device option', function (done) { - const s = new Speaker({ device: 'test' }) - - assert.strictEqual(s.device, 'test') - - s.on('close', done) - s.end(Buffer.alloc(0)) - }) - - it('should not throw an Error if native "endianness" is specified', function () { - assert.doesNotThrow(function () { - // eslint-disable-next-line no-new - new Speaker({ endianness: endianness }) - }) - }) - - it('should throw an Error if non-native "endianness" is specified', function () { - assert.throws(function () { - // eslint-disable-next-line no-new - new Speaker({ endianness: opposite }) - }) - }) - - it('should throw an Error if a non-supported "format" is specified', function (done) { - const speaker = new Speaker({ - bitDepth: 31, - signed: true - }) - speaker.once('error', (err) => { - assert.strictEqual('invalid PCM format specified', err.message) - done() - }) - speaker.write('a') - }) -}) diff --git a/package-lock.json b/package-lock.json index 5c4acfc..8b4d052 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "kannon-client", "version": "0.0.1", + "hasInstallScript": true, "license": "MIT", "dependencies": { "moment": "^2.29.1" diff --git a/package.json b/package.json index 8cb61f5..5be9c23 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "0.0.1", "description": "a multi room audio player", "main": "kannon-client.js", - "scripts": {}, + "scripts": { + "postinstall": "(cd libs/speaker && npm install);" + }, "keywords": [ "audio", "player",