2018-04-11 17:56:09 +02:00
|
|
|
interface CodecCostructor {
|
|
|
|
new (codecSampleRate: number) : Codec;
|
|
|
|
}
|
2018-03-24 23:38:01 +01:00
|
|
|
|
2018-11-12 13:00:13 +01:00
|
|
|
enum CodecType {
|
|
|
|
OPUS_VOICE,
|
2018-11-14 19:29:29 +01:00
|
|
|
OPUS_MUSIC,
|
|
|
|
|
|
|
|
SPEEX_NARROWBAND,
|
|
|
|
SPEEX_WIDEBAND,
|
|
|
|
SPEEX_ULTRA_WIDEBAND,
|
|
|
|
CELT_MONO
|
2018-11-12 13:00:13 +01:00
|
|
|
}
|
|
|
|
|
2018-03-07 19:06:52 +01:00
|
|
|
class BufferChunk {
|
|
|
|
buffer: AudioBuffer;
|
2018-03-02 20:39:46 +01:00
|
|
|
index: number;
|
|
|
|
|
2018-03-07 19:06:52 +01:00
|
|
|
constructor(buffer: AudioBuffer) {
|
2018-03-02 20:39:46 +01:00
|
|
|
this.buffer = buffer;
|
|
|
|
this.index = 0;
|
|
|
|
}
|
2018-03-07 19:06:52 +01:00
|
|
|
|
|
|
|
copyRangeTo(target: AudioBuffer, maxLength: number, offset: number) {
|
|
|
|
let copy = Math.min(this.buffer.length - this.index, maxLength);
|
2018-11-26 20:28:36 +01:00
|
|
|
//TODO may warning if channel counts are not queal?
|
|
|
|
for(let channel = 0; channel < Math.min(target.numberOfChannels, this.buffer.numberOfChannels); channel++) {
|
2018-03-07 19:06:52 +01:00
|
|
|
target.getChannelData(channel).set(
|
|
|
|
this.buffer.getChannelData(channel).subarray(this.index, this.index + copy),
|
|
|
|
offset
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
2018-03-02 20:39:46 +01:00
|
|
|
}
|
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
class CodecClientCache {
|
2019-04-04 21:47:52 +02:00
|
|
|
_last_access: number;
|
2018-04-11 17:56:09 +02:00
|
|
|
_chunks: BufferChunk[] = [];
|
2018-03-02 20:39:46 +01:00
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
bufferedSamples(max: number = 0) : number {
|
2018-03-02 20:39:46 +01:00
|
|
|
let value = 0;
|
2018-03-07 19:06:52 +01:00
|
|
|
for(let i = 0; i < this._chunks.length && value < max; i++)
|
|
|
|
value += this._chunks[i].buffer.length - this._chunks[i].index;
|
2018-03-02 20:39:46 +01:00
|
|
|
return value;
|
|
|
|
}
|
2018-03-07 19:06:52 +01:00
|
|
|
}
|
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
interface Codec {
|
|
|
|
on_encoded_data: (Uint8Array) => void;
|
2018-02-27 17:20:49 +01:00
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
channelCount: number;
|
|
|
|
samplesPerUnit: number;
|
2018-03-07 19:06:52 +01:00
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
name() : string;
|
|
|
|
initialise();
|
|
|
|
deinitialise();
|
2018-02-27 17:20:49 +01:00
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
decodeSamples(cache: CodecClientCache, data: Uint8Array) : Promise<AudioBuffer>;
|
|
|
|
encodeSamples(cache: CodecClientCache, pcm: AudioBuffer);
|
2018-03-02 23:39:12 +01:00
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
reset() : boolean;
|
2018-03-10 09:03:29 +01:00
|
|
|
}
|