jbc-dssi 1.1.149 → 1.1.150
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/lib/ogg-opus.js +31 -2
- package/package.json +1 -1
package/lib/ogg-opus.js
CHANGED
|
@@ -67,7 +67,36 @@ const OPUS_TAGS = (() => {
|
|
|
67
67
|
return b;
|
|
68
68
|
})();
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
const FRAME_MS = [
|
|
71
|
+
10, 20, 40, 60,
|
|
72
|
+
10, 20, 40, 60,
|
|
73
|
+
10, 20, 40, 60,
|
|
74
|
+
10, 20,
|
|
75
|
+
10, 20,
|
|
76
|
+
2.5, 5, 10, 20,
|
|
77
|
+
2.5, 5, 10, 20,
|
|
78
|
+
2.5, 5, 10, 20,
|
|
79
|
+
2.5, 5, 10, 20,
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
function packetSamples(packet) {
|
|
83
|
+
if (!packet || packet.length < 1) return 960;
|
|
84
|
+
const toc = packet[0];
|
|
85
|
+
const config = toc >> 3;
|
|
86
|
+
const code = toc & 0x03;
|
|
87
|
+
const ms = FRAME_MS[config] ?? 20;
|
|
88
|
+
let frames = 1;
|
|
89
|
+
if (code === 1) frames = 2;
|
|
90
|
+
else if (code === 2) frames = 2;
|
|
91
|
+
else if (code === 3) {
|
|
92
|
+
if (packet.length < 2) return 960;
|
|
93
|
+
frames = packet[1] & 0x3f;
|
|
94
|
+
if (frames <= 0) frames = 1;
|
|
95
|
+
}
|
|
96
|
+
return Math.round((ms * frames * 48));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function createOggOpusStream() {
|
|
71
100
|
const serial = Math.floor(Math.random() * 0x7fffffff);
|
|
72
101
|
let sequence = 0;
|
|
73
102
|
let granule = 0;
|
|
@@ -80,7 +109,7 @@ export function createOggOpusStream({ samplesPerPacket = 960 } = {}) {
|
|
|
80
109
|
}
|
|
81
110
|
|
|
82
111
|
function packet(data) {
|
|
83
|
-
granule +=
|
|
112
|
+
granule += packetSamples(data);
|
|
84
113
|
pages.push(page({ headerType: 0x00, granule, serial, sequence: sequence++, packets: [data] }));
|
|
85
114
|
return drain();
|
|
86
115
|
}
|