https://github.com/audiojs/web-audio-write
Write data to web-audio
https://github.com/audiojs/web-audio-write
audio audiojs
Last synced: 8 months ago
JSON representation
Write data to web-audio
- Host: GitHub
- URL: https://github.com/audiojs/web-audio-write
- Owner: audiojs
- License: mit
- Created: 2017-06-11T07:04:18.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-14T14:12:26.000Z (about 5 years ago)
- Last Synced: 2025-09-20T15:48:23.872Z (8 months ago)
- Topics: audio, audiojs
- Language: JavaScript
- Homepage: https://audiojs.github.io/web-audio-write/test.html
- Size: 174 KB
- Stars: 11
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# web-audio-write [](http://github.com/badges/stability-badges)
Write data to any web-audio node.
## Usage
[](https://npmjs.org/package/web-audio-write/)
```js
import createWriter from 'web-audio-write'
const context = new AudioContext()
const write = createWriter(context.destination)
for (let n = 0; n < 10; n++) await write(noise())
write.end()
function noise (frame=1024, channels=2) {
let data = new Float32Array(channels * frame)
for (let i = 0; i < data.length; i++) {
data[i] = Math.random() * 2. - 1.
}
return data
}
```
## API
#### `write = createWriter(node = audioContext.destination)`
Create a function, writing any data to any _AudioNode_. Channel number and sample rate is derived from destination `node`.
#### `async write(samples)`
Send data to the destination `node`.
`samples` can be an array with planar channels layout or a list of arrays, with floats in `-1...+1` range.
Returns `promise` that is resolved when data chunk is being consumed, that's a good place to feed more data.
#### `write(null)`
Schedules end of writing.
#### `write.node`
Exposes worklet web-audio node.
## Related
* [web-audio-read](https://github.com/audiojs/web-audio-read) — read data from web audio.
## License
(c) 2019 audiojs. MIT License
ॐ