mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2026-05-17 04:33:26 +00:00
Compare commits
7 Commits
features
...
3315f00a89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3315f00a89 | ||
|
|
6819f63c74 | ||
| 1c83094888 | |||
| 977c8263d2 | |||
| da4bad0e87 | |||
| c89a98f7e4 | |||
|
|
8e341990fa |
64
CONTRIBUTING.md
Normal file
64
CONTRIBUTING.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Contributing
|
||||
|
||||
Contributions to `bwavfile` are welcome!
|
||||
|
||||
This project is currently in a maintenance phase, new features are entertained if we
|
||||
believe there is some demand for them but for the most part our current priorities
|
||||
are:
|
||||
|
||||
* Addressing bugs.
|
||||
* Keeping the codebase modern as the Rust language evolves.
|
||||
|
||||
This being said, there are some features that we've been wanting for some time and
|
||||
new contributors are welcome to take a swing at these:
|
||||
|
||||
* Reading `levl` metadata for the generation of waveform overviews.
|
||||
* Reading `smpl` metadata for reading sampler data, note assignments, loops etc.
|
||||
|
||||
## Adding New Features
|
||||
|
||||
If you are adding a large amount of new functionality, please weigh the amount of
|
||||
work you're doing against the potential benefit, the burden on the maintainers to
|
||||
review the work, and the technical debt incurred.
|
||||
|
||||
In general,
|
||||
|
||||
* new features should address new technologies; do not expend large amounts of
|
||||
effort to implement features that are primarily of historical interest.
|
||||
* new features should address the needs of professional users in a music or media
|
||||
production environment.
|
||||
|
||||
Features that implement new reading functionality must, when submitted, include
|
||||
test WAV files created empirically by third-party software.
|
||||
|
||||
## Regarding use of Agents
|
||||
|
||||
`bwavfile` is an open-source project that is offered free for no commerical gain, and
|
||||
is developed and maintained for educational and creative reasons.
|
||||
|
||||
If you use an agent or LLM to produce code for it you are missing out on the benefits
|
||||
of contributing to an open-source project, particularly community, collaboration with
|
||||
other developers and designers, and being able to learn and experiment without the
|
||||
burden of deadlines or worrying about business cases or profits.
|
||||
|
||||
This project is supposed to be fun, do not let machines have fun for you.
|
||||
|
||||
We can't prevent you from using LLMs to contribute to this project but we ask you
|
||||
abide by the following eitiquette when doing so:
|
||||
|
||||
* All communication with the maintainers must be written by a human in their own
|
||||
voice. Never use an LLM to craft thread comments, discussion posts, issues, emails
|
||||
or other correspondence with other developers or the maintainers.
|
||||
* PRs must be submitted by a person. Do not allow an agent to submit its own PRs to
|
||||
this project.
|
||||
* Especially if you are a new contributor to this project, please submit only one PR
|
||||
at a time and please restrict the subject matter of the PR to a specific unit,
|
||||
module or tool. All submissions have to be reviewed and understood by the
|
||||
maintainers before they can be merged.
|
||||
|
||||
Obviously we can't verify if you follow all of these rules but certain telltale
|
||||
traits of LLM-predicted text or code will raise a flag: lack of brevity in
|
||||
descriptions or code comments, large amounts of text describing your process or
|
||||
steps that add little to understanding the changes you've made, use of an
|
||||
obsequious tone or being excessively accomodating, immediately doing requests
|
||||
without further discussion or clarifications.
|
||||
294
Cargo.lock
generated
294
Cargo.lock
generated
@@ -1,21 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
@@ -37,30 +22,17 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
||||
|
||||
[[package]]
|
||||
name = "bwavfile"
|
||||
version = "2.1.0"
|
||||
version = "2.0.2"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"chrono",
|
||||
"clap",
|
||||
"dasp_sample",
|
||||
"encoding",
|
||||
@@ -74,33 +46,6 @@ version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"time",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
@@ -116,12 +61,6 @@ dependencies = [
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||
|
||||
[[package]]
|
||||
name = "dasp_sample"
|
||||
version = "0.11.0"
|
||||
@@ -201,88 +140,17 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.144"
|
||||
version = "0.2.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
@@ -313,17 +181,6 @@ version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
@@ -333,23 +190,6 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.9"
|
||||
@@ -368,66 +208,6 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@@ -449,69 +229,3 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bwavfile"
|
||||
version = "2.1.0"
|
||||
version = "2.0.2"
|
||||
authors = ["Jamie Hardt <jamiehardt@me.com>", "Ian Hobson <ian.r.hobson@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
@@ -19,7 +19,6 @@ dasp_sample = "0.11.0"
|
||||
encoding = "0.2.33"
|
||||
uuid = "0.8.1"
|
||||
clap = "2.33.3"
|
||||
chrono = "0.4.26"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0.61"
|
||||
|
||||
44
src/bext.rs
44
src/bext.rs
@@ -1,10 +1,8 @@
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub type LU = f32;
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub type LUFS = f32;
|
||||
pub type Decibels = f32;
|
||||
|
||||
use chrono::{Local, DateTime};
|
||||
|
||||
/// Broadcast-WAV metadata record.
|
||||
///
|
||||
/// The `bext` record contains information about the original recording of the
|
||||
@@ -81,43 +79,3 @@ pub struct Bext {
|
||||
/// Coding History.
|
||||
pub coding_history: String,
|
||||
}
|
||||
|
||||
impl Default for Bext {
|
||||
/// Create a new version 0 `bext` with all description fields set to the empty string
|
||||
/// and the current local date and time filled in.
|
||||
fn default() -> Self {
|
||||
let now: DateTime<_> = Local::now();
|
||||
|
||||
Self {
|
||||
description: "".to_string(),
|
||||
originator: "".to_string(),
|
||||
originator_reference: "".to_string(),
|
||||
origination_date: now.date_naive().format("%Y-%m%-d").to_string(),
|
||||
origination_time: now.time().format("%H:%M:%S").to_string(),
|
||||
time_reference: 0,
|
||||
version: 0,
|
||||
umid: None,
|
||||
loudness_value: None,
|
||||
loudness_range: None,
|
||||
max_true_peak_level: None,
|
||||
max_momentary_loudness: None,
|
||||
max_short_term_loudness: None,
|
||||
coding_history: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn build_default() {
|
||||
let d = Bext::default();
|
||||
assert_eq!(d.description, "");
|
||||
assert_eq!(d.originator, "");
|
||||
assert_eq!(d.originator_reference, "");
|
||||
assert_eq!(d.version, 0);
|
||||
assert_eq!(d.time_reference, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ where
|
||||
self.write_u16::<LittleEndian>(format.block_alignment)?;
|
||||
self.write_u16::<LittleEndian>(format.bits_per_sample)?;
|
||||
if let Some(ext) = format.extended_format {
|
||||
let cb_size = 24u16;
|
||||
let cb_size = 22u16;
|
||||
self.write_u16::<LittleEndian>(cb_size)?;
|
||||
self.write_u16::<LittleEndian>(ext.valid_bits_per_sample)?;
|
||||
self.write_u32::<LittleEndian>(ext.channel_mask)?;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/// Format tags, UUIDs and utilities
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Format tag for integer LPCM
|
||||
@@ -90,7 +89,9 @@ impl CommonFormat {
|
||||
(WAVE_TAG_EXTENDED, Some(WAVE_UUID_PCM)) => Self::IntegerPCM,
|
||||
(WAVE_TAG_EXTENDED, Some(WAVE_UUID_FLOAT)) => Self::IeeeFloatPCM,
|
||||
(WAVE_TAG_EXTENDED, Some(WAVE_UUID_BFORMAT_PCM)) => Self::AmbisonicBFormatIntegerPCM,
|
||||
(WAVE_TAG_EXTENDED, Some(WAVE_UUID_BFORMAT_FLOAT)) => Self::AmbisonicBFormatIeeeFloatPCM,
|
||||
(WAVE_TAG_EXTENDED, Some(WAVE_UUID_BFORMAT_FLOAT)) => {
|
||||
Self::AmbisonicBFormatIeeeFloatPCM
|
||||
}
|
||||
(WAVE_TAG_EXTENDED, Some(x)) => CommonFormat::UnknownExtended(x),
|
||||
(x, _) => CommonFormat::UnknownBasic(x),
|
||||
}
|
||||
|
||||
11
src/fmt.rs
11
src/fmt.rs
@@ -1,3 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::common_format::{CommonFormat, WAVE_UUID_BFORMAT_PCM, WAVE_UUID_PCM};
|
||||
use crate::Sample;
|
||||
|
||||
@@ -8,7 +10,6 @@ use byteorder::LittleEndian;
|
||||
use byteorder::ReadBytesExt;
|
||||
|
||||
// Need more test cases for ADMAudioID
|
||||
#[allow(dead_code)]
|
||||
|
||||
/// ADM Audio ID record.
|
||||
///
|
||||
@@ -154,7 +155,7 @@ pub struct WaveFmtExtended {
|
||||
/// - [Sampler Metadata](http://www.piclist.com/techref/io/serial/midi/wave.html)
|
||||
/// - [Audio File Format Specifications](http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html) (September 2022) Prof. Peter Kabal, MMSP Lab, ECE, McGill University
|
||||
/// - [Multimedia Programming Interface and Data Specifications 1.0](http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf)
|
||||
/// (August 1991), IBM Corporation and Microsoft Corporation
|
||||
/// (August 1991), IBM Corporation and Microsoft Corporation
|
||||
///
|
||||
/// [rfc3261]: https://tools.ietf.org/html/rfc2361
|
||||
|
||||
@@ -394,7 +395,7 @@ pub trait ReadWavAudioData {
|
||||
|
||||
impl<T> ReadWavAudioData for T
|
||||
where
|
||||
T: std::io::Read
|
||||
T: std::io::Read,
|
||||
{
|
||||
/// # Panics:
|
||||
/// * If the format's [valid bits per sample](WaveFmt::valid_bits_per_sample) is
|
||||
@@ -404,7 +405,7 @@ where
|
||||
format: WaveFmt,
|
||||
into: &mut [i32],
|
||||
) -> Result<usize, std::io::Error> {
|
||||
assert!(into.len() % format.channel_count as usize == 0);
|
||||
assert!(into.len().is_multiple_of(format.channel_count as usize));
|
||||
|
||||
for frame in into {
|
||||
*frame = match (format.valid_bits_per_sample(), format.bits_per_sample) {
|
||||
@@ -424,7 +425,7 @@ where
|
||||
format: WaveFmt,
|
||||
into: &mut [f32],
|
||||
) -> Result<usize, std::io::Error> {
|
||||
assert!(into.len() % format.channel_count as usize == 0);
|
||||
assert!(into.len().is_multiple_of(format.channel_count as usize));
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,9 @@ pub use common_format::{
|
||||
};
|
||||
pub use cue::Cue;
|
||||
pub use errors::Error;
|
||||
pub use fmt::{ADMAudioID, ChannelDescriptor, ChannelMask, WaveFmt, WaveFmtExtended, ReadWavAudioData};
|
||||
pub use fmt::{
|
||||
ADMAudioID, ChannelDescriptor, ChannelMask, ReadWavAudioData, WaveFmt, WaveFmtExtended,
|
||||
};
|
||||
pub use sample::{Sample, I24};
|
||||
pub use wavereader::{AudioFrameReader, WaveReader};
|
||||
pub use wavewriter::{AudioFrameWriter, WaveWriter};
|
||||
|
||||
@@ -18,6 +18,7 @@ use super::fourcc::{BW64_SIG, DATA_SIG, DS64_SIG, RF64_SIG, RIFF_SIG, WAVE_SIG};
|
||||
const RF64_SIZE_MARKER: u32 = 0xFF_FF_FF_FF;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub enum Event {
|
||||
StartParse,
|
||||
ReadHeader {
|
||||
@@ -258,7 +259,7 @@ impl<R: Read + Seek> Parser<R> {
|
||||
|
||||
state = State::ReadyForChunk {
|
||||
at: at + 8 + this_displacement,
|
||||
remaining: remaining - 8 - this_displacement,
|
||||
remaining: remaining.saturating_sub(8 + this_displacement),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,3 +293,35 @@ impl<R: Read + Seek> Parser<R> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::Cursor;
|
||||
|
||||
#[test]
|
||||
fn parser_handles_missing_trailing_pad_on_final_odd_chunk() {
|
||||
let mut buf = Vec::new();
|
||||
buf.extend_from_slice(b"RIFF");
|
||||
buf.extend_from_slice(&39u32.to_le_bytes());
|
||||
buf.extend_from_slice(b"WAVE");
|
||||
buf.extend_from_slice(b"fmt ");
|
||||
buf.extend_from_slice(&16u32.to_le_bytes());
|
||||
buf.extend_from_slice(&[0u8; 16]);
|
||||
buf.extend_from_slice(b"data");
|
||||
buf.extend_from_slice(&3u32.to_le_bytes());
|
||||
buf.extend_from_slice(&[0xAA, 0xBB, 0xCC]);
|
||||
assert_eq!(buf.len(), 47);
|
||||
|
||||
let chunks = Parser::make(Cursor::new(&buf))
|
||||
.unwrap()
|
||||
.into_chunk_list()
|
||||
.expect("parser should accept a missing trailing pad on the final odd-length chunk");
|
||||
|
||||
assert_eq!(chunks.len(), 2);
|
||||
assert_eq!(chunks[0].signature, FourCC::from(*b"fmt "));
|
||||
assert_eq!(chunks[0].length, 16);
|
||||
assert_eq!(chunks[1].signature, DATA_SIG);
|
||||
assert_eq!(chunks[1].length, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
||||
let common_format = self.format.common_format();
|
||||
let bits_per_sample = self.format.bits_per_sample;
|
||||
|
||||
if buffer.len() % channel_count != 0 {
|
||||
if !buffer.len().is_multiple_of(channel_count) {
|
||||
return Err(Error::InvalidBufferSize {
|
||||
buffer_size: buffer.len(),
|
||||
channel_count: self.format.channel_count,
|
||||
@@ -245,7 +245,7 @@ impl<R: Read + Seek> WaveReader<R> {
|
||||
/// will return an `Err(errors::Error)` immediately if there is a structural
|
||||
/// inconsistency that makes the stream unreadable or if it's missing
|
||||
/// essential components that make interpreting the audio data impossible.
|
||||
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::fs::File;
|
||||
/// use std::io::{Error,ErrorKind};
|
||||
|
||||
@@ -51,7 +51,7 @@ where
|
||||
let format = &self.inner.inner.format;
|
||||
let channel_count = format.channel_count as usize;
|
||||
|
||||
if buffer.len() % channel_count != 0 {
|
||||
if !buffer.len().is_multiple_of(channel_count) {
|
||||
return Err(Error::InvalidBufferSize {
|
||||
buffer_size: buffer.len(),
|
||||
channel_count: format.channel_count,
|
||||
@@ -339,7 +339,7 @@ where
|
||||
assert!(data.len() < u32::MAX as usize);
|
||||
self.inner.write_u32::<LittleEndian>(data.len() as u32)?;
|
||||
self.inner.write_all(data)?;
|
||||
if data.len() % 2 == 0 {
|
||||
if data.len().is_multiple_of(2) {
|
||||
self.increment_form_length(8 + data.len() as u64)?;
|
||||
} else {
|
||||
self.inner.write_u8(0)?;
|
||||
|
||||
Reference in New Issue
Block a user