@thi.ng/dsp-io-wav
Version:
WAV file format generation
124 lines (87 loc) • 4.28 kB
Markdown
<!-- This file is generated - DO NOT EDIT! -->
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
# 
[](https://www.npmjs.com/package/@thi.ng/dsp-io-wav)

[](https://mastodon.thi.ng/@toxi)
> [!NOTE]
> This is one of 210 standalone projects, maintained as part
> of the [.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
> and anti-framework.
>
> 🚀 Please help me to work full-time on these projects by [sponsoring me on
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
- [About](#about)
- [Status](#status)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Usage examples](#usage-examples)
- [API](#api)
- [Authors](#authors)
- [License](#license)
## About
WAV file format generation. This is a support package for [.ng/dsp](https://github.com/thi-ng/umbrella/tree/develop/packages/dsp).
## Status
**STABLE** - used in production
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Bdsp-io-wav%5D+in%3Atitle)
## Installation
```bash
yarn add .ng/dsp-io-wav
```
ESM import:
```ts
import * as wav from "@thi.ng/dsp-io-wav";
```
Browser ESM import:
```html
<script type="module" src="https://esm.run/@thi.ng/dsp-io-wav"></script>
```
[JSDelivr documentation](https://www.jsdelivr.com/)
For Node.js REPL:
```js
const wav = await import("@thi.ng/dsp-io-wav");
```
Package sizes (brotli'd, pre-treeshake): ESM: 488 bytes
## Dependencies
- [.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
- [.ng/binary](https://github.com/thi-ng/umbrella/tree/develop/packages/binary)
- [.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
- [.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
- [.ng/transducers-binary](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers-binary)
Note: .ng/api is in _most_ cases a type-only import (not used at runtime)
## Usage examples
One project in this repo's
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
directory is using this package:
| Screenshot | Description | Live demo | Source |
|:--------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------|:---------------------------------------------------|:--------------------------------------------------------------------------------|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/render-audio.png" width="240"/> | Generative audio synth offline renderer and WAV file export | [Demo](https://demo.thi.ng/umbrella/render-audio/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/render-audio) |
## API
[Generated API docs](https://docs.thi.ng/umbrella/dsp-io-wav/)
TODO
```ts
import { osc, sin } from "@thi.ng/dsp";
import { wavByteArray } from "@thi.ng/dsp-io-wav";
const FS = 48000;
// write 1 second 24bit mono WAV file of 440Hz sine
fs.writeFileSync(
"sine-440.wav",
wavByteArray(
{ sampleRate: FS, channels: 1, length: FS, bits: 24 },
osc(sin, 440 / FS)
)
);
```
## Authors
- [Karsten Schmidt](https://thi.ng)
If this project contributes to an academic publication, please cite it as:
```bibtex
{thing-dsp-io-wav,
title = "@thi.ng/dsp-io-wav",
author = "Karsten Schmidt",
note = "https://thi.ng/dsp-io-wav",
year = 2020
}
```
## License
© 2020 - 2025 Karsten Schmidt // Apache License 2.0