Skip to content

fix: use Csound API for microphone startup - #428

Merged
hlolli merged 3 commits into
csound:developfrom
Nandos0804:audio-in
Oct 3, 2026
Merged

hlolli merged 3 commits into
csound:developfrom
Nandos0804:audio-in

Conversation

@Nandos0804

@Nandos0804 Nandos0804 commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Use Csound's isRequestingRtAudioInput() after compilation to request microphone access only when the project needs live input. Call enableAudioInput() before startup in both single-thread and worker modes, and let Csound handle routing and stream cleanup.

Remove the custom Web Audio bridge and CSD option parsing. Keep the UI loading while microphone access is pending, report permission errors through the existing error UI, and let Stop cancel setup without starting audio later. Rebased onto the latest develop.

Validation: all 134 tests, lint, type checks, formatting, and the production build passed. Chrome checks with a simulated microphone passed in single-thread, worker, and SharedArrayBuffer modes, covering output-only playback, input flags, track cleanup, and permission denial.

@Nandos0804

Nandos0804 commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor Author

If this is a clear sign of errors on @csound/wasm build, than this PR is safe to close without review. Attempt to fix #411

Comment thread src/components/csound/actions.ts Outdated
Comment on lines +146 to +156
const hasAdcInputFlagInCsOptions = (csd: string = ""): boolean => {
const match = csd.match(/<CsOptions>[\s\S]*?<\/CsOptions>/i);
if (!match) {
return false;
}
const options = match[0].replace(/;.*$/gm, "");
return (
/(^|\s)-i\s*(?:"adc"|'adc'|adc)(?=\s|$)/i.test(options) ||
/(^|\s)--input\s*(?:=\s*)?(?:"adc"|'adc'|adc)(?=\s|$)/i.test(options)
);
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to help here, we can probably get this more reliably. There's a chance that the regex doesn't find the option in some cases, or some cases where the option isn't set in the file. For example project settings should be able to configure flags. Other parts look fine, I'll review better this weekend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thank you. It would be nice also to double check if orc + sco project without explicit csd option can now use input

@vlazzarini

Copy link
Copy Markdown
Member

As I said in the issue - there is no problem getting audio input in other projects using Csound wasm, so the audio input problem is the web ide code.

@Nandos0804

Copy link
Copy Markdown
Contributor Author

As I said in the issue - there is no problem getting audio input in other projects using Csound wasm, so the audio input problem is the web ide code.

Yes agreed, sorry for not explaining my self well. The problem as I was able to identify is on the ide, because without rebuild Csound wasm I was able to connect the input. But my knowledge is very limited in scope so I am not able to identify possible better solution (in the ide itself, or elsewhere). Thank you for the patience

@hlolli hlolli changed the title fix: browser microphone connection to Csound with user warnings fix: use Csound API for microphone startup Oct 1, 2026
@hlolli

hlolli commented Oct 1, 2026

Copy link
Copy Markdown
Member

@Nandos0804 do you have bandwidth to test the mic input on this branch I pushed to, using the upstream input detection I added

@hlolli

hlolli commented Oct 3, 2026

Copy link
Copy Markdown
Member

it works, I ran this on the dev / localhost and it pulled the mic automatically

<CsoundSynthesizer>
<CsOptions>
-iadc -odac
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
nchnls_i = 1
0dbfs = 1

instr 1
    aMic inch 1
    aRing oscili 1, 75
    aRobot = aMic * aRing

    aEcho1 delay aRobot, 0.45
    aEcho2 delay aRobot, 0.90

    ; Quiet output, bounded to 0.2 peak.
    aOut = 0.2 * tanh(2 * (aEcho1 + 0.45 * aEcho2))
    outs aOut, aOut
endin
</CsInstruments>
<CsScore>
i 1 0 60
e
</CsScore>
</CsoundSynthesizer>

@hlolli
hlolli merged commit 7c521b7 into csound:develop Oct 3, 2026
5 checks passed
@Nandos0804

Copy link
Copy Markdown
Contributor Author

@Nandos0804 do you have bandwidth to test the mic input on this branch I pushed to, using the upstream input detection I added

Sorry for the delay. Safe to merge from my end since you tested it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants