| 59 | } |
| 60 | |
| 61 | processRealtimeAudio() { |
| 62 | const nchnls = this.libcsound.csoundGetNchnls(this.csoundInstance); |
| 63 | const ksmps = this.libcsound.csoundGetKsmps(this.csoundInstance); |
| 64 | |
| 65 | const stream = new Readable(); |
| 66 | |
| 67 | const speaker = new Speaker({ |
| 68 | float: true, |
| 69 | signed: true, |
| 70 | bitDepth: 32, |
| 71 | channels: nchnls, |
| 72 | sampleRate: this.libcsound.csoundGetSr(this.csoundInstance), |
| 73 | }); |
| 74 | |
| 75 | stream._read = this.processKsmps; |
| 76 | stream.that = this; |
| 77 | stream.ksmps = ksmps; |
| 78 | stream.nchnls = nchnls; |
| 79 | stream.csoundBufferPos = 0; |
| 80 | stream.zeroDecibelFullScale = this.libcsound.csoundGet0dBFS(this.csoundInstance); |
| 81 | |
| 82 | const outputBufferPtr = this.libcsound.csoundGetSpout(this.csoundInstance); |
| 83 | stream.outputBufferPtr = outputBufferPtr; |
| 84 | stream.csoundOutputBuffer = new Float64Array( |
| 85 | this.wasm.exports.memory.buffer, |
| 86 | outputBufferPtr, |
| 87 | ksmps * nchnls, |
| 88 | ); |
| 89 | stream.startClickKillCount = 0; |
| 90 | stream.pipe(speaker); |
| 91 | } |
| 92 | |
| 93 | handleStart() { |
| 94 | const shouldDemonize = this.libcsound.csoundShouldDaemonize(this.csoundInstance) === 1; |