|
1 | 1 | # @descript/web-audio-js
|
2 | 2 |
|
3 | 3 | 
|
4 |
| -[](https://www.npmjs.org/package/@descript/web-audio-js) |
5 |
| -[](https://mohayonao.mit-license.org/) |
| 4 | +[](https://www.npmjs.org/package/@descript/web-audio-js) |
| 5 | +[](https://mohayonao.mit-license.org/) |
6 | 6 |
|
7 | 7 | > Pure JS implementation of the [Web Audio API](https://www.w3.org/TR/webaudio/)
|
8 | 8 |
|
| 9 | +Fork of [mohayonao/web-audio-engine](https://github.com/mohayonao/web-audio-engine) with following changes: |
| 10 | + |
| 11 | +- Use TypeScript and fix some types |
| 12 | + - Remove `BaseAudioContext.suspend()` |
| 13 | +- Add new `RawDataAudioContext` |
| 14 | +- Bug fixes |
| 15 | + - Fixes for `BiquadFilterNode` and `DelayNode` |
| 16 | + - Fix WAVE decoding |
| 17 | + - Fix `AudioNode.disconnect(x)` not disconnecting |
| 18 | + |
9 | 19 | ## Installation
|
10 | 20 |
|
11 | 21 | ```
|
12 | 22 | npm install --save web-audio-engine
|
13 | 23 | ```
|
14 | 24 |
|
15 |
| -##### download |
16 |
| - |
17 |
| -- [web-audio-engine.js](https://raw.githubusercontent.com/mohayonao/web-audio-engine/master/build/web-audio-engine.js) |
18 |
| - |
19 | 25 | ## API
|
20 | 26 |
|
21 | 27 | `web-audio-engine` provides some `AudioContext` class for each use-case: audio playback, rendering and simulation.
|
@@ -105,6 +111,38 @@ context.encodeAudioData(audioData).then((arrayBuffer) => {
|
105 | 111 | });
|
106 | 112 | ```
|
107 | 113 |
|
| 114 | +### Class: RawDataAudioContext |
| 115 | + |
| 116 | +`RawDataAudioContext` allows you to synchronously step through an AudioContext. This is useful for streaming output at |
| 117 | +and controlling the rate |
| 118 | + |
| 119 | +##### new RawDataAudioContext(opts?: object) |
| 120 | + |
| 121 | +Creates new `RenderingAudioContext` instance. |
| 122 | + |
| 123 | +- `opts.sampleRate: number` audio sample rate (in Hz) - _default: 44100_ |
| 124 | +- `opts.numberOfChannels: number` audio channels (e.g. 2: stereo) - _default: 2_ |
| 125 | +- `opts.blockSize: number` samples each rendering quantum - _default: 128_ |
| 126 | + |
| 127 | +##### context.process(channelData: Float32Array[], offset: number = 0) |
| 128 | + |
| 129 | +Renders the next `blockSize` samples of audio into `channelData`. |
| 130 | + |
| 131 | +```js |
| 132 | +import { RawDataAudioContext } from 'web-audio-engine'; |
| 133 | +const context = new RawDataAudioContext(); |
| 134 | +const { blockSize } = context; |
| 135 | +const channelData = [ |
| 136 | + new Float32Array(blockSize), |
| 137 | + new Float32Array(blockSize), |
| 138 | +]; |
| 139 | + |
| 140 | +for (let i = 0; i < 100_000; i += blockSize) |
| 141 | + context.process(channelData); |
| 142 | + // Do something with channeLData |
| 143 | +} |
| 144 | +``` |
| 145 | + |
108 | 146 | ### Class: WebAudioContext
|
109 | 147 |
|
110 | 148 | :construction*worker: \_TODO: WRITE DESCRIPTION*
|
|
0 commit comments