()
| 162 | } |
| 163 | |
| 164 | async start() { |
| 165 | if (!this.csoundApi) { |
| 166 | console.error("starting csound failed because csound instance wasn't created"); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | if (this.currentPlayState !== "realtimePerformanceStarted") { |
| 171 | this.result = 0; |
| 172 | this.csoundApi.csoundSetOption(this.csoundInstance, "-odac"); |
| 173 | this.csoundApi.csoundSetOption(this.csoundInstance, "-iadc"); |
| 174 | this.csoundApi.csoundSetOption(this.csoundInstance, "--sample-rate=" + this.sampleRate); |
| 175 | this.nchnls = -1; |
| 176 | this.nchnls_i = -1; |
| 177 | |
| 178 | const ksmps = this.csoundApi.csoundGetKsmps(this.csoundInstance); |
| 179 | this.ksmps = ksmps; |
| 180 | this.cnt = ksmps; |
| 181 | |
| 182 | this.nchnls = this.csoundApi.csoundGetNchnls(this.csoundInstance); |
| 183 | this.nchnls_i = this.csoundApi.csoundGetNchnlsInput(this.csoundInstance); |
| 184 | |
| 185 | const outputPointer = this.csoundApi.csoundGetSpout(this.csoundInstance); |
| 186 | this.csoundOutputBuffer = new Float64Array( |
| 187 | this.wasm.wasi.memory.buffer, |
| 188 | outputPointer, |
| 189 | ksmps * this.nchnls, |
| 190 | ); |
| 191 | |
| 192 | const inputPointer = this.csoundApi.csoundGetSpin(this.csoundInstance); |
| 193 | this.csoundInputBuffer = new Float64Array( |
| 194 | this.wasm.wasi.memory.buffer, |
| 195 | inputPointer, |
| 196 | ksmps * this.nchnls_i, |
| 197 | ); |
| 198 | this.zerodBFS = this.csoundApi.csoundGet0dBFS(this.csoundInstance); |
| 199 | |
| 200 | this.publicEvents.triggerOnAudioNodeCreated(this.spn); |
| 201 | this.eventPromises.createStartPromise(); |
| 202 | |
| 203 | const startResult = this.csoundApi.csoundStart(this.csoundInstance); |
| 204 | if (this.csoundApi._isRequestingRtMidiInput(this.csoundInstance)) { |
| 205 | requestMidi({ |
| 206 | onMidiMessage: ({ data: event }) => |
| 207 | this.csoundApi.csoundPushMidiMessage(this.csoundInstance, event[0], event[1], event[2]), |
| 208 | }); |
| 209 | } |
| 210 | this.running = true; |
| 211 | await this.eventPromises.waitForStart(); |
| 212 | return startResult; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | async initialize({ wasmDataURI, withPlugins, autoConnect }) { |
| 217 | if (!this.plugins && withPlugins && !isEmpty(withPlugins)) { |
no test coverage detected