tone-stream 1.10.0 → 1.11.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/index.js +12 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const DTMF = require("./lib/dtmf");
|
|
|
7
7
|
const EventEmitter = require('events');
|
|
8
8
|
|
|
9
9
|
class ToneStream extends Readable {
|
|
10
|
-
constructor(format
|
|
10
|
+
constructor(format) {
|
|
11
11
|
super();
|
|
12
12
|
|
|
13
13
|
if (format) {
|
|
@@ -21,8 +21,6 @@ class ToneStream extends Readable {
|
|
|
21
21
|
this.channels = 1;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
this.opts = opts;
|
|
25
|
-
|
|
26
24
|
this.amplitude = 2 ** this.bitDepth / 2 - 1;
|
|
27
25
|
|
|
28
26
|
this.specReadStream = new SpecReadStream();
|
|
@@ -37,13 +35,18 @@ class ToneStream extends Readable {
|
|
|
37
35
|
add(spec) {
|
|
38
36
|
this.specReadStream.add(spec);
|
|
39
37
|
this.pending_ended = true
|
|
38
|
+
var num_samples = spec[0]
|
|
39
|
+
return num_samples
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
concat(specs) {
|
|
43
|
+
var num_samples = 0
|
|
43
44
|
specs.forEach((spec) => {
|
|
44
45
|
this.specReadStream.add(spec);
|
|
46
|
+
num_samples += spec[0]
|
|
45
47
|
});
|
|
46
48
|
this.pending_ended = true
|
|
49
|
+
return num_samples
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
on(evt, cb) {
|
|
@@ -80,17 +83,14 @@ class ToneStream extends Readable {
|
|
|
80
83
|
this.pending_ended = false
|
|
81
84
|
this.eventEmitter.emit("ended")
|
|
82
85
|
}
|
|
83
|
-
if (this.opts && this.opts.stay_alive) {
|
|
84
|
-
for (var j = 0; j < numSamples * this.channels; j++) {
|
|
85
|
-
let offset = j * sampleSize * this.channels;
|
|
86
|
-
setter(0, offset);
|
|
87
|
-
}
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return null;
|
|
87
|
+
for (var j = 0; j < numSamples * this.channels; j++) {
|
|
88
|
+
let offset = j * sampleSize * this.channels;
|
|
89
|
+
setter(0, offset);
|
|
93
90
|
}
|
|
91
|
+
|
|
92
|
+
this.push(buf);
|
|
93
|
+
return;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
let actualSamples = specs.reduce((total, spec) => {
|