(frame: Uint8Array)
| 95 | } |
| 96 | |
| 97 | encode(frame: Uint8Array): Uint8Array { |
| 98 | if (this.closed) { |
| 99 | throw new Error("Opus encoder is closed"); |
| 100 | } |
| 101 | |
| 102 | this.refreshMemory(); |
| 103 | this.memory.set(frame, this.pcmPtr); |
| 104 | const size = ensureOk( |
| 105 | this.wasm.opus_encode( |
| 106 | this.encoderPtr, |
| 107 | this.pcmPtr, |
| 108 | frame.byteLength / BYTES_PER_SAMPLE / CHANNELS, |
| 109 | this.packetPtr, |
| 110 | MAX_PACKET_SIZE, |
| 111 | ), |
| 112 | this.memory, |
| 113 | this.wasm, |
| 114 | ); |
| 115 | |
| 116 | this.refreshMemory(); |
| 117 | return this.memory.slice(this.packetPtr, this.packetPtr + size); |
| 118 | } |
| 119 | |
| 120 | close() { |
| 121 | if (this.closed) { |
no test coverage detected