@ain1084/audio-worklet-stream 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -142,9 +142,7 @@ The library does not handle the construction or destruction of AudioContext. Whe
|
|
|
142
142
|
Example:
|
|
143
143
|
|
|
144
144
|
```typescript
|
|
145
|
-
import {
|
|
146
|
-
type OutputStreamNode,
|
|
147
|
-
} from '@ain1084/audio-worklet-stream'
|
|
145
|
+
import { StreamNodeFactory, type OutputStreamNode } from '@ain1084/audio-worklet-stream'
|
|
148
146
|
|
|
149
147
|
let audioContext: AudioContext | null = null
|
|
150
148
|
let factory: StreamNodeFactory | null = null
|
|
@@ -157,23 +155,23 @@ const clicked = async () => {
|
|
|
157
155
|
|
|
158
156
|
// Create manual buffer stream
|
|
159
157
|
const channelCount = 1
|
|
160
|
-
const [node, writer] = await factory.createManualBufferNode(
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
const [node, writer] = await factory.createManualBufferNode({
|
|
159
|
+
channelCount,
|
|
160
|
+
frameCount: 4096,
|
|
161
|
+
})
|
|
163
162
|
|
|
164
163
|
// Write frames
|
|
165
|
-
writer.write((
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
buffer[i + channel] = sampleValue /* TODO: Write sample */
|
|
164
|
+
writer.write((segment) => {
|
|
165
|
+
for (let frame = 0; frame < segment.frameCount; frame++) {
|
|
166
|
+
for (let channel = 0; channel < segment.channels; ++channel) {
|
|
167
|
+
segment.set(frame, channel, /* TODO: Write sample value */)
|
|
170
168
|
}
|
|
171
169
|
}
|
|
172
170
|
// Return the count of written frames
|
|
173
|
-
return
|
|
171
|
+
return segment.frameCount
|
|
174
172
|
})
|
|
175
173
|
|
|
176
|
-
//
|
|
174
|
+
// Start playback
|
|
177
175
|
node.start()
|
|
178
176
|
audioContext.connect(audioContext.destination)
|
|
179
177
|
}
|