Skip to content

Commit 088aa99

Browse files
authored
Offline audio context updates (#1185)
* Add format and length options to preferred API * Change param name to chunkSize
1 parent 2e9f063 commit 088aa99

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

OfflineAudioContext/explainer.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const context = new OfflineAudioContext({ numberOfChannels: 2, length: 44100, sa
4949
// Add some nodes to build a graph...
5050

5151
if ("startRenderingStream" in context) {
52-
const reader = context.startRenderingStream().getReader();
52+
const reader = context.startRenderingStream({ format: 'f32', chunkSize: 128 }).getReader();
5353
while (true) {
5454
// get the next chunk of data from the stream
5555
const result = await reader.read();
@@ -70,9 +70,32 @@ if ("startRenderingStream" in context) {
7070
Proposed interface:
7171

7272
```js
73+
// From https://developer.mozilla.org/en-US/docs/Web/API/AudioData/format
74+
enum AudioFormat {
75+
"u8",
76+
"s16",
77+
"s32",
78+
"f32",
79+
"u8-planar",
80+
"s16-planar",
81+
"s32-planar",
82+
"f32-planar"
83+
}
84+
85+
dictionary OfflineAudioRenderingOptions {
86+
// Output format
87+
AudioFormat format = "f32";
88+
// The number of frames to render each iteration
89+
Number chunkSize = 128;
90+
}
91+
7392
partial interface OfflineAudioContext {
93+
// Immediately stops the rendering, to implement a "cancel" button when rendering
94+
// if startRenderingStream was called, this closes the stream
95+
// If startRendering was called, this rejects the promise
96+
Promise<void> close();
7497
// Returns a stream that yields buffers of interleaved audio samples in Float32Array or whatever format is specified
75-
Promise<ReadableStream> startRenderingStream();
98+
Promise<ReadableStream> startRenderingStream(optional OfflineAudioRenderingOptions);
7699
};
77100
```
78101

0 commit comments

Comments
 (0)