Refatora processamento de preview em tempo real para AudioWorklet#83
Conversation
|
Warning Review limit reached
More reviews will be available in 44 minutes and 45 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughReplaced realtime audio processing from deprecated ChangesAudioWorkletNode Migration
Sequence DiagramsequenceDiagram
participant User
participant setParam as setParam()
participant orbitNode as orbit-delay-processor
participant wasmAPI as WASM api
User->>setParam: adjust parameter
alt Realtime preview active
setParam->>orbitNode: setValueAtTime(key, value)
orbitNode->>orbitNode: update parameter
else Offline or no preview
setParam->>wasmAPI: call api setter
wasmAPI->>wasmAPI: update state
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the realtime audio processing in the WASM demo to use an AudioWorkletNode (orbit-delay-processor) instead of the deprecated ScriptProcessorNode. This involves removing the ensureRealtimeBuffers function and updating setParam to dynamically set parameters on the worklet node. The reviewer identified a critical issue where certain parameters (like shimmerMode, feedbackTapMixerEnabled, and feedbackTapMixerAmount) are not declared in the worklet's descriptors, causing them to be silently ignored during realtime playback. A code suggestion was provided to add warning logs for missing parameters.
| if (previewGraph.orbitNode && previewGraph.audioCtx && !realtimeState.isOfflineProcessing) { | ||
| const param = previewGraph.orbitNode.parameters.get(key); | ||
| if (param) { | ||
| param.setValueAtTime(value, previewGraph.audioCtx.currentTime); | ||
| } | ||
| return; | ||
| } |
There was a problem hiding this comment.
Há uma incompatibilidade entre os parâmetros suportados pelo OrbitDelayProcessor (definidos em worklet-processor.js) e os parâmetros enviados por setParam.
Os parâmetros shimmerMode, feedbackTapMixerEnabled e feedbackTapMixerAmount estão presentes em PARAM_KEYS e são atualizados via UI, mas não estão declarados em parameterDescriptors nem são tratados em applyParams dentro do worklet-processor.js.
Como a função setParam retorna imediatamente quando previewGraph.orbitNode está ativo (mesmo se o parâmetro for undefined), essas configurações serão silenciosamente ignoradas e nunca serão aplicadas ao áudio em tempo real.
Para corrigir isso, você precisa:
- Adicionar esses parâmetros ao
parameterDescriptorse ao métodoapplyParamsno arquivotargets/wasm/js/worklet-processor.js. - Adicionar um aviso no console caso um parâmetro não seja encontrado no nó do Worklet para facilitar a depuração.
| if (previewGraph.orbitNode && previewGraph.audioCtx && !realtimeState.isOfflineProcessing) { | |
| const param = previewGraph.orbitNode.parameters.get(key); | |
| if (param) { | |
| param.setValueAtTime(value, previewGraph.audioCtx.currentTime); | |
| } | |
| return; | |
| } | |
| if (previewGraph.orbitNode && previewGraph.audioCtx && !realtimeState.isOfflineProcessing) { | |
| const param = previewGraph.orbitNode.parameters.get(key); | |
| if (param) { | |
| param.setValueAtTime(value, previewGraph.audioCtx.currentTime); | |
| } else { | |
| console.warn(`Parâmetro "${key}" não encontrado no AudioWorkletNode.`); | |
| } | |
| return; | |
| } |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@targets/wasm/js/demo.js`:
- Around line 243-249: Add error handling and lifecycle feedback around worklet
initialization: await audioCtx.audioWorklet.addModule('./worklet-processor.js')
should be wrapped to catch and log/display errors; creation of the
AudioWorkletNode (orbitNode = new AudioWorkletNode(...)) should also be guarded
to handle exceptions. Extend orbitNode.port.onmessage to handle event.data.type
=== 'ready' (signal successful WASM init) and event.data.type === 'error' (show
error details to UI/console) in addition to the existing 'orbit_diag' handling,
and surface errors to the user (e.g., processLogger/console and a UI
notification) so WASM init failures and node creation failures aren’t silent.
- Around line 251-263: applyParams() is being called before
previewGraph.orbitNode is assigned, causing setParam() to fall back to the WASM
path and not send initial values to the worklet; move the applyParams() call so
it runs after previewGraph.orbitNode (and
previewGraph.dryGain/wetGain/orbitNode) are assigned and previewGraph.audioCtx
is set, or alternatively call applyParams() again after those assignments,
ensuring applyParams(), setParam(), previewGraph.orbitNode and api see the
correct initialized graph so the worklet receives the UI/preset values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a5a47c74-9767-45c9-9ffd-c715ff06fda9
📒 Files selected for processing (1)
targets/wasm/js/demo.js
Motivation
ScriptProcessorNodena thread principal movendo o processamento realtime para umAudioWorkletNodededicado.Description
ScriptProcessorNodeemensurePreviewGraph()porawait audioCtx.audioWorklet.addModule('./worklet-processor.js')enew AudioWorkletNode(audioCtx, 'orbit-delay-processor'), conectandodrySource -> orbitNode -> wetGain -> audioCtx.destinatione salvando a referência empreviewGraph.orbitNode.ensureRealtimeBufferse ponteiros relacionados), preservando apenasrealtimeState.isOfflineProcessingcomo sinalizador para o modo offline.setParam(key)para, quando oorbitNodeestiver presente e não estivermos em processamento offline, aplicar valores realtime viapreviewGraph.orbitNode.parameters.get(paramName).setValueAtTime(value, audioCtx.currentTime); mantém chamadas diretas à API WASM no caminho offline (botão de processamento).orbitNode.port.onmessage) para encaminhar diagnósticosorbit_diagao UI se necessário, e mantém a rotina offline síncrona com_malloc/api.processsem alterações.Testing
node --check targets/wasm/js/demo.jspara verificação sintática do script e o comando terminou sem erros (sucesso).Codex Task
Summary by CodeRabbit
Release Notes