audiowaveform 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/COPYING +674 -0
- data/Cargo.lock +1108 -0
- data/Cargo.toml +28 -0
- data/README.md +255 -0
- data/bindings/ruby/CHANGELOG.md +29 -0
- data/bindings/ruby/Cargo.lock +621 -0
- data/bindings/ruby/Cargo.toml +8 -0
- data/bindings/ruby/README.md +193 -0
- data/bindings/ruby/ext/audiowaveform/Cargo.toml +20 -0
- data/bindings/ruby/ext/audiowaveform/build.rs +4 -0
- data/bindings/ruby/ext/audiowaveform/extconf.rb +6 -0
- data/bindings/ruby/ext/audiowaveform/src/lib.rs +239 -0
- data/bindings/ruby/lib/audiowaveform/version.rb +5 -0
- data/bindings/ruby/lib/audiowaveform.rb +131 -0
- data/crates/audiowaveform/Cargo.toml +73 -0
- data/crates/audiowaveform/examples/generate_from_pcm.rs +25 -0
- data/crates/audiowaveform/examples/generate_waveform.rs +18 -0
- data/crates/audiowaveform/examples/render_waveform.rs +18 -0
- data/crates/audiowaveform/examples/resample_waveform.rs +19 -0
- data/crates/audiowaveform/src/audio.rs +938 -0
- data/crates/audiowaveform/src/color.rs +201 -0
- data/crates/audiowaveform/src/error.rs +89 -0
- data/crates/audiowaveform/src/format.rs +215 -0
- data/crates/audiowaveform/src/lib.rs +79 -0
- data/crates/audiowaveform/src/render.rs +802 -0
- data/crates/audiowaveform/src/wav.rs +95 -0
- data/crates/audiowaveform/src/waveform.rs +790 -0
- data/crates/audiowaveform/tests/formats.rs +223 -0
- data/crates/audiowaveform/tests/generate.rs +233 -0
- data/crates/audiowaveform/tests/render.rs +263 -0
- data/crates/audiowaveform/tests/support/mod.rs +125 -0
- data/crates/audiowaveform/tests/wav.rs +54 -0
- data/crates/audiowaveform/tests/waveform_io.rs +255 -0
- data/crates/audiowaveform-cli/Cargo.toml +43 -0
- data/crates/audiowaveform-cli/src/main.rs +803 -0
- data/crates/audiowaveform-cli/tests/cli.rs +483 -0
- data/crates/audiowaveform-cli/tests/support/mod.rs +111 -0
- data/sig/audiowaveform.rbs +33 -0
- metadata +100 -0
data/Cargo.toml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[workspace]
|
|
2
|
+
members = [
|
|
3
|
+
"crates/audiowaveform",
|
|
4
|
+
"crates/audiowaveform-cli",
|
|
5
|
+
]
|
|
6
|
+
exclude = ["bindings/ruby"]
|
|
7
|
+
resolver = "2"
|
|
8
|
+
|
|
9
|
+
[workspace.package]
|
|
10
|
+
version = "1.10.3"
|
|
11
|
+
edition = "2024"
|
|
12
|
+
license = "GPL-3.0-or-later"
|
|
13
|
+
repository = "https://github.com/Antti/audiowaveform"
|
|
14
|
+
authors = ["Andrii Dmytrenko", "BBC Research and Development"]
|
|
15
|
+
|
|
16
|
+
[workspace.dependencies]
|
|
17
|
+
assert_cmd = "2.0"
|
|
18
|
+
byteorder = "1.5"
|
|
19
|
+
clap = { version = "4.5", features = ["derive"] }
|
|
20
|
+
hound = "3.5"
|
|
21
|
+
image = { version = "0.25", default-features = false, features = ["png"] }
|
|
22
|
+
png = "0.17"
|
|
23
|
+
predicates = "3.1"
|
|
24
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
25
|
+
serde_json = "1.0"
|
|
26
|
+
symphonia = { version = "0.5", default-features = false }
|
|
27
|
+
tempfile = "3.14"
|
|
28
|
+
thiserror = "2.0"
|
data/README.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# audiowaveform
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Antti/audiowaveform/actions/workflows/rust.yml)
|
|
4
|
+
|
|
5
|
+
`audiowaveform` is a Rust library and CLI for generating waveform data from audio,
|
|
6
|
+
serializing waveform files, rendering PNG waveform images, and transcoding audio
|
|
7
|
+
to PCM16 WAV.
|
|
8
|
+
|
|
9
|
+
This repository is the canonical home of the Rust rewrite:
|
|
10
|
+
[github.com/Antti/audiowaveform](https://github.com/Antti/audiowaveform).
|
|
11
|
+
|
|
12
|
+
It is a Rust rewrite of the original BBC `audiowaveform` project:
|
|
13
|
+
[github.com/bbc/audiowaveform](https://github.com/bbc/audiowaveform).
|
|
14
|
+
The original project was created by Chris Needham and contributors at BBC
|
|
15
|
+
Research & Development.
|
|
16
|
+
|
|
17
|
+
The repository's main workspace remains Rust-only:
|
|
18
|
+
|
|
19
|
+
- `crates/audiowaveform`: reusable library crate
|
|
20
|
+
- `crates/audiowaveform-cli`: thin `audiowaveform` command-line wrapper
|
|
21
|
+
|
|
22
|
+
Ruby applications can use the native extension in `bindings/ruby` to generate
|
|
23
|
+
waveforms in process through the same library crate.
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Decode AAC-LC, ALAC, MP1/MP2/MP3, WAV, FLAC, Ogg, AIFF, CAF, and audio in MP4/Matroska/WebM containers
|
|
30
|
+
- Generate `.dat`, `.json`, and `.txt` waveform files
|
|
31
|
+
- Render PNG waveform images in pure Rust
|
|
32
|
+
- Transcode decoded audio or raw PCM input to PCM16 WAV
|
|
33
|
+
- Use path-based, stream-based, or in-memory APIs from the library crate
|
|
34
|
+
|
|
35
|
+
Opus and HE-AAC are unsupported by the current decoder. AAC-LC supports mono and
|
|
36
|
+
stereo. Enabling a container such as WebM does not add unsupported codecs.
|
|
37
|
+
AAC/MP4 decoding does not apply gapless trimming, so decoded audio and waveform
|
|
38
|
+
duration can include encoder delay and padding.
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
Build the workspace:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
cargo build --workspace
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Run the CLI:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
cargo run -p audiowaveform-cli -- -i fixtures/test_file_stereo.wav -o output.dat
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Install the CLI locally:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
cargo install --path crates/audiowaveform-cli
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Run the test suite:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
cargo test --workspace
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Library Usage
|
|
67
|
+
|
|
68
|
+
The Rust library has **no default features**. PCM/raw waveform generation,
|
|
69
|
+
waveform serialization, and resampling are always available. Enable input formats
|
|
70
|
+
and output capabilities explicitly:
|
|
71
|
+
|
|
72
|
+
```toml
|
|
73
|
+
[dependencies]
|
|
74
|
+
audiowaveform = { version = "1.10.3", features = ["format-mp3", "format-m4a"] }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Cargo feature | Capability |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `format-aac` | AAC-LC in ADTS (`.aac`, `.adts`) |
|
|
80
|
+
| `format-aiff` | PCM in AIFF/AIFF-C (`.aiff`, `.aif`, `.aifc`) |
|
|
81
|
+
| `format-caf` | PCM and ALAC in CAF |
|
|
82
|
+
| `format-flac` | FLAC |
|
|
83
|
+
| `format-m4a` / `format-mp4` | AAC-LC, ALAC, MP3, and PCM in MP4/M4A/MOV containers |
|
|
84
|
+
| `format-mkv` / `format-webm` | Supported audio codecs in Matroska/WebM (`.mkv`, `.mka`, `.webm`); no Opus |
|
|
85
|
+
| `format-mp1`, `format-mp2`, `format-mp3` | MPEG audio layers I, II, and III respectively |
|
|
86
|
+
| `format-ogg` | Vorbis and FLAC in Ogg (`.ogg`, `.oga`) |
|
|
87
|
+
| `format-wav` | PCM and ADPCM in WAV/W64 |
|
|
88
|
+
| `all-formats` | All input format bundles above |
|
|
89
|
+
| `render` | PNG rendering |
|
|
90
|
+
| `wav-output` | PCM16 WAV writing |
|
|
91
|
+
|
|
92
|
+
`format-mp4` aliases `format-m4a`; `format-webm` aliases `format-mkv`.
|
|
93
|
+
Format features enable the shared `decode` plumbing automatically. `decode`
|
|
94
|
+
alone does not enable any codecs or containers. `all-formats` does not enable
|
|
95
|
+
PNG rendering or WAV writing. Cargo features are additive: another dependency
|
|
96
|
+
can enable additional features in a shared build.
|
|
97
|
+
|
|
98
|
+
Generate waveform data from an audio file:
|
|
99
|
+
|
|
100
|
+
```rust,no_run
|
|
101
|
+
use audiowaveform::{GenerateOptions, WaveformFormat, generate_waveform_from_path};
|
|
102
|
+
|
|
103
|
+
fn main() -> Result<(), audiowaveform::Error> {
|
|
104
|
+
let waveform = generate_waveform_from_path("input.mp3", &GenerateOptions::default())?;
|
|
105
|
+
waveform.save_to_path("output.dat", Some(WaveformFormat::Dat))?;
|
|
106
|
+
Ok(())
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Render a PNG from a stored waveform (requires `render`):
|
|
111
|
+
|
|
112
|
+
```rust,no_run
|
|
113
|
+
use std::fs::File;
|
|
114
|
+
|
|
115
|
+
use audiowaveform::{RenderOptions, Waveform, write_waveform_png};
|
|
116
|
+
|
|
117
|
+
fn main() -> Result<(), audiowaveform::Error> {
|
|
118
|
+
let waveform = Waveform::load_from_path("input.dat", None)?;
|
|
119
|
+
write_waveform_png(&waveform, &RenderOptions::default(), File::create("output.png")?)?;
|
|
120
|
+
Ok(())
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Generate waveform data from in-memory PCM:
|
|
125
|
+
|
|
126
|
+
```rust
|
|
127
|
+
use audiowaveform::{GenerateOptions, PcmAudio, generate_waveform_from_pcm};
|
|
128
|
+
|
|
129
|
+
fn main() -> Result<(), audiowaveform::Error> {
|
|
130
|
+
let pcm = PcmAudio::new(48_000, 1, vec![0_i16; 48_000])?;
|
|
131
|
+
let waveform = generate_waveform_from_pcm(&pcm, &GenerateOptions::default())?;
|
|
132
|
+
assert!(!waveform.is_empty());
|
|
133
|
+
Ok(())
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Additional examples live in `crates/audiowaveform/examples`.
|
|
138
|
+
|
|
139
|
+
## Ruby Usage
|
|
140
|
+
|
|
141
|
+
Install the `audiowaveform` gem from RubyGems and generate waveform
|
|
142
|
+
data without invoking the command-line program:
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
gem "audiowaveform", "~> 0.1"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
require "audiowaveform"
|
|
150
|
+
|
|
151
|
+
waveform = AudioWaveform.generate("input.mp3", samples_per_pixel: 256)
|
|
152
|
+
waveform.save("output.dat", bits: 8)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
See [`bindings/ruby/README.md`](bindings/ruby/README.md) for the full Ruby API
|
|
156
|
+
and development instructions.
|
|
157
|
+
|
|
158
|
+
## CLI Usage
|
|
159
|
+
|
|
160
|
+
The CLI defaults to `all-formats`, `render`, and `wav-output`. To build a smaller
|
|
161
|
+
CLI, disable defaults and enable only the features you need:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
cargo build -p audiowaveform-cli --no-default-features --features format-mp3,format-m4a
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Add `render` or `wav-output` for those outputs. With no features, the CLI can
|
|
168
|
+
still process raw PCM and convert/resample waveform data. Requests for omitted
|
|
169
|
+
formats or outputs report the required Cargo feature.
|
|
170
|
+
|
|
171
|
+
Generate `.dat` waveform data:
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
audiowaveform -i input.wav -o output.dat -z 128 -b 8
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Render a PNG from waveform data:
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
audiowaveform -i input.dat -o output.png -w 1000 -h 200
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Generate JSON waveform data from compressed audio:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
audiowaveform -i input.flac -o output.json --pixels-per-second 50
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Convert raw PCM to WAV:
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
audiowaveform -i input.raw -o output.wav --input-format raw --raw-samplerate 48000 --raw-channels 2 --raw-format s16le
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
See all options with:
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
audiowaveform --help
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Supported Formats
|
|
202
|
+
|
|
203
|
+
Audio input:
|
|
204
|
+
|
|
205
|
+
- `aac` and `adts` (AAC-LC)
|
|
206
|
+
- `mp1`, `mp2`, and `mp3`
|
|
207
|
+
- `mp4`, `m4a`, `m4b`, `m4r`, `m4v`, and `mov` (supported audio tracks only)
|
|
208
|
+
- `mkv`, `mka`, and `webm` (supported audio tracks only; no Opus)
|
|
209
|
+
- `aiff`, `aif`, and `aifc`
|
|
210
|
+
- `caf`
|
|
211
|
+
- `wav` and `w64`
|
|
212
|
+
- `flac`
|
|
213
|
+
- `ogg` and `oga`
|
|
214
|
+
- `raw`
|
|
215
|
+
|
|
216
|
+
Waveform input:
|
|
217
|
+
|
|
218
|
+
- `dat`
|
|
219
|
+
- `json`
|
|
220
|
+
|
|
221
|
+
Waveform output:
|
|
222
|
+
|
|
223
|
+
- `dat`
|
|
224
|
+
- `json`
|
|
225
|
+
- `txt`
|
|
226
|
+
|
|
227
|
+
Image output:
|
|
228
|
+
|
|
229
|
+
- `png`
|
|
230
|
+
|
|
231
|
+
Audio output:
|
|
232
|
+
|
|
233
|
+
- `wav`
|
|
234
|
+
|
|
235
|
+
## Documentation
|
|
236
|
+
|
|
237
|
+
- Waveform file formats: [doc/DataFormat.md](doc/DataFormat.md)
|
|
238
|
+
- CLI man page: [doc/audiowaveform.1](doc/audiowaveform.1)
|
|
239
|
+
- Waveform format man page: [doc/audiowaveform.5](doc/audiowaveform.5)
|
|
240
|
+
- Project release history: [CHANGELOG.md](CHANGELOG.md)
|
|
241
|
+
- Ruby gem release history: [bindings/ruby/CHANGELOG.md](bindings/ruby/CHANGELOG.md)
|
|
242
|
+
|
|
243
|
+
Generate local API docs with:
|
|
244
|
+
|
|
245
|
+
```sh
|
|
246
|
+
cargo doc -p audiowaveform --all-features --no-deps
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Contributing
|
|
250
|
+
|
|
251
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for workflow, documentation, and testing expectations.
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
|
|
255
|
+
`audiowaveform` is released under the GPL-3.0-or-later license. See [COPYING](COPYING).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Ruby Gem Version History
|
|
2
|
+
|
|
3
|
+
## 0.1.0 - 2026-09-20
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Publish source and precompiled gems through RubyGems Trusted Publishing on
|
|
8
|
+
`ruby-vX.Y.Z` tag pushes. Manual workflow runs build and test without publishing.
|
|
9
|
+
- Build native gems for CRuby 3.2–4.0 on Linux glibc/musl (x86-64 and ARM64),
|
|
10
|
+
macOS (Intel and Apple Silicon), and Windows UCRT (x86-64).
|
|
11
|
+
- Load the extension matching the running Ruby version and verify installed
|
|
12
|
+
platform gems before publishing. Native gems have no build-time dependencies.
|
|
13
|
+
- Enable all supported Rust input formats in source and precompiled builds,
|
|
14
|
+
including AAC-LC/M4A, ALAC, AIFF, CAF, MPEG layers I/II, Matroska/WebM audio,
|
|
15
|
+
Ogg FLAC, and WAV ADPCM. Opus and HE-AAC remain unsupported.
|
|
16
|
+
|
|
17
|
+
- Generate waveform data directly from WAV, MP3, FLAC, and Ogg/Vorbis files.
|
|
18
|
+
- Read waveform metadata and points, then serialize data as DAT, JSON, or text.
|
|
19
|
+
- Install a source gem from GitHub releases or directly from the repository.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Release Ruby's global VM lock during generation, serialization, and file writes.
|
|
24
|
+
- Point installation instructions and package metadata at `Antti/audiowaveform`.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Build, install, and test the native extension across supported Linux, macOS,
|
|
29
|
+
and Windows environments.
|