-
Notifications
You must be signed in to change notification settings - Fork 1
/
rm.hbs
122 lines (90 loc) · 4.05 KB
/
rm.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
[![view on npm](https://img.shields.io/npm/v/@uttori/audio-wave.svg)](https://www.npmjs.com/package/@uttori/audio-wave)
[![npm module downloads](https://img.shields.io/npm/dt/@uttori/audio-wave.svg)](https://www.npmjs.com/package/@uttori/audio-wave)
[![Build Status](https://travis-ci.com/uttori/uttori-audio-wave.svg?branch=master)](https://travis-ci.com/uttori/uttori-audio-wave)
[![Dependency Status](https://david-dm.org/uttori/uttori-audio-wave.svg)](https://david-dm.org/uttori/uttori-audio-wave)
[![Coverage Status](https://coveralls.io/repos/github/uttori/uttori-audio-wave/badge.svg?branch=master)](https://coveralls.io/github/uttori/uttori-audio-wave?branch=master)
[![Tree-Shaking Support](https://badgen.net/bundlephobia/tree-shaking/@uttori/audio-wave)](https://bundlephobia.com/result?p=@uttori/audio-wave)
[![Dependency Count](https://badgen.net/bundlephobia/dependency-count/@uttori/audio-wave)](https://bundlephobia.com/result?p=@uttori/audio-wave)
[![Minified + GZip](https://badgen.net/bundlephobia/minzip/@uttori/audio-wave)](https://bundlephobia.com/result?p=@uttori/audio-wave)
[![Minified](https://badgen.net/bundlephobia/min/@uttori/audio-wave)](https://bundlephobia.com/result?p=@uttori/audio-wave)
# Uttori AudioWAV
Utility for reading, parsing and basic encoding for Waveform Audio File Format (WAVE / WAV) files. Check out [the demo](https://uttori.github.io/uttori-audio-wave/) to explore the chunks for a given WAV file in the browser.
AudioWAV supports parsing the following WAVE chunks:
- `acid` - ACID Loop Chunk
- `bext` - Broadcast Wave Format (BWF) Broadcast Extension Chunk
- `cue ` - Cue Points Chunk
- `data` - Audio Data Chunk
- `DISP` - Display Chunk
- `ds64` - DataSize 64 Chunk
- `fact` - Additional Data Chunk
- `fmt ` - Format Chunk (Encode Avaliable)
- `inst` - Instrument Chunk
- `JUNK` - Garbage Chunks
- `LIST` - LIST Information Chunk
- `ResU` - Logic Pro X Chunk
- `RLND` - Roland Sampler Chunk (Encode Avaliable)
- `smpl` - Sample Chunk
- `tlst` - Trigger List Chunk
## Install
```bash
npm install --save @uttori/audio-wave
```
## Configuration
```js
{
// This keeps data chunks even and in spec, however some files fail with this.
roundOddChunks: true,
}
```
* * *
# Example
In this example we convert a valid 16 bit, 44.1kHz Wave file to be used with an SP-404SX by adding the appropriate header.
```js
const fs = require('fs');
const { AudioWAV } = require('@uttori/audio-wave');
// Read in a WAV file with AudioWAV
const data = fs.readFileSync('./test/assets/input.wav');
const { chunks } = AudioWAV.fromFile(data);
// Remove the header, we will make a new one with our new size.
chunks.splice(0, 1);
// Remove any existing RLND chunks, should be after `fmt `
const roland_index = chunks.findIndex((chunk) => chunk.type === 'roland');
if (roland_index > 0) {
chunks.splice(roland_index, 1);
}
// Create a RLND chunk and set the pad to J12
const rlnd = AudioWAV.encodeRLND({ device: 'roifspsx', sampleIndex: 'J12' });
// Add the new RLND after the format chunk
const index = chunks.findIndex((chunk) => chunk.type === 'format');
chunks.splice(index + 1, 0, { type: 'roland', chunk: rlnd });
// Calculate the total size, include `WAVE` text (4 bytes)
const size = chunks.reduce((total, chunk) => {
total += chunk.chunk.length;
return total;
}, 4);
// Build the binary data
const header = AudioWAV.encodeHeader({ size });
const parts = chunks.reduce((arr, chunk) => {
arr.push(Buffer.from(chunk.chunk));
return arr;
}, [header]);
const output = Buffer.concat(parts);
// Write file, *.WAV as that is what the offical software uses.
fs.writeFileSync('./test/assets/output.WAV', output);
```
# API Reference
{{>main}}
* * *
## Tests
To run the test suite, first install the dependencies, then run `npm test`:
```bash
npm install
npm test
DEBUG=Uttori* npm test
```
## Contributors
* [Matthew Callis](https://github.com/MatthewCallis)
## Thanks
* [Paul Battley](https://github.com/threedaymonk) - His [Roland SP-404SX sample file format](https://gist.github.com/threedaymonk/701ca30e5d363caa288986ad972ab3e0) was a huge help.
## License
* [MIT](LICENSE)