| 1 |
# WebAudio |
| 2 |
|
| 3 |
[View full source code][code] or [view the compiled example online][online] |
| 4 |
|
| 5 |
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/webaudio/ |
| 6 |
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/webaudio |
| 7 |
|
| 8 |
This example creates an [FM |
| 9 |
oscillator](https://en.wikipedia.org/wiki/Frequency_modulation_synthesis) using |
| 10 |
the [WebAudio |
| 11 |
API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API) and |
| 12 |
`web-sys`. |
| 13 |
|
| 14 |
## `Cargo.toml` |
| 15 |
|
| 16 |
The `Cargo.toml` enables the types needed to use the relevant bits of the |
| 17 |
WebAudio API. |
| 18 |
|
| 19 |
```toml |
| 20 |
{{#include ../../../examples/webaudio/Cargo.toml}} |
| 21 |
``` |
| 22 |
|
| 23 |
## `src/lib.rs` |
| 24 |
|
| 25 |
The Rust code implements the FM oscillator. |
| 26 |
|
| 27 |
```rust |
| 28 |
{{#include ../../../examples/webaudio/src/lib.rs}} |
| 29 |
``` |
| 30 |
|
| 31 |
## `index.js` |
| 32 |
|
| 33 |
A small bit of JavaScript glues the rust module to input widgets and translates |
| 34 |
events into calls into wasm code. |
| 35 |
|
| 36 |
```js |
| 37 |
{{#include ../../../examples/webaudio/index.js}} |
| 38 |
``` |