@lox-audioserver/node-slimproto 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/volume.js ADDED
@@ -0,0 +1,59 @@
1
+ export class SlimProtoVolume {
2
+ minimum = 0;
3
+ maximum = 100;
4
+ step = 1;
5
+ static oldMap = [
6
+ 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15,
7
+ 16, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 37,
8
+ 38, 39, 40, 42, 43, 44, 46, 47, 48, 50, 51, 53, 54, 56, 57, 59, 60, 61, 63, 65,
9
+ 66, 68, 69, 71, 72, 74, 75, 77, 79, 80, 82, 84, 85, 87, 89, 90, 92, 94, 96, 97,
10
+ 99, 101, 103, 104, 106, 108, 110, 112, 113, 115, 117, 119, 121, 123, 125, 127,
11
+ 128,
12
+ ];
13
+ totalVolumeRange = -50; // dB
14
+ stepPoint = -1;
15
+ stepFraction = 1;
16
+ volume = 50;
17
+ increment() {
18
+ this.volume = Math.min(this.volume + this.step, this.maximum);
19
+ }
20
+ decrement() {
21
+ this.volume = Math.max(this.volume - this.step, this.minimum);
22
+ }
23
+ oldGain() {
24
+ if (this.volume <= 0)
25
+ return 0;
26
+ return SlimProtoVolume.oldMap[this.volume];
27
+ }
28
+ decibels() {
29
+ const stepDb = this.totalVolumeRange * this.stepFraction;
30
+ const maxVolumeDb = 0;
31
+ const slopeHigh = maxVolumeDb - stepDb / (100 - this.stepPoint);
32
+ const slopeLow = stepDb - this.totalVolumeRange / (this.stepPoint - 0.0);
33
+ const x2 = this.volume;
34
+ let m;
35
+ let x1;
36
+ let y1;
37
+ if (x2 > this.stepPoint) {
38
+ m = slopeHigh;
39
+ x1 = 100;
40
+ y1 = maxVolumeDb;
41
+ }
42
+ else {
43
+ m = slopeLow;
44
+ x1 = 0;
45
+ y1 = this.totalVolumeRange;
46
+ }
47
+ return m * (x2 - x1) + y1;
48
+ }
49
+ newGain() {
50
+ if (this.volume <= 0)
51
+ return 0;
52
+ const decibel = this.decibels();
53
+ const floatmult = 10 ** (decibel / 20.0);
54
+ if (decibel >= -30 && decibel <= 0) {
55
+ return Math.trunc(floatmult * (1 << 8) + 0.5) * (1 << 8);
56
+ }
57
+ return Math.trunc(floatmult * (1 << 16) + 0.5);
58
+ }
59
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@lox-audioserver/node-slimproto",
3
+ "version": "0.1.0",
4
+ "description": "SlimProto server/client utilities for controlling Squeezebox-compatible players in Node.js.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig.json",
13
+ "clean": "rm -rf dist",
14
+ "prepare": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "slimproto",
18
+ "squeezebox",
19
+ "audio",
20
+ "async"
21
+ ],
22
+ "author": "",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "@types/node": "^22.5.1",
26
+ "typescript": "^5.5.4"
27
+ }
28
+ }