Skip to content

Choose modifying startRendering as the preferred approach#1332

Open
gabrielsanbrito wants to merge 1 commit into
MicrosoftEdge:mainfrom
gabrielsanbrito:update-offline-audio-context-prog-rendering
Open

Choose modifying startRendering as the preferred approach#1332
gabrielsanbrito wants to merge 1 commit into
MicrosoftEdge:mainfrom
gabrielsanbrito:update-offline-audio-context-prog-rendering

Conversation

@gabrielsanbrito
Copy link
Copy Markdown
Contributor

@gabrielsanbrito gabrielsanbrito commented May 30, 2026

This PR updates the progressive OfflineAudioContext explainer to reflect the latest discussions that happened in the Audio WG (discussion thread here). The main outcome is that now the preferred approach is to modify the behavior of OfflineAudioContext.startRendering in a backward-compatible manner so that it now renders audio in chunks by default.

Copy link
Copy Markdown
Contributor

@rahulsingh-msft rahulsingh-msft left a comment

Choose a reason for hiding this comment

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

Thanks for updating this! I made some suggestions to improve readability.

### Cons
- Harder to feature-detect — Unlike a new method (e.g., startRenderingStream), you can't simply check if ("newMethod" in context). Detecting chunkSize support requires a try/catch or similar heuristic.
- Changes the mental model for startRendering a bit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add an Alternative Considered section here that the Alternatives that follow can live under?

WebAudio works well in a realtime playback context but it is not suitable for offline context (faster-than-realtime) processing due to a limitation in the design of WebAudio's [OfflineAudioContext API](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext). The design of the API requires allocating memory to render the whole audio graph's memory up-front which can reach gigabytes of AudioBuffer data.

This document will propose adding a streaming offline context rendering function so that the audio graph data can be incrementally processed rather than allocating the whole audio buffer up-front.
This document will propose expanding the functionality of the offline context rendering function so that the audio graph data can be incrementally processed rather than allocating the whole audio buffer up-front.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: This document proposes.

### Goals

- Allow streaming data out of a WebAudio in an offline context for rendering large audio graphs
- Allow incrementally rendering data out of a WebAudio offline context for rendering large audio graphs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we concretely use the API's name i.e. OfflineAudioContext?

- Change the existing `startRendering()` behavior, this API change is additive

## Proposed Approach - Add `startRenderingStream()` function
## Proposed Approach - `startRendering` can render in chunks
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Should Proposed Approach be the Section heading? And then startRendering can render in chunks could be a subheading under that.

## Proposed Approach - `startRendering` can render in chunks

The preferred approach is adding a new method `startRenderingStream()` that yields buffers of interleaved audio samples in a Float32Array, or another format as outlined in Open Questions. In this scenario, the user can read chunks as they arrive and consume them for storage, transcoding via WebCodecs, sending to a server, etc.
The preferred approach is to modify the behavior of `startRendering()` in a backwards-compatible manner so that it always renders incrementally in chunks. With it, as will be explained ahead, the current one-shot render scenario now becomes a special case of the new behavior where the `chunkSize` is set to `OfflineAudioContextOptions.length`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider slightly rewording this:
We propose modifying the behavior of startRendering() in a backwards-compatible manner so that it always renders incrementally in chunks. With this, the current one-shot render scenario becomes a special case of the new behavior where the new chunkSize param is set to ...

```

### Pros
- Solution that is also backward-compatible.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Maintains backwards compatibility.


### Pros
- Solution that is also backward-compatible.
- Simple to reason about and implement, since callers just need to request chunks whenever they are ready to process them.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be 2 sentences?
Simple to reason about and implement. Callers just need to ...


### Cons
- Harder to feature-detect — Unlike a new method (e.g., startRenderingStream), you can't simply check if ("newMethod" in context). Detecting chunkSize support requires a try/catch or similar heuristic.
- Changes the mental model for startRendering a bit.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we say:
Evolves the mental model for startRendering.

- Doesn't require integration with the Streams API.

### Cons
- Harder to feature-detect — Unlike a new method (e.g., startRenderingStream), you can't simply check if ("newMethod" in context). Detecting chunkSize support requires a try/catch or similar heuristic.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be written as:
Harder to feature detect. In contrast, adding a new method would allow checking for its presence in the context...

- It is not feature detectable, as compared to the Proposed Approach, because it only adds options dictionary to an existing function
- Less explicit than the proposed approach as it overloads an existing public API function. It is safer and simpler to add a new function and not change the behaviour of an existing function
- The same cons as Alternative 1
- It is not feature detectable, as compared to Alternative 1, because it only adds options dictionary to an existing function
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unlike Alternative 1, it is not feature detectable because it modifies an existing function.

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.

2 participants