()
| 17 | } |
| 18 | |
| 19 | flush() { |
| 20 | if (this.writeIndex <= 0) return; |
| 21 | const output = this.buffer.slice(0, this.writeIndex); |
| 22 | const level = |
| 23 | this.levelCount > 0 |
| 24 | ? Math.sqrt(this.levelSumSquares / this.levelCount) |
| 25 | : 0; |
| 26 | this.port.postMessage( |
| 27 | { type: "pcm", buffer: output.buffer, level }, |
| 28 | [output.buffer], |
| 29 | ); |
| 30 | this.buffer = new Int16Array(this.chunkSamples); |
| 31 | this.writeIndex = 0; |
| 32 | this.levelSumSquares = 0; |
| 33 | this.levelCount = 0; |
| 34 | } |
| 35 | |
| 36 | appendSample(sample) { |
| 37 | const clamped = Math.max(-1, Math.min(1, sample || 0)); |
no outgoing calls
no test coverage detected