opus-codec 0.0.69 → 0.0.71

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.
Files changed (41) hide show
  1. package/es/actions/Client.d.ts +10 -0
  2. package/es/actions/Client.js +73 -0
  3. package/es/actions/actions.d.ts +112 -0
  4. package/es/actions/actions.js +79 -0
  5. package/es/actions/index.d.ts +1 -0
  6. package/es/actions/index.js +1 -0
  7. package/es/actions/opus.d.ts +255 -0
  8. package/es/actions/opus.js +293 -0
  9. package/es/opus/Decoder.d.ts +8 -0
  10. package/es/opus/Decoder.js +72 -0
  11. package/es/opus/Encoder.d.ts +24 -0
  12. package/es/opus/Encoder.js +81 -0
  13. package/es/opus/OpusGettersAndSetters.d.ts +44 -0
  14. package/es/opus/OpusGettersAndSetters.js +212 -0
  15. package/es/opus/RingBuffer.d.ts +6 -0
  16. package/es/opus/RingBuffer.js +46 -0
  17. package/es/opus/constants.d.ts +33 -0
  18. package/es/opus/constants.js +33 -0
  19. package/es/opus/index.d.ts +4 -0
  20. package/es/opus/index.js +4 -0
  21. package/es/runtime/Buffer.d.ts +10 -0
  22. package/es/runtime/Buffer.js +23 -0
  23. package/es/runtime/Integer.d.ts +11 -0
  24. package/es/runtime/Integer.js +27 -0
  25. package/es/runtime/ResourcesHolder.d.ts +9 -0
  26. package/es/runtime/ResourcesHolder.js +13 -0
  27. package/es/runtime/Runtime.d.ts +10 -0
  28. package/es/runtime/Runtime.js +25 -0
  29. package/es/runtime/index.d.ts +4 -0
  30. package/es/runtime/index.js +4 -0
  31. package/native/libopusenc-cmake/src/COPYING +29 -0
  32. package/native/libopusenc-cmake/src/README.md +11 -0
  33. package/native/opus/COPYING +44 -0
  34. package/native/opus/README +161 -0
  35. package/native/opus/README.draft +54 -0
  36. package/native/speexdsp-cmake/src/COPYING +35 -0
  37. package/native/speexdsp-cmake/src/README +3 -0
  38. package/native/speexdsp-cmake/src/README.Trimedia +103 -0
  39. package/native/speexdsp-cmake/src/README.blackfin +22 -0
  40. package/native/speexdsp-cmake/src/README.win32 +11 -0
  41. package/package.json +2 -2
@@ -0,0 +1,293 @@
1
+ export var OpusRequest;
2
+ (function (OpusRequest) {
3
+ OpusRequest["SetComplexity"] = "OPUS_SET_COMPLEXITY";
4
+ OpusRequest["GetComplexity"] = "OPUS_GET_COMPLEXITY";
5
+ OpusRequest["SetBitrate"] = "OPUS_SET_BITRATE";
6
+ OpusRequest["GetBitrate"] = "OPUS_GET_BITRATE";
7
+ OpusRequest["SetVbr"] = "OPUS_SET_VBR";
8
+ OpusRequest["GetVbr"] = "OPUS_GET_VBR";
9
+ OpusRequest["SetVbrConstraint"] = "OPUS_SET_VBR_CONSTRAINT";
10
+ OpusRequest["GetVbrConstraint"] = "OPUS_GET_VBR_CONSTRAINT";
11
+ OpusRequest["SetForceChannels"] = "OPUS_SET_FORCE_CHANNELS";
12
+ OpusRequest["GetForceChannels"] = "OPUS_GET_FORCE_CHANNELS";
13
+ OpusRequest["SetMaxBandwidth"] = "OPUS_SET_MAX_BANDWIDTH";
14
+ OpusRequest["GetMaxBandwidth"] = "OPUS_GET_MAX_BANDWIDTH";
15
+ OpusRequest["SetBandwidth"] = "OPUS_SET_BANDWIDTH";
16
+ OpusRequest["SetSignal"] = "OPUS_SET_SIGNAL";
17
+ OpusRequest["GetSignal"] = "OPUS_GET_SIGNAL";
18
+ OpusRequest["SetApplication"] = "OPUS_SET_APPLICATION";
19
+ OpusRequest["GetApplication"] = "OPUS_GET_APPLICATION";
20
+ OpusRequest["GetLookahead"] = "OPUS_GET_LOOKAHEAD";
21
+ OpusRequest["SetInbandFec"] = "OPUS_SET_INBAND_FEC";
22
+ OpusRequest["GetInbandFec"] = "OPUS_GET_INBAND_FEC";
23
+ OpusRequest["SetPacketLossperc"] = "OPUS_SET_PACKET_LOSS_PERC";
24
+ OpusRequest["GetPacketLossperc"] = "OPUS_GET_PACKET_LOSS_PERC";
25
+ OpusRequest["SetDtx"] = "OPUS_SET_DTX";
26
+ OpusRequest["GetDtx"] = "OPUS_GET_DTX";
27
+ OpusRequest["SetLsbDepth"] = "OPUS_SET_LSB_DEPTH";
28
+ OpusRequest["GetLsbDepth"] = "OPUS_GET_LSB_DEPTH";
29
+ OpusRequest["SetExpertFrameduration"] = "OPUS_SET_EXPERT_FRAME_DURATION";
30
+ OpusRequest["GetExpertFrameduration"] = "OPUS_GET_EXPERT_FRAME_DURATION";
31
+ OpusRequest["SetPredictionDisabled"] = "OPUS_SET_PREDICTION_DISABLED";
32
+ OpusRequest["GetPredictionDisabled"] = "OPUS_GET_PREDICTION_DISABLED";
33
+ OpusRequest["GetBandwidth"] = "OPUS_GET_BANDWIDTH";
34
+ OpusRequest["GetSampleRate"] = "OPUS_GET_SAMPLE_RATE";
35
+ OpusRequest["SetPhaseInversiondisabled"] = "OPUS_SET_PHASE_INVERSION_DISABLED";
36
+ OpusRequest["GetPhaseInversiondisabled"] = "OPUS_GET_PHASE_INVERSION_DISABLED";
37
+ OpusRequest["GetInDtx"] = "OPUS_GET_IN_DTX";
38
+ OpusRequest["SetGain"] = "OPUS_SET_GAIN";
39
+ OpusRequest["GetGain"] = "OPUS_GET_GAIN";
40
+ OpusRequest["GetLastPacketduration"] = "OPUS_GET_LAST_PACKET_DURATION";
41
+ OpusRequest["GetPitch"] = "OPUS_GET_PITCH";
42
+ })(OpusRequest || (OpusRequest = {}));
43
+ export function OPUS_SET_COMPLEXITY(encoderId, x) {
44
+ return {
45
+ encoderId,
46
+ type: OpusRequest.SetComplexity,
47
+ value: x
48
+ };
49
+ }
50
+ export function OPUS_GET_COMPLEXITY(encoderId) {
51
+ return {
52
+ encoderId,
53
+ type: OpusRequest.GetComplexity,
54
+ };
55
+ }
56
+ export function OPUS_SET_BITRATE(encoderId, x) {
57
+ return {
58
+ encoderId,
59
+ type: OpusRequest.SetBitrate,
60
+ value: x
61
+ };
62
+ }
63
+ export function OPUS_GET_BITRATE(encoderId) {
64
+ return {
65
+ encoderId,
66
+ type: OpusRequest.GetBitrate,
67
+ };
68
+ }
69
+ export function OPUS_SET_VBR(encoderId, x) {
70
+ return {
71
+ encoderId,
72
+ type: OpusRequest.SetVbr,
73
+ value: x
74
+ };
75
+ }
76
+ export function OPUS_GET_VBR(encoderId) {
77
+ return {
78
+ encoderId,
79
+ type: OpusRequest.GetVbr,
80
+ };
81
+ }
82
+ export function OPUS_SET_VBR_CONSTRAINT(encoderId, x) {
83
+ return {
84
+ encoderId,
85
+ type: OpusRequest.SetVbrConstraint,
86
+ value: x
87
+ };
88
+ }
89
+ export function OPUS_GET_VBR_CONSTRAINT(encoderId) {
90
+ return {
91
+ encoderId,
92
+ type: OpusRequest.GetVbrConstraint,
93
+ };
94
+ }
95
+ export function OPUS_SET_FORCE_CHANNELS(encoderId, x) {
96
+ return {
97
+ encoderId,
98
+ type: OpusRequest.SetForceChannels,
99
+ value: x
100
+ };
101
+ }
102
+ export function OPUS_GET_FORCE_CHANNELS(encoderId) {
103
+ return {
104
+ encoderId,
105
+ type: OpusRequest.GetForceChannels,
106
+ };
107
+ }
108
+ export function OPUS_SET_MAX_BANDWIDTH(encoderId, x) {
109
+ return {
110
+ encoderId,
111
+ type: OpusRequest.SetMaxBandwidth,
112
+ value: x
113
+ };
114
+ }
115
+ export function OPUS_GET_MAX_BANDWIDTH(encoderId) {
116
+ return {
117
+ encoderId,
118
+ type: OpusRequest.GetMaxBandwidth,
119
+ };
120
+ }
121
+ export function OPUS_SET_BANDWIDTH(encoderId, x) {
122
+ return {
123
+ encoderId,
124
+ type: OpusRequest.SetBandwidth,
125
+ value: x
126
+ };
127
+ }
128
+ export function OPUS_SET_SIGNAL(encoderId, x) {
129
+ return {
130
+ encoderId,
131
+ type: OpusRequest.SetSignal,
132
+ value: x
133
+ };
134
+ }
135
+ export function OPUS_GET_SIGNAL(encoderId) {
136
+ return {
137
+ encoderId,
138
+ type: OpusRequest.GetSignal,
139
+ };
140
+ }
141
+ export function OPUS_SET_APPLICATION(encoderId, x) {
142
+ return {
143
+ encoderId,
144
+ type: OpusRequest.SetApplication,
145
+ value: x
146
+ };
147
+ }
148
+ export function OPUS_GET_APPLICATION(encoderId) {
149
+ return {
150
+ encoderId,
151
+ type: OpusRequest.GetApplication,
152
+ };
153
+ }
154
+ export function OPUS_GET_LOOKAHEAD(encoderId) {
155
+ return {
156
+ encoderId,
157
+ type: OpusRequest.GetLookahead,
158
+ };
159
+ }
160
+ export function OPUS_SET_INBAND_FEC(encoderId, x) {
161
+ return {
162
+ encoderId,
163
+ type: OpusRequest.SetInbandFec,
164
+ value: x
165
+ };
166
+ }
167
+ export function OPUS_GET_INBAND_FEC(encoderId) {
168
+ return {
169
+ encoderId,
170
+ type: OpusRequest.GetInbandFec,
171
+ };
172
+ }
173
+ export function OPUS_SET_PACKET_LOSS_PERC(encoderId, x) {
174
+ return {
175
+ encoderId,
176
+ type: OpusRequest.SetPacketLossperc,
177
+ value: x
178
+ };
179
+ }
180
+ export function OPUS_GET_PACKET_LOSS_PERC(encoderId) {
181
+ return {
182
+ encoderId,
183
+ type: OpusRequest.GetPacketLossperc,
184
+ };
185
+ }
186
+ export function OPUS_SET_DTX(encoderId, x) {
187
+ return {
188
+ encoderId,
189
+ type: OpusRequest.SetDtx,
190
+ value: x
191
+ };
192
+ }
193
+ export function OPUS_GET_DTX(encoderId) {
194
+ return {
195
+ encoderId,
196
+ type: OpusRequest.GetDtx,
197
+ };
198
+ }
199
+ export function OPUS_SET_LSB_DEPTH(encoderId, x) {
200
+ return {
201
+ encoderId,
202
+ type: OpusRequest.SetLsbDepth,
203
+ value: x
204
+ };
205
+ }
206
+ export function OPUS_GET_LSB_DEPTH(encoderId) {
207
+ return {
208
+ encoderId,
209
+ type: OpusRequest.GetLsbDepth,
210
+ };
211
+ }
212
+ export function OPUS_SET_EXPERT_FRAME_DURATION(encoderId, x) {
213
+ return {
214
+ encoderId,
215
+ type: OpusRequest.SetExpertFrameduration,
216
+ value: x
217
+ };
218
+ }
219
+ export function OPUS_GET_EXPERT_FRAME_DURATION(encoderId) {
220
+ return {
221
+ encoderId,
222
+ type: OpusRequest.GetExpertFrameduration,
223
+ };
224
+ }
225
+ export function OPUS_SET_PREDICTION_DISABLED(encoderId, x) {
226
+ return {
227
+ encoderId,
228
+ type: OpusRequest.SetPredictionDisabled,
229
+ value: x
230
+ };
231
+ }
232
+ export function OPUS_GET_PREDICTION_DISABLED(encoderId) {
233
+ return {
234
+ encoderId,
235
+ type: OpusRequest.GetPredictionDisabled,
236
+ };
237
+ }
238
+ export function OPUS_GET_BANDWIDTH(encoderId) {
239
+ return {
240
+ encoderId,
241
+ type: OpusRequest.GetBandwidth,
242
+ };
243
+ }
244
+ export function OPUS_GET_SAMPLE_RATE(encoderId) {
245
+ return {
246
+ encoderId,
247
+ type: OpusRequest.GetSampleRate,
248
+ };
249
+ }
250
+ export function OPUS_SET_PHASE_INVERSION_DISABLED(encoderId, x) {
251
+ return {
252
+ encoderId,
253
+ type: OpusRequest.SetPhaseInversiondisabled,
254
+ value: x
255
+ };
256
+ }
257
+ export function OPUS_GET_PHASE_INVERSION_DISABLED(encoderId) {
258
+ return {
259
+ encoderId,
260
+ type: OpusRequest.GetPhaseInversiondisabled,
261
+ };
262
+ }
263
+ export function OPUS_GET_IN_DTX(encoderId) {
264
+ return {
265
+ encoderId,
266
+ type: OpusRequest.GetInDtx,
267
+ };
268
+ }
269
+ export function OPUS_SET_GAIN(encoderId, x) {
270
+ return {
271
+ encoderId,
272
+ type: OpusRequest.SetGain,
273
+ value: x
274
+ };
275
+ }
276
+ export function OPUS_GET_GAIN(encoderId) {
277
+ return {
278
+ encoderId,
279
+ type: OpusRequest.GetGain,
280
+ };
281
+ }
282
+ export function OPUS_GET_LAST_PACKET_DURATION(encoderId) {
283
+ return {
284
+ encoderId,
285
+ type: OpusRequest.GetLastPacketduration,
286
+ };
287
+ }
288
+ export function OPUS_GET_PITCH(encoderId) {
289
+ return {
290
+ encoderId,
291
+ type: OpusRequest.GetPitch,
292
+ };
293
+ }
@@ -0,0 +1,8 @@
1
+ import { Runtime } from '../runtime';
2
+ export default class Decoder {
3
+ #private;
4
+ constructor(runtime: Runtime, sampleRate: number, channels: number, frameSize: number);
5
+ decodeFloat(value: Uint8Array, decodeFec?: number): number;
6
+ decoded(): Float32Array;
7
+ destroy(): void;
8
+ }
@@ -0,0 +1,72 @@
1
+ import { Integer, ResourcesHolder, Buffer } from '../runtime';
2
+ export default class Decoder {
3
+ #error;
4
+ #decoder;
5
+ #holder;
6
+ #runtime;
7
+ #pcm;
8
+ #frameSize;
9
+ constructor(runtime, sampleRate, channels, frameSize) {
10
+ this.#frameSize = frameSize;
11
+ this.#runtime = runtime;
12
+ this.#holder = new ResourcesHolder();
13
+ this.#error = new Integer(runtime);
14
+ /**
15
+ * holder
16
+ */
17
+ this.#holder.add(this.#error);
18
+ /**
19
+ * create decoder
20
+ */
21
+ this.#decoder = runtime
22
+ .originalRuntime()
23
+ ._opus_decoder_create(sampleRate, channels, this.#error.offset());
24
+ if (!this.#decoder || this.#error.value() < 0) {
25
+ throw new Error('Failed to create decoder');
26
+ }
27
+ this.#pcm = new Buffer(runtime, this.#frameSize * channels * Float32Array.BYTES_PER_ELEMENT);
28
+ }
29
+ #data = null;
30
+ decodeFloat(value, decodeFec = 0) {
31
+ let data = this.#data;
32
+ if (!data) {
33
+ data = new Buffer(this.#runtime, value.byteLength);
34
+ }
35
+ /**
36
+ * reallocate in case current allocated buffer is smaller than the actual
37
+ * incoming data
38
+ */
39
+ if (data.data().byteLength < value.byteLength) {
40
+ data.destroy();
41
+ data = new Buffer(this.#runtime, value.byteLength);
42
+ }
43
+ /**
44
+ * set data
45
+ */
46
+ data.data().set(value);
47
+ /**
48
+ * in case the data buffer has changed, set it back to the class
49
+ * instance so we can later destroy it
50
+ */
51
+ this.#data = data;
52
+ /**
53
+ * decode float data
54
+ */
55
+ const decodedSamples = this.#runtime
56
+ .originalRuntime()
57
+ ._opus_decode_float(this.#decoder, data.offset(), value.byteLength, this.#pcm.offset(), this.#frameSize, decodeFec);
58
+ if (decodedSamples < 0) {
59
+ throw new Error('Failed to decode float');
60
+ }
61
+ return decodedSamples;
62
+ }
63
+ decoded() {
64
+ const pcm = this.#pcm.data();
65
+ return new Float32Array(pcm.buffer, pcm.byteOffset, pcm.byteLength / Float32Array.BYTES_PER_ELEMENT);
66
+ }
67
+ destroy() {
68
+ this.#runtime.originalRuntime()._opus_decoder_destroy(this.#decoder);
69
+ this.#holder.destroy();
70
+ this.#data?.destroy();
71
+ }
72
+ }
@@ -0,0 +1,24 @@
1
+ import { Runtime } from '../runtime';
2
+ import { OpusGettersAndSetters } from './OpusGettersAndSetters';
3
+ export default class Encoder extends OpusGettersAndSetters {
4
+ #private;
5
+ constructor(runtime: Runtime, sampleRate: number, channels: number, application: number,
6
+ /**
7
+ * what is the size of the buffer that holds the encoded data
8
+ */
9
+ outBufferLength: number,
10
+ /**
11
+ * how many bytes will we be receiving through encodeFloat() function
12
+ */
13
+ pcmBufferLength: number);
14
+ encoded(): Uint8Array;
15
+ /**
16
+ *
17
+ * @param value
18
+ * @param frameSize
19
+ * @param maxDataBytes
20
+ * @returns encoded sample count
21
+ */
22
+ encodeFloat(value: Float32Array, frameSize: number, maxDataBytes: number): number;
23
+ destroy(): void;
24
+ }
@@ -0,0 +1,81 @@
1
+ import { Integer, ResourcesHolder, Buffer } from '../runtime';
2
+ import { OpusGettersAndSetters } from './OpusGettersAndSetters';
3
+ export default class Encoder extends OpusGettersAndSetters {
4
+ #error;
5
+ #runtime;
6
+ #encoder;
7
+ #encoded;
8
+ #pcm;
9
+ #holder;
10
+ constructor(runtime, sampleRate, channels, application,
11
+ /**
12
+ * what is the size of the buffer that holds the encoded data
13
+ */
14
+ outBufferLength,
15
+ /**
16
+ * how many bytes will we be receiving through encodeFloat() function
17
+ */
18
+ pcmBufferLength) {
19
+ const error = new Integer(runtime);
20
+ const encoderId = runtime
21
+ .originalRuntime()
22
+ ._opus_encoder_create(sampleRate, channels, application, error.offset());
23
+ super(runtime, encoderId);
24
+ this.#holder = new ResourcesHolder();
25
+ this.#error = error;
26
+ this.#runtime = runtime;
27
+ /**
28
+ * pcm buffer
29
+ */
30
+ this.#pcm = new Buffer(runtime, pcmBufferLength);
31
+ /**
32
+ * out buffer
33
+ */
34
+ this.#encoded = new Buffer(runtime, outBufferLength);
35
+ /**
36
+ * add items to resources holder
37
+ */
38
+ this.#holder.add(this.#encoded);
39
+ this.#holder.add(this.#pcm);
40
+ this.#holder.add(this.#error);
41
+ /**
42
+ * create encoder
43
+ */
44
+ this.#encoder = encoderId;
45
+ if (error.value() < 0) {
46
+ throw new Error('Failed to create encoder');
47
+ }
48
+ if (!outBufferLength) {
49
+ throw new Error('outBufferLength must be more than 0');
50
+ }
51
+ }
52
+ encoded() {
53
+ return this.#encoded.data();
54
+ }
55
+ /**
56
+ *
57
+ * @param value
58
+ * @param frameSize
59
+ * @param maxDataBytes
60
+ * @returns encoded sample count
61
+ */
62
+ encodeFloat(value, frameSize, maxDataBytes) {
63
+ if (maxDataBytes > this.#encoded.size()) {
64
+ throw new Error(`encoded buffer length is ${this.#encoded.size()}, but maxDataBytes is ${maxDataBytes}`);
65
+ }
66
+ this.#pcm
67
+ .data()
68
+ .set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
69
+ const result = this.#runtime
70
+ .originalRuntime()
71
+ ._opus_encode_float(this.#encoder, this.#pcm.offset(), frameSize, this.#encoded.offset(), maxDataBytes);
72
+ if (result < 0) {
73
+ throw new Error(`Failed to encode float`);
74
+ }
75
+ return result;
76
+ }
77
+ destroy() {
78
+ this.#holder.destroy();
79
+ this.#runtime.originalRuntime()._opus_encoder_destroy(this.#encoder);
80
+ }
81
+ }
@@ -0,0 +1,44 @@
1
+ import { Runtime } from '../runtime';
2
+ export declare class OpusGettersAndSetters {
3
+ #private;
4
+ constructor(runtime: Runtime, opusEncoderOffset: number);
5
+ setComplexity(x: number): boolean;
6
+ getComplexity(): number;
7
+ setBitrate(x: number): boolean;
8
+ getBitrate(): number;
9
+ setVbr(x: number): boolean;
10
+ getVbr(): number;
11
+ setVbrConstraint(x: number): boolean;
12
+ getVbrConstraint(): number;
13
+ setForceChannels(x: number): boolean;
14
+ getForceChannels(): number;
15
+ setMaxBandwidth(x: number): boolean;
16
+ getMaxBandwidth(): number;
17
+ setBandwidth(x: number): boolean;
18
+ setSignal(x: number): boolean;
19
+ getSignal(): number;
20
+ setApplication(x: number): boolean;
21
+ getApplication(): number;
22
+ getLookahead(): number;
23
+ setInbandFec(x: number): boolean;
24
+ getInbandFec(): number;
25
+ setPacketLossperc(x: number): boolean;
26
+ getPacketLossperc(): number;
27
+ setDtx(x: number): boolean;
28
+ getDtx(): number;
29
+ setLsbDepth(x: number): boolean;
30
+ getLsbDepth(): number;
31
+ setExpertFrameduration(x: number): boolean;
32
+ getExpertFrameduration(): number;
33
+ setPredictionDisabled(x: number): boolean;
34
+ getPredictionDisabled(): number;
35
+ getBandwidth(): number;
36
+ getSampleRate(): number;
37
+ setPhaseInversiondisabled(x: number): boolean;
38
+ getPhaseInversiondisabled(): number;
39
+ getInDtx(): number;
40
+ setGain(x: number): boolean;
41
+ getGain(): number;
42
+ getLastPacketduration(): number;
43
+ getPitch(): number;
44
+ }