mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2025-12-31 17:00:44 +00:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a625b485d9 | ||
|
|
d17c6badfa | ||
|
|
bc6be79715 | ||
|
|
763e9a10a3 | ||
|
|
319845ae49 | ||
|
|
53fcecfc45 | ||
|
|
6776820e16 | ||
|
|
eee3c3f625 | ||
|
|
6375567af1 | ||
|
|
1a169da48f | ||
|
|
50b7b7b640 | ||
|
|
72d6be406e | ||
|
|
814b54a6e8 | ||
|
|
e826628096 | ||
|
|
0a307fbf05 | ||
|
|
e941358c8d | ||
|
|
c2cff2a893 | ||
|
|
94eb36bbb5 | ||
|
|
f2c53061dc | ||
|
|
190e8bc677 | ||
|
|
80be74c8fb | ||
|
|
5057862258 | ||
|
|
75fc40d638 | ||
|
|
2780bfb31b | ||
|
|
b160284e21 | ||
|
|
8d55b126ae | ||
|
|
b1c806598e | ||
|
|
58e43902cd | ||
|
|
48517c22bc | ||
|
|
634c21dc9a | ||
|
|
b7f82a9d63 | ||
|
|
3b88b95065 | ||
|
|
a21e17ee78 | ||
|
|
e495ad704e | ||
|
|
bbab81746f | ||
|
|
ca1d5eb714 | ||
|
|
e652722250 | ||
|
|
d0b4582dca | ||
|
|
4a0a9b7ec1 | ||
|
|
a851ed7a7f | ||
|
|
fc21173312 | ||
|
|
350599411f | ||
|
|
ec462a0b96 |
132
Cargo.lock
generated
132
Cargo.lock
generated
@@ -1,10 +1,37 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "bwavfile"
|
||||
version = "0.9.2"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"clap",
|
||||
"encoding",
|
||||
"serde_json",
|
||||
"uuid",
|
||||
@@ -12,9 +39,24 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.3.4"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"strsim",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding"
|
||||
@@ -81,10 +123,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.6"
|
||||
name = "hermit-abi"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
||||
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
@@ -94,15 +151,15 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.117"
|
||||
version = "1.0.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
||||
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.59"
|
||||
version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95"
|
||||
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@@ -110,7 +167,56 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.1"
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bwavfile"
|
||||
version = "0.9.2"
|
||||
version = "1.0.0"
|
||||
authors = ["Jamie Hardt <jamiehardt@me.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
@@ -16,8 +16,11 @@ keywords = ["audio", "broadcast", "multimedia","smpte"]
|
||||
[dependencies]
|
||||
byteorder = "1.3.4"
|
||||
encoding = "0.2.33"
|
||||
serde_json = "1.0.59"
|
||||
uuid = "0.8.1"
|
||||
clap = "2.33.3"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0.61"
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Jamie Hardt
|
||||
Copyright (c) 2021 Jamie Hardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
87
README.md
87
README.md
@@ -4,65 +4,44 @@
|
||||
[](https://github.com/iluvcapra/bwavfile/actions?query=workflow%3ARust)
|
||||
|
||||
# bwavfile
|
||||
Rust Wave File Reader/Writer with Broadcast-WAV, MBWF and RF64 Support
|
||||
Wave File Reader/Writer library in Rust, with Broadcast-WAV, MBWF and RF64 Support
|
||||
|
||||
### Features
|
||||
## Features
|
||||
|
||||
This is currently a work-in-progress! However many features presently work:
|
||||
__bwavfile__ provides a reader `WaveReader` and writer type `WaveWriter` for
|
||||
reading and creating new audio files respectively.
|
||||
|
||||
| Feature |Read |Write|
|
||||
|---------------------------------------|:---:|:-----:|
|
||||
| Standard .wav files | ☑️ | ☑️ |
|
||||
| Transparent promotion to RF64/BW64 | ☑️ | ☑️ |
|
||||
| Unified interface for regular and extended Wave format | ☑️ | ☑️ |
|
||||
| Channel/speaker map metadata | ☑️ | ☑️ |
|
||||
| Ambisonic B-format metadata | ☑️ | ☑️ |
|
||||
| EBU Broadcast-WAVE metadata | ☑️ | ☑️ |
|
||||
| Basic iXML/ADM metadata | ☑️ | ☑️ |
|
||||
| Enhanced iXML metadata support | | |
|
||||
| ADM `chna` channel metadata | | |
|
||||
| Broadcast-WAVE Level overview `levl` metadata | | |
|
||||
| Cue list metadata | ☑️ | |
|
||||
| Sampler and instrument metadata | | |
|
||||
| Enhanced Wave file form validation | ☑️ | |
|
||||
`WaveReader` and `WaveWriter` support:
|
||||
* A unified interface for standard RIFF and RF64/BW64 64-bit Wave files.
|
||||
* When using `WaveWriter`, wave files are transparently upgraded from RIFF
|
||||
to RF64 when required.
|
||||
* Unpacked reading and writing of Integer PCM and IEEE float audio data
|
||||
formats.
|
||||
* A unified interface for standard `WaveFormat` and extended `WaveFormatEx`
|
||||
wave data format specification.
|
||||
* Multichannel, surround, and ambisonic audio data description including
|
||||
surround channel maps, ADM `AudioTrackFormat`, `AudioChannelFormatRef` and
|
||||
`AudioPackRef` data structures.
|
||||
* Broadcast-Wave metdata extension, including long description, originator
|
||||
information, SMPTE UMID and coding history.
|
||||
* Reading and writing of embedded iXML and axml/ADM metadata.
|
||||
* Reading and writing of timed cues and and timed cue region.
|
||||
|
||||
### Feature Roadmap
|
||||
|
||||
Some features that may be included in the future include:
|
||||
* Broadcast-Wave `levl` waveform overview data reading and writing.
|
||||
* Sampler and Instrument mentadata.
|
||||
|
||||
|
||||
## Use Examples
|
||||
|
||||
### Reading Audio Frames From a File
|
||||
|
||||
```rust
|
||||
|
||||
use bwavfile::WaveReader;
|
||||
let mut r = WaveReader::open("tests/media/ff_silence.wav").unwrap();
|
||||
|
||||
let format = r.format().unwrap();
|
||||
assert_eq!(format.sample_rate, 44100);
|
||||
assert_eq!(format.channel_count, 1);
|
||||
|
||||
let mut buffer = format.create_frame_buffer();
|
||||
let mut frame_reader = r.audio_frame_reader().unwrap();
|
||||
|
||||
let read = frame_reader.read_integer_frame(&mut buffer).unwrap();
|
||||
|
||||
assert_eq!(buffer, [0i32]);
|
||||
assert_eq!(read, 1);
|
||||
```
|
||||
|
||||
### Accessing Channel Descriptions
|
||||
|
||||
```rust
|
||||
use bwavfile::{WaveReader, ChannelMask};
|
||||
|
||||
let mut f = WaveReader::open("tests/media/pt_24bit_51.wav").unwrap();
|
||||
|
||||
let chans = f.channels().unwrap();
|
||||
assert_eq!(chans[0].index, 0);
|
||||
assert_eq!(chans[0].speaker, ChannelMask::FrontLeft);
|
||||
assert_eq!(chans[3].index, 3);
|
||||
assert_eq!(chans[3].speaker, ChannelMask::LowFrequency);
|
||||
assert_eq!(chans[4].speaker, ChannelMask::BackLeft);
|
||||
```
|
||||
* [blits](examples/blits.rs) shows how to use `WaveWriter` to create a new
|
||||
file with BLITS alignment tones.
|
||||
* [wave-inter](examples/wave-inter.rs) uses `WaveReader` and `WaveWriter` to
|
||||
interleave several input Wave files into a single polyphonic Wave file.
|
||||
* [wave-deinter](examples/wave-deinter.rs) uses `WaveReader` and `WaveWriter`
|
||||
to de-interleave an input Wave file into several monoarual Wave files.
|
||||
|
||||
## Note on Testing
|
||||
|
||||
@@ -71,8 +50,4 @@ in zipped form. Before you can run tests, you need to `cd` into the `tests`
|
||||
directory and run the `create_test_media.sh` script. Note that one of the
|
||||
test files (the RF64 test case) is over four gigs in size.
|
||||
|
||||
Likewise, [the RF64 _writing_ test case][rf64test] writes an RF64 wave file
|
||||
to memory and is very time-intensive, so is commented-out in the code but
|
||||
can be un-commented if you want to run it on your system.
|
||||
|
||||
[rf64test]: https://github.com/iluvcapra/bwavfile/blob/1f8542a7efb481da076120bf8107032c5b48889d/src/wavewriter.rs#L399
|
||||
|
||||
@@ -1,3 +1,266 @@
|
||||
fn main() -> () {
|
||||
//! bilts.rs
|
||||
//! (c) 2021 Jamie Hardt. All rights reserved.
|
||||
//!
|
||||
//! This program demonstrates the creation of a wave file with a BLITS
|
||||
//! ("Black and Lanes' Ident Tones for Surround") channel identification and
|
||||
//! alignment signal.
|
||||
//!
|
||||
//! TODO: Pre-calculate the sine waves to speed up generation
|
||||
//! TODO: Make tone onsets less snappy
|
||||
|
||||
use std::f64;
|
||||
use std::io;
|
||||
|
||||
extern crate bwavfile;
|
||||
use bwavfile::{WaveWriter, WaveFmt, Error};
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
use clap::{Arg, App};
|
||||
|
||||
|
||||
fn sine_wave(t: u64, amplitude : i32, wavelength : u32) -> i32 {
|
||||
//I did it this way because I'm weird
|
||||
Some(t).map(|i| (i as f64) * 2f64 * f64::consts::PI / wavelength as f64 )
|
||||
.map(|f| f.sin() )
|
||||
.map(|s| (s * amplitude as f64) as i32)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Return the corresponding f32 gain for a dbfs.
|
||||
///
|
||||
/// Retval will always be positive
|
||||
fn dbfs_to_f32(dbfs : f32) -> f32 {
|
||||
10f32.powf(dbfs / 20f32)
|
||||
}
|
||||
|
||||
fn dbfs_to_signed_int(dbfs: f32, bit_depth: u16) -> i32 {
|
||||
let full_code : i32 = (1i32 << bit_depth - 1) - 1;
|
||||
((full_code as f32) * dbfs_to_f32(dbfs)) as i32
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum ToneBurst {
|
||||
/// Tone of .0 frequency (hz) for .1 duration (ms) at .2 dBfs
|
||||
Tone(f32, u64, f32),
|
||||
/// Silence of .0 Duration (ms)
|
||||
Silence(u64),
|
||||
}
|
||||
|
||||
impl ToneBurst {
|
||||
fn duration(&self, sample_rate : u32) -> u64 {
|
||||
match self {
|
||||
Self::Tone(_, dur, _) => *dur * sample_rate as u64 / 1000,
|
||||
Self::Silence(dur) => *dur * sample_rate as u64 / 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait ToneBurstSignal {
|
||||
|
||||
fn duration(&self, sample_rate: u32) -> u64;
|
||||
|
||||
fn signal(&self, t: u64, sample_rate: u32, bit_depth: u16) -> i32;
|
||||
}
|
||||
|
||||
impl ToneBurstSignal for Vec<ToneBurst> {
|
||||
|
||||
}
|
||||
fn duration(&self, sample_rate: u32) -> u64 {
|
||||
self.iter().fold(0u64, |accum, &item| {
|
||||
accum + &item.duration(sample_rate)
|
||||
})
|
||||
}
|
||||
|
||||
fn signal(&self, t: u64, sample_rate: u32, bit_depth: u16) -> i32 {
|
||||
self.iter()
|
||||
.scan(0u64, |accum, &item| {
|
||||
let dur = item.duration(sample_rate);
|
||||
let this_time_range = *accum..(*accum + dur);
|
||||
*accum = *accum + dur;
|
||||
Some( (this_time_range, item) )
|
||||
})
|
||||
.find(|(range, _)| range.contains(&t))
|
||||
.map(|(_, item)| {
|
||||
match item {
|
||||
ToneBurst::Tone(freq, _, dbfs) => {
|
||||
let gain = dbfs_to_signed_int(dbfs, bit_depth);
|
||||
sine_wave(t, gain, (sample_rate as f32 / freq) as u32)
|
||||
},
|
||||
ToneBurst::Silence(_) => {
|
||||
0
|
||||
}
|
||||
}
|
||||
}).unwrap_or(0i32)
|
||||
}
|
||||
}
|
||||
|
||||
fn create_blits_file(file_name: &str, sample_rate : u32, bits_per_sample : u16) -> Result<(),Error> {
|
||||
|
||||
// BLITS Tone signal format
|
||||
// From EBU Tech 3304 §4 - https://tech.ebu.ch/docs/tech/tech3304.pdf
|
||||
let left_channel_sequence : Vec<ToneBurst> = vec![
|
||||
// channel ident
|
||||
ToneBurst::Tone(880.0, 600, -18.0),
|
||||
ToneBurst::Silence(200),
|
||||
ToneBurst::Silence(4000),
|
||||
|
||||
// LR ident
|
||||
ToneBurst::Tone(1000.0, 1000, -18.0),
|
||||
ToneBurst::Silence(300),
|
||||
ToneBurst::Tone(1000.0, 300, -18.0),
|
||||
ToneBurst::Silence(300),
|
||||
ToneBurst::Tone(1000.0, 300, -18.0),
|
||||
ToneBurst::Silence(300),
|
||||
ToneBurst::Tone(1000.0, 300, -18.0),
|
||||
ToneBurst::Silence(300),
|
||||
ToneBurst::Tone(1000.0, 2000, -18.0),
|
||||
ToneBurst::Silence(300),
|
||||
|
||||
// Phase check,
|
||||
ToneBurst::Tone(2000.0, 3000, -24.0),
|
||||
ToneBurst::Silence(200)
|
||||
];
|
||||
|
||||
let right_channel_sequence : Vec<ToneBurst> = vec![
|
||||
// channel ident
|
||||
ToneBurst::Silence(800),
|
||||
ToneBurst::Tone(880.0, 600, -18.0),
|
||||
ToneBurst::Silence(200),
|
||||
ToneBurst::Silence(3200),
|
||||
|
||||
// LR ident
|
||||
ToneBurst::Tone(1000.0, 5100, -18.0),
|
||||
ToneBurst::Silence(300),
|
||||
|
||||
// Phase check,
|
||||
ToneBurst::Tone(2000.0, 3000, -24.0),
|
||||
ToneBurst::Silence(200)
|
||||
];
|
||||
|
||||
let center_channel_sequence : Vec<ToneBurst> = vec![
|
||||
// channel ident
|
||||
ToneBurst::Silence(1600),
|
||||
ToneBurst::Tone(1320.0, 600, -18.0),
|
||||
ToneBurst::Silence(200),
|
||||
ToneBurst::Silence(2400),
|
||||
|
||||
// LR ident
|
||||
ToneBurst::Silence(5400),
|
||||
|
||||
// Phase check,
|
||||
ToneBurst::Tone(2000.0, 3000, -24.0),
|
||||
ToneBurst::Silence(200)
|
||||
];
|
||||
|
||||
let lfe_channel_sequence : Vec<ToneBurst> = vec![
|
||||
// channel ident
|
||||
ToneBurst::Silence(2400),
|
||||
ToneBurst::Tone(82.5, 600, -18.0),
|
||||
ToneBurst::Silence(200),
|
||||
ToneBurst::Silence(1600),
|
||||
|
||||
// LR ident
|
||||
ToneBurst::Silence(5400),
|
||||
|
||||
// Phase check,
|
||||
ToneBurst::Tone(2000.0, 3000, -24.0),
|
||||
ToneBurst::Silence(200)
|
||||
];
|
||||
|
||||
let ls_channel_sequence : Vec<ToneBurst> = vec![
|
||||
// channel ident
|
||||
ToneBurst::Silence(3200),
|
||||
ToneBurst::Tone(660.0, 600, -18.0),
|
||||
ToneBurst::Silence(200),
|
||||
ToneBurst::Silence(800),
|
||||
|
||||
// LR ident
|
||||
ToneBurst::Silence(5400),
|
||||
|
||||
// Phase check,
|
||||
ToneBurst::Tone(2000.0, 3000, -24.0),
|
||||
ToneBurst::Silence(200)
|
||||
];
|
||||
|
||||
let rs_channel_sequence : Vec<ToneBurst> = vec![
|
||||
// channel ident
|
||||
ToneBurst::Silence(4000),
|
||||
ToneBurst::Tone(660.0, 600, -18.0),
|
||||
ToneBurst::Silence(200),
|
||||
|
||||
// LR ident
|
||||
ToneBurst::Silence(5400),
|
||||
|
||||
// Phase check,
|
||||
ToneBurst::Tone(2000.0, 3000, -24.0),
|
||||
ToneBurst::Silence(200)
|
||||
];
|
||||
|
||||
let length = [&left_channel_sequence, &right_channel_sequence,
|
||||
¢er_channel_sequence, &lfe_channel_sequence,
|
||||
&ls_channel_sequence, &rs_channel_sequence].iter()
|
||||
.map(|i| i.duration(sample_rate))
|
||||
.max().unwrap_or(0);
|
||||
|
||||
let frames = (0..=length).map(|frame| {
|
||||
(left_channel_sequence.signal(frame, sample_rate, bits_per_sample),
|
||||
right_channel_sequence.signal(frame, sample_rate, bits_per_sample),
|
||||
center_channel_sequence.signal(frame, sample_rate, bits_per_sample),
|
||||
lfe_channel_sequence.signal(frame, sample_rate, bits_per_sample),
|
||||
ls_channel_sequence.signal(frame, sample_rate, bits_per_sample),
|
||||
rs_channel_sequence.signal(frame, sample_rate, bits_per_sample))
|
||||
});
|
||||
|
||||
let format = WaveFmt::new_pcm_multichannel(sample_rate, bits_per_sample, 0b111111);
|
||||
|
||||
let file = WaveWriter::create(file_name, format)?;
|
||||
|
||||
let mut fw = file.audio_frame_writer()?;
|
||||
for frame in frames {
|
||||
let buf = vec![frame.0, frame.1, frame.2, frame.3, frame.4, frame.5];
|
||||
fw.write_integer_frames(&buf)?;
|
||||
}
|
||||
fw.end()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
|
||||
let matches = App::new("blits")
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!())
|
||||
.about("Generate a BLITS 5.1 alignment tone.")
|
||||
.arg(Arg::with_name("sample_rate")
|
||||
.long("sample-rate")
|
||||
.short("s")
|
||||
.help("Sample rate of output")
|
||||
.default_value("48000")
|
||||
)
|
||||
.arg(Arg::with_name("bit_depth")
|
||||
.long("bit-depth")
|
||||
.short("b")
|
||||
.help("Bit depth of output")
|
||||
.default_value("24")
|
||||
)
|
||||
.arg(Arg::with_name("OUTPUT")
|
||||
.help("Output wave file")
|
||||
.default_value("blits.wav")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let sample_rate = matches.value_of("sample_rate").unwrap().parse::<u32>()
|
||||
.expect("Failed to read sample rate");
|
||||
|
||||
let bits_per_sample = matches.value_of("bit_depth").unwrap().parse::<u16>()
|
||||
.expect("Failed to read bit depth");
|
||||
|
||||
let filename = matches.value_of("OUTPUT").unwrap();
|
||||
|
||||
match create_blits_file(&filename, sample_rate, bits_per_sample) {
|
||||
Err( Error::IOError(x) ) => panic!("IO Error: {:?}", x),
|
||||
Err( err ) => panic!("Error: {:?}", err),
|
||||
Ok(()) => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fn main() -> () {
|
||||
|
||||
}
|
||||
119
examples/wave-deinter.rs
Normal file
119
examples/wave-deinter.rs
Normal file
@@ -0,0 +1,119 @@
|
||||
//! wave-inter.rs
|
||||
//! (c) 2021 Jamie Hardt. All rights reserved.
|
||||
//!
|
||||
//! This program demonstrats combining several wave files into a single
|
||||
//! polyphonic wave file.
|
||||
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
extern crate bwavfile;
|
||||
use bwavfile::{Error,WaveReader, WaveWriter, ChannelDescriptor, ChannelMask, WaveFmt};
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
use clap::{Arg, App};
|
||||
|
||||
fn name_suffix(force_numeric : bool, delim : &str, index: usize, channel_descriptor : &ChannelDescriptor) -> String {
|
||||
if force_numeric || channel_descriptor.speaker == ChannelMask::DirectOut {
|
||||
format!("{}A{:02}", delim, index)
|
||||
} else {
|
||||
let chan_name = match channel_descriptor.speaker {
|
||||
ChannelMask::FrontLeft => "L",
|
||||
ChannelMask::FrontCenter => "C",
|
||||
ChannelMask::FrontRight => "R",
|
||||
ChannelMask::BackLeft => "Ls",
|
||||
ChannelMask::BackRight => "Rs",
|
||||
ChannelMask::BackCenter => "S",
|
||||
ChannelMask::TopCenter => "Tc",
|
||||
ChannelMask::LowFrequency => "Lfe",
|
||||
ChannelMask::SideLeft => "Lss",
|
||||
ChannelMask::SideRight => "Rss",
|
||||
ChannelMask::FrontCenterLeft => "Lc",
|
||||
ChannelMask::FrontCenterRight => "Rc",
|
||||
ChannelMask::TopFrontLeft => "Ltf",
|
||||
ChannelMask::TopFrontCenter => "Ctf",
|
||||
ChannelMask::TopFrontRight => "Rtf",
|
||||
ChannelMask::TopBackLeft => "Ltb",
|
||||
ChannelMask::TopBackCenter => "Ctb",
|
||||
ChannelMask::TopBackRight => "Rtb",
|
||||
ChannelMask::DirectOut => panic!("Error, can't get here")
|
||||
};
|
||||
format!("{}{}", delim, chan_name)
|
||||
}
|
||||
}
|
||||
|
||||
fn process_file(infile: &str, delim : &str, numeric_channel_names : bool) -> Result<(), Error> {
|
||||
let mut input_file = WaveReader::open(infile)?;
|
||||
let channel_desc = input_file.channels()?;
|
||||
let input_format = input_file.format()?;
|
||||
|
||||
if channel_desc.len() == 1 {
|
||||
println!("Input file in monoaural, exiting.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let infile_path = Path::new(infile);
|
||||
let basename = infile_path.file_stem().expect("Unable to extract file basename").to_str().unwrap();
|
||||
let output_dir = infile_path.parent().expect("Unable to derive parent directory");
|
||||
|
||||
let ouptut_format = WaveFmt::new_pcm_mono(input_format.sample_rate, input_format.bits_per_sample);
|
||||
let mut input_wave_reader = input_file.audio_frame_reader()?;
|
||||
|
||||
for (n, channel) in channel_desc.iter().enumerate() {
|
||||
let suffix = name_suffix(numeric_channel_names, delim, n + 1, channel);
|
||||
let outfile_name = output_dir.join(format!("{}{}.wav", basename, suffix))
|
||||
.into_os_string().into_string().unwrap();
|
||||
|
||||
println!("Will create file {}", outfile_name);
|
||||
|
||||
let output_file = WaveWriter::create(&outfile_name, ouptut_format).expect("Failed to create new file");
|
||||
|
||||
let mut output_wave_writer = output_file.audio_frame_writer()?;
|
||||
let mut buffer = input_format.create_frame_buffer(1);
|
||||
|
||||
while input_wave_reader.read_integer_frame(&mut buffer)? > 0 {
|
||||
output_wave_writer.write_integer_frames(&buffer[n..=n])?;
|
||||
}
|
||||
|
||||
output_wave_writer.end()?;
|
||||
input_wave_reader.locate(0)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let matches = App::new("wave-deinter")
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!())
|
||||
.about("Extract each channel of a polyphonic wave file as a new monoaural wave file.")
|
||||
.arg(Arg::with_name("numeric_names")
|
||||
.long("numeric")
|
||||
.short("n")
|
||||
.help("Use numeric channel names \"01\" \"02\" etc.")
|
||||
.takes_value(false)
|
||||
)
|
||||
.arg(Arg::with_name("channel_delimiter")
|
||||
.long("delim")
|
||||
.short("d")
|
||||
.help("Channel label delimiter.")
|
||||
.default_value(".")
|
||||
)
|
||||
.arg(Arg::with_name("INPUT")
|
||||
.help("Input wave file")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let delimiter = matches.value_of("channel_delimiter").unwrap();
|
||||
let use_numeric_names = matches.is_present("numeric_names");
|
||||
let infile = matches.value_of("INPUT").unwrap();
|
||||
|
||||
match process_file(infile, delimiter, use_numeric_names) {
|
||||
Err(Error::IOError(io)) => Err(io),
|
||||
Err(e) => panic!("Error: {:?}", e),
|
||||
Ok(()) => Ok(())
|
||||
}
|
||||
}
|
||||
35
examples/wave-inter.rs
Normal file
35
examples/wave-inter.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! wave-inter.rs
|
||||
//! (c) 2021 Jamie Hardt. All rights reserved.
|
||||
//!
|
||||
//! This program demonstrates combining several wave files into a single
|
||||
//! polyphonic wave file.
|
||||
|
||||
use std::io;
|
||||
|
||||
extern crate bwavfile;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
use clap::{Arg, App};
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let matches = App::new("wave-inter")
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!())
|
||||
.about("Combine several wave files into a single polyphonic wave file.")
|
||||
.arg(Arg::with_name("OUTPUT")
|
||||
.long("output")
|
||||
.short("o")
|
||||
.help("Output file name. If absent, will be basename, minus any channel extension, of first INPUT.")
|
||||
)
|
||||
.arg(Arg::with_name("INPUT")
|
||||
.help("Input wave file")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
println!("Command line opts: {:?}", matches);
|
||||
|
||||
todo!("Finish implementation");
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
use std::io::{Read, Seek};
|
||||
use std::io::SeekFrom::{Start,Current,};
|
||||
|
||||
use byteorder::LittleEndian;
|
||||
use byteorder::ReadBytesExt;
|
||||
|
||||
use super::fmt::{WaveFmt};
|
||||
use super::errors::Error;
|
||||
use super::CommonFormat;
|
||||
|
||||
/// Read audio frames
|
||||
///
|
||||
/// The inner reader is interpreted as a raw audio data
|
||||
/// bitstream having a format specified by `format`.
|
||||
///
|
||||
#[derive(Debug)]
|
||||
pub struct AudioFrameReader<R: Read + Seek> {
|
||||
inner : R,
|
||||
format: WaveFmt,
|
||||
start: u64,
|
||||
length: u64
|
||||
}
|
||||
|
||||
impl<R: Read + Seek> AudioFrameReader<R> {
|
||||
|
||||
/// Create a new `AudioFrameReader`
|
||||
///
|
||||
/// ### Panics
|
||||
///
|
||||
/// This method does a few sanity checks on the provided format
|
||||
/// parameter to confirm the `block_alignment` law is fulfilled
|
||||
/// and the format tag is readable by this implementation (only
|
||||
/// format 0x01 is supported at this time.)
|
||||
pub fn new(mut inner: R, format: WaveFmt, start: u64, length: u64) -> Result<Self, Error> {
|
||||
assert!(format.block_alignment * 8 == format.bits_per_sample * format.channel_count,
|
||||
"Unable to read audio frames from packed formats: block alignment is {}, should be {}",
|
||||
format.block_alignment, (format.bits_per_sample / 8 ) * format.channel_count);
|
||||
|
||||
assert!(format.common_format() == CommonFormat::IntegerPCM ,
|
||||
"Unsupported format tag {:?}", format.tag);
|
||||
|
||||
inner.seek(Start(start))?;
|
||||
Ok( AudioFrameReader { inner , format , start, length} )
|
||||
}
|
||||
|
||||
/// Unwrap the inner reader.
|
||||
pub fn into_inner(self) -> R {
|
||||
self.inner
|
||||
}
|
||||
|
||||
/// Locate the read position to a different frame
|
||||
///
|
||||
/// Seeks within the audio stream.
|
||||
///
|
||||
/// Returns the new location of the read position.
|
||||
///
|
||||
/// locate() behaves similarly to Read methods in that
|
||||
/// seeking after the end of the audio data is not an error.
|
||||
pub fn locate(&mut self, to :u64) -> Result<u64,Error> {
|
||||
let position = to * self.format.block_alignment as u64;
|
||||
let seek_result = self.inner.seek(Start(self.start + position))?;
|
||||
Ok( (seek_result - self.start) / self.format.block_alignment as u64 )
|
||||
}
|
||||
|
||||
|
||||
/// Read a frame
|
||||
///
|
||||
/// A single frame is read from the audio stream and the read location
|
||||
/// is advanced one frame.
|
||||
///
|
||||
/// Regardless of the number of bits in the audio sample, this method
|
||||
/// always writes `i32` samples back to the buffer. These samples are
|
||||
/// written back "right-aligned" so samples that are shorter than i32
|
||||
/// will leave the MSB bits empty.
|
||||
///
|
||||
/// For example: A full-code sample in 16 bit (0xFFFF) will be written
|
||||
/// back to the buffer as 0x0000FFFF.
|
||||
///
|
||||
///
|
||||
/// ### Panics
|
||||
///
|
||||
/// The `buffer` must have a number of elements equal to the number of
|
||||
/// channels and this method will panic if this is not the case.
|
||||
pub fn read_integer_frame(&mut self, buffer:&mut [i32]) -> Result<u64,Error> {
|
||||
assert!(buffer.len() as u16 == self.format.channel_count,
|
||||
"read_integer_frame was called with a mis-sized buffer, expected {}, was {}",
|
||||
self.format.channel_count, buffer.len());
|
||||
|
||||
let framed_bits_per_sample = self.format.block_alignment * 8 / self.format.channel_count;
|
||||
|
||||
let tell = self.inner.seek(Current(0))?;
|
||||
|
||||
if (tell - self.start) < self.length {
|
||||
for n in 0..(self.format.channel_count as usize) {
|
||||
buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
||||
(0..=8,8) => self.inner.read_u8()? as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||
(9..=16,16) => self.inner.read_i16::<LittleEndian>()? as i32,
|
||||
(10..=24,24) => self.inner.read_i24::<LittleEndian>()?,
|
||||
(25..=32,32) => self.inner.read_i32::<LittleEndian>()?,
|
||||
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||
b, self.format.channel_count, self.format.block_alignment)
|
||||
}
|
||||
}
|
||||
Ok( 1 )
|
||||
} else {
|
||||
Ok( 0 )
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ pub type Decibels = f32;
|
||||
/// - [EBU Tech R099](https://tech.ebu.ch/docs/r/r099.pdf) (October 2011) "‘Unique’ Source Identifier (USID) for use in the
|
||||
/// <OriginatorReference> field of the Broadcast Wave Format"
|
||||
|
||||
// Note for me later:
|
||||
// get env values: https://doc.rust-lang.org/std/macro.option_env.html
|
||||
// Cargo env values: https://doc.rust-lang.org/cargo/reference/environment-variables.html
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Bext {
|
||||
|
||||
|
||||
@@ -33,7 +33,14 @@ impl<T> WriteBWaveChunks for T where T: Write {
|
||||
self.write_u32::<LittleEndian>(format.bytes_per_second)?;
|
||||
self.write_u16::<LittleEndian>(format.block_alignment)?;
|
||||
self.write_u16::<LittleEndian>(format.bits_per_sample)?;
|
||||
// self.write_u8(0)?;
|
||||
if let Some(ext) = format.extended_format {
|
||||
let cb_size = 24u16;
|
||||
self.write_u16::<LittleEndian>(cb_size)?;
|
||||
self.write_u16::<LittleEndian>(ext.valid_bits_per_sample)?;
|
||||
self.write_u32::<LittleEndian>(ext.channel_mask)?;
|
||||
let uuid = ext.type_guid.as_bytes();
|
||||
self.write(uuid)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
143
src/cue.rs
143
src/cue.rs
@@ -1,13 +1,14 @@
|
||||
use super::fourcc::{FourCC,ReadFourCC, LABL_SIG, NOTE_SIG, LTXT_SIG};
|
||||
use super::fourcc::{FourCC,ReadFourCC, WriteFourCC, LABL_SIG, NOTE_SIG,
|
||||
ADTL_SIG, LTXT_SIG, DATA_SIG};
|
||||
use super::list_form::collect_list_form;
|
||||
|
||||
use byteorder::{ReadBytesExt, LittleEndian};
|
||||
use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian};
|
||||
|
||||
use encoding::{DecoderTrap};
|
||||
use encoding::{DecoderTrap,EncoderTrap};
|
||||
use encoding::{Encoding};
|
||||
use encoding::all::ASCII;
|
||||
|
||||
use std::io::{Cursor, Error, Read};
|
||||
use std::io::{Cursor, Error, Read, Write};
|
||||
|
||||
#[derive(Copy,Clone, Debug)]
|
||||
struct RawCue {
|
||||
@@ -20,6 +21,23 @@ struct RawCue {
|
||||
}
|
||||
|
||||
impl RawCue {
|
||||
|
||||
fn write_to(cues : Vec<Self>) -> Vec<u8> {
|
||||
let mut writer = Cursor::new(vec![0u8; 0]);
|
||||
|
||||
writer.write_u32::<LittleEndian>(cues.len() as u32).unwrap();
|
||||
for cue in cues.iter() {
|
||||
writer.write_u32::<LittleEndian>(cue.cue_point_id).unwrap();
|
||||
writer.write_u32::<LittleEndian>(cue.frame).unwrap();
|
||||
writer.write_fourcc(cue.chunk_id).unwrap();
|
||||
writer.write_u32::<LittleEndian>(cue.chunk_start).unwrap();
|
||||
writer.write_u32::<LittleEndian>(cue.block_start).unwrap();
|
||||
writer.write_u32::<LittleEndian>(cue.frame_offset).unwrap();
|
||||
}
|
||||
|
||||
writer.into_inner()
|
||||
}
|
||||
|
||||
fn read_from(data : &[u8]) -> Result<Vec<Self>,Error> {
|
||||
let mut rdr = Cursor::new(data);
|
||||
let count = rdr.read_u32::<LittleEndian>()?;
|
||||
@@ -47,6 +65,14 @@ struct RawLabel {
|
||||
}
|
||||
|
||||
impl RawLabel {
|
||||
|
||||
fn write_to(&self) -> Vec<u8> {
|
||||
let mut writer = Cursor::new(vec![0u8;0]);
|
||||
writer.write_u32::<LittleEndian>(self.cue_point_id as u32).unwrap();
|
||||
writer.write(&self.text).unwrap();
|
||||
writer.into_inner()
|
||||
}
|
||||
|
||||
fn read_from(data : &[u8]) -> Result<Self, Error> {
|
||||
let mut rdr = Cursor::new(data);
|
||||
let length = data.len();
|
||||
@@ -69,6 +95,14 @@ struct RawNote {
|
||||
}
|
||||
|
||||
impl RawNote {
|
||||
|
||||
fn write_to(&self) -> Vec<u8> {
|
||||
let mut writer = Cursor::new(vec![0u8; 0]);
|
||||
writer.write_u32::<LittleEndian>(self.cue_point_id).unwrap();
|
||||
writer.write(&self.text).unwrap();
|
||||
writer.into_inner()
|
||||
}
|
||||
|
||||
fn read_from(data : &[u8]) -> Result<Self, Error> {
|
||||
let mut rdr = Cursor::new(data);
|
||||
let length = data.len();
|
||||
@@ -97,6 +131,22 @@ struct RawLtxt {
|
||||
}
|
||||
|
||||
impl RawLtxt {
|
||||
|
||||
fn write_to(&self) -> Vec<u8> {
|
||||
let mut writer = Cursor::new(vec![0u8; 0]);
|
||||
writer.write_u32::<LittleEndian>(self.cue_point_id).unwrap();
|
||||
writer.write_u32::<LittleEndian>(self.frame_length).unwrap();
|
||||
writer.write_fourcc(self.purpose).unwrap();
|
||||
writer.write_u16::<LittleEndian>(self.country).unwrap();
|
||||
writer.write_u16::<LittleEndian>(self.language).unwrap();
|
||||
writer.write_u16::<LittleEndian>(self.dialect).unwrap();
|
||||
writer.write_u16::<LittleEndian>(self.code_page).unwrap();
|
||||
if let Some(ext_text) = &self.text {
|
||||
writer.write(ext_text).unwrap();
|
||||
}
|
||||
writer.into_inner()
|
||||
}
|
||||
|
||||
fn read_from(data : &[u8]) -> Result<Self, Error> {
|
||||
let mut rdr = Cursor::new(data);
|
||||
let length = data.len();
|
||||
@@ -131,6 +181,30 @@ enum RawAdtlMember {
|
||||
}
|
||||
|
||||
impl RawAdtlMember {
|
||||
fn compile_adtl(members : &[Self]) -> Vec<u8> {
|
||||
let mut w = Cursor::new(vec![0u8; 0]);
|
||||
// It seems like all this casing could be done with traits
|
||||
for member in members.iter() {
|
||||
let (fcc, buf) = match member {
|
||||
RawAdtlMember::Label(l) => ( (LABL_SIG, l.write_to()) ),
|
||||
RawAdtlMember::Note(n) => ( (NOTE_SIG, n.write_to()) ),
|
||||
RawAdtlMember::LabeledText(t) => ( (LTXT_SIG, t.write_to()) ),
|
||||
RawAdtlMember::Unrecognized(f) => (*f, vec![0u8;0] ) // <-- this is a dopey case but here for completeness
|
||||
};
|
||||
w.write_fourcc(fcc).unwrap();
|
||||
w.write_u32::<LittleEndian>(buf.len() as u32).unwrap();
|
||||
w.write(&buf).unwrap();
|
||||
if buf.len() % 2 == 1 { w.write_u8(0).unwrap(); }
|
||||
}
|
||||
|
||||
let chunk_content = w.into_inner();
|
||||
let mut writer = Cursor::new(vec![0u8; 0]);
|
||||
writer.write_fourcc(ADTL_SIG).unwrap();
|
||||
writer.write_u32::<LittleEndian>(chunk_content.len() as u32).unwrap();
|
||||
writer.write(&chunk_content).unwrap();
|
||||
writer.into_inner()
|
||||
}
|
||||
|
||||
fn collect_from(chunk : &[u8]) -> Result<Vec<RawAdtlMember>,Error> {
|
||||
let chunks = collect_list_form(chunk)?;
|
||||
let mut retval : Vec<RawAdtlMember> = vec![];
|
||||
@@ -197,9 +271,6 @@ impl AdtlMemberSearch for Vec<RawAdtlMember> {
|
||||
/// - [EBU 3285 Supplement 2](https://tech.ebu.ch/docs/tech/tech3285s2.pdf) (July 2001): Quality chunk and cuesheet
|
||||
pub struct Cue {
|
||||
|
||||
/// Unique numeric identifier for this cue
|
||||
pub ident : u32,
|
||||
|
||||
/// The time of this marker
|
||||
pub frame : u32,
|
||||
|
||||
@@ -219,8 +290,64 @@ fn convert_to_cue_string(buffer : &[u8]) -> String {
|
||||
ASCII.decode(&trimmed, DecoderTrap::Ignore).expect("Error decoding text")
|
||||
}
|
||||
|
||||
fn convert_from_cue_string(val : &str) -> Vec<u8> {
|
||||
ASCII.encode(&val, EncoderTrap::Ignore).expect("Error encoding text")
|
||||
}
|
||||
|
||||
impl Cue {
|
||||
|
||||
/// Take a list of `Cue`s and convert it into `RawCue` and `RawAdtlMember`s
|
||||
fn compile_to(cues : &[Cue]) -> (Vec<RawCue>, Vec<RawAdtlMember>) {
|
||||
cues.iter().enumerate()
|
||||
.map(|(n, cue)| {
|
||||
let raw_cue = RawCue {
|
||||
cue_point_id: n as u32,
|
||||
frame : cue.frame,
|
||||
chunk_id: DATA_SIG,
|
||||
chunk_start: 0,
|
||||
block_start: 0,
|
||||
frame_offset: cue.frame
|
||||
};
|
||||
|
||||
let raw_label = cue.label.as_ref().map(|val| {
|
||||
RawLabel {
|
||||
cue_point_id : n as u32,
|
||||
text: convert_from_cue_string(&val)
|
||||
}
|
||||
});
|
||||
|
||||
let raw_note = cue.note.as_ref().map(|val| {
|
||||
RawNote {
|
||||
cue_point_id: n as u32,
|
||||
text : convert_from_cue_string(&val)
|
||||
}
|
||||
});
|
||||
|
||||
let raw_ltxt = cue.length.map(|val| {
|
||||
RawLtxt {
|
||||
cue_point_id : n as u32,
|
||||
frame_length : val,
|
||||
purpose : FourCC::make(b"rgn "),
|
||||
country : 0,
|
||||
language : 0,
|
||||
dialect : 0,
|
||||
code_page : 0,
|
||||
text : None
|
||||
}
|
||||
});
|
||||
|
||||
(raw_cue, raw_label, raw_note, raw_ltxt)
|
||||
})
|
||||
.fold((Vec::<RawCue>::new(), Vec::<RawAdtlMember>::new()),
|
||||
|(mut cues, mut adtls) , (cue, label, note, ltxt)| {
|
||||
cues.push(cue);
|
||||
label.map(|l| adtls.push( RawAdtlMember::Label(l)));
|
||||
note.map(|n| adtls.push(RawAdtlMember::Note(n)));
|
||||
ltxt.map(|m| adtls.push(RawAdtlMember::LabeledText(m)));
|
||||
(cues, adtls)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn collect_from(cue_chunk : &[u8], adtl_chunk : Option<&[u8]>) -> Result<Vec<Cue>, Error> {
|
||||
let raw_cues = RawCue::read_from(cue_chunk)?;
|
||||
let raw_adtl : Vec<RawAdtlMember>;
|
||||
@@ -236,7 +363,7 @@ impl Cue {
|
||||
raw_cues.iter()
|
||||
.map(|i| {
|
||||
Cue {
|
||||
ident : i.cue_point_id,
|
||||
//ident : i.cue_point_id,
|
||||
frame : i.frame,
|
||||
length: {
|
||||
raw_adtl.ltxt_for_cue_point(i.cue_point_id).first()
|
||||
|
||||
90
src/fmt.rs
90
src/fmt.rs
@@ -3,7 +3,7 @@ use super::common_format::{CommonFormat, UUID_PCM,UUID_BFORMAT_PCM};
|
||||
use std::io::Cursor;
|
||||
|
||||
use byteorder::LittleEndian;
|
||||
use byteorder::WriteBytesExt;
|
||||
use byteorder::{WriteBytesExt, ReadBytesExt};
|
||||
|
||||
// Need more test cases for ADMAudioID
|
||||
#[allow(dead_code)]
|
||||
@@ -290,22 +290,23 @@ impl WaveFmt {
|
||||
CommonFormat::make( self.tag, self.extended_format.map(|ext| ext.type_guid))
|
||||
}
|
||||
|
||||
/// Create a frame buffer sized to hold frames for a reader or writer
|
||||
/// Create a frame buffer sized to hold `length` frames for a reader or
|
||||
/// writer
|
||||
///
|
||||
/// This is a conveneince method that creates a `Vec<i32>` with
|
||||
/// as many elements as there are channels in the underlying stream.
|
||||
pub fn create_frame_buffer(&self) -> Vec<i32> {
|
||||
vec![0i32; self.channel_count as usize]
|
||||
pub fn create_frame_buffer(&self, length : usize) -> Vec<i32> {
|
||||
vec![0i32; self.channel_count as usize * length]
|
||||
}
|
||||
|
||||
/// Calculate the size of a byte buffer needed to hold audio data of this
|
||||
/// format for a given number of frames
|
||||
pub fn buffer_length(&self, frame_count: u64) -> usize {
|
||||
(self.block_alignment as u64 * frame_count) as usize
|
||||
/// Create a raw byte buffer to hold `length` blocks from a reader or
|
||||
/// writer
|
||||
pub fn create_raw_buffer(&self, length : usize) -> Vec<u8> {
|
||||
vec![0u8; self.block_alignment as usize * length]
|
||||
}
|
||||
|
||||
// Write frames into a byte vector
|
||||
pub fn pack_frames(&self, from_frames: &[i32], into_bytes: &mut Vec<u8>) -> () {
|
||||
/// Write frames into a byte vector
|
||||
pub fn pack_frames(&self, from_frames: &[i32], into_bytes: &mut [u8]) -> () {
|
||||
let mut write_cursor = Cursor::new(into_bytes);
|
||||
|
||||
assert!(from_frames.len() % self.channel_count as usize == 0,
|
||||
@@ -325,18 +326,19 @@ impl WaveFmt {
|
||||
}
|
||||
|
||||
/// Read bytes into frames
|
||||
// pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut Vec<i32>) -> () {
|
||||
// for n in 0..(from_bytes.len()) {
|
||||
// buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
||||
// (0..=8,8) => self.inner.read_u8()? as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||
// (9..=16,16) => self.inner.read_i16::<LittleEndian>()? as i32,
|
||||
// (10..=24,24) => self.inner.read_i24::<LittleEndian>()?,
|
||||
// (25..=32,32) => self.inner.read_i32::<LittleEndian>()?,
|
||||
// (b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||
// b, self.format.channel_count, self.format.block_alignment)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32]) -> () {
|
||||
let mut rdr = Cursor::new(from_bytes);
|
||||
for n in 0..(into_frames.len()) {
|
||||
into_frames[n] = match (self.valid_bits_per_sample(), self.bits_per_sample) {
|
||||
(0..=8,8) => rdr.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||
(9..=16,16) => rdr.read_i16::<LittleEndian>().unwrap() as i32,
|
||||
(10..=24,24) => rdr.read_i24::<LittleEndian>().unwrap(),
|
||||
(25..=32,32) => rdr.read_i32::<LittleEndian>().unwrap(),
|
||||
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||
b, self.channel_count, self.block_alignment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Channel descriptors for each channel.
|
||||
@@ -379,3 +381,47 @@ impl WaveFmt {
|
||||
}
|
||||
}
|
||||
|
||||
trait ReadWavAudioData {
|
||||
fn read_i32_frames(&mut self, format: WaveFmt, into: &mut [i32]) -> Result<usize,std::io::Error>;
|
||||
fn read_f32_frames(&mut self, format: WaveFmt, into: &mut [f32]) -> Result<usize,std::io::Error>;
|
||||
}
|
||||
|
||||
impl<T> ReadWavAudioData for T where T: std::io::Read {
|
||||
|
||||
fn read_i32_frames(&mut self, format: WaveFmt, into: &mut [i32]) -> Result<usize, std::io::Error> {
|
||||
assert!(into.len() % format.channel_count as usize == 0);
|
||||
|
||||
for n in 0..(into.len()) {
|
||||
into[n] = match (format.valid_bits_per_sample(), format.bits_per_sample) {
|
||||
(0..=8,8) => self.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||
(9..=16,16) => self.read_i16::<LittleEndian>().unwrap() as i32,
|
||||
(10..=24,24) => self.read_i24::<LittleEndian>().unwrap(),
|
||||
(25..=32,32) => self.read_i32::<LittleEndian>().unwrap(),
|
||||
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||
b, format.channel_count, format.block_alignment)
|
||||
}
|
||||
}
|
||||
|
||||
todo!()
|
||||
}
|
||||
fn read_f32_frames(&mut self, format: WaveFmt, into: &mut [f32]) -> Result<usize, std::io::Error> {
|
||||
assert!(into.len() % format.channel_count as usize == 0);
|
||||
todo!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trait WriteWavAudioData {
|
||||
fn write_i32_frames(&mut self, format: WaveFmt, from: &[i32]) -> Result<usize, std::io::Error>;
|
||||
fn write_f32_frames(&mut self, format: WaveFmt, from: &[f32]) -> Result<usize, std::io::Error>;
|
||||
}
|
||||
|
||||
impl<T> WriteWavAudioData for T where T: std::io::Write {
|
||||
|
||||
fn write_i32_frames(&mut self, format: WaveFmt, _: &[i32]) -> Result<usize, std::io::Error> {
|
||||
todo!()
|
||||
}
|
||||
fn write_f32_frames(&mut self, format: WaveFmt, _: &[f32]) -> Result<usize, std::io::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
11
src/lib.rs
11
src/lib.rs
@@ -35,12 +35,6 @@ Apps we test against:
|
||||
[github]: https://github.com/iluvcapra/bwavfile
|
||||
*/
|
||||
|
||||
// #![feature(external_doc)]
|
||||
|
||||
// #[doc(include="../README.md")]
|
||||
// #[cfg(doctest)]
|
||||
// pub struct ReadmeDoctests;
|
||||
|
||||
extern crate encoding;
|
||||
extern crate byteorder;
|
||||
extern crate uuid;
|
||||
@@ -50,8 +44,6 @@ mod errors;
|
||||
mod common_format;
|
||||
|
||||
mod parser;
|
||||
|
||||
mod audio_frame_reader;
|
||||
mod list_form;
|
||||
|
||||
mod chunks;
|
||||
@@ -63,10 +55,9 @@ mod wavereader;
|
||||
mod wavewriter;
|
||||
|
||||
pub use errors::Error;
|
||||
pub use wavereader::WaveReader;
|
||||
pub use wavereader::{WaveReader, AudioFrameReader};
|
||||
pub use wavewriter::{WaveWriter, AudioFrameWriter};
|
||||
pub use bext::Bext;
|
||||
pub use fmt::{WaveFmt, WaveFmtExtended, ChannelDescriptor, ChannelMask, ADMAudioID};
|
||||
pub use common_format::CommonFormat;
|
||||
pub use audio_frame_reader::AudioFrameReader;
|
||||
pub use cue::Cue;
|
||||
@@ -1,22 +1,131 @@
|
||||
|
||||
use std::io::SeekFrom;
|
||||
use std::fs::File;
|
||||
|
||||
use std::io::SeekFrom;
|
||||
use std::io::Cursor;
|
||||
use std::io::{Read, Seek, BufReader};
|
||||
use std::io::SeekFrom::{Start,Current,};
|
||||
|
||||
use super::parser::Parser;
|
||||
use super::fourcc::{FourCC, ReadFourCC, FMT__SIG,DATA_SIG, BEXT_SIG, LIST_SIG, JUNK_SIG, FLLR_SIG, CUE__SIG,
|
||||
ADTL_SIG, AXML_SIG, IXML_SIG};
|
||||
use super::fourcc::{FourCC, ReadFourCC, FMT__SIG, DATA_SIG, BEXT_SIG, LIST_SIG,
|
||||
JUNK_SIG, FLLR_SIG, CUE__SIG, ADTL_SIG, AXML_SIG, IXML_SIG};
|
||||
use super::errors::Error as ParserError;
|
||||
use super::fmt::{WaveFmt, ChannelDescriptor, ChannelMask};
|
||||
use super::bext::Bext;
|
||||
use super::audio_frame_reader::AudioFrameReader;
|
||||
use super::chunks::ReadBWaveChunks;
|
||||
use super::cue::Cue;
|
||||
use super::errors::Error;
|
||||
use super::CommonFormat;
|
||||
|
||||
use std::io::Cursor;
|
||||
use std::io::{Read, Seek};
|
||||
use byteorder::LittleEndian;
|
||||
use byteorder::ReadBytesExt;
|
||||
|
||||
|
||||
|
||||
/// Read audio frames
|
||||
///
|
||||
/// The inner reader is interpreted as a raw audio data
|
||||
/// bitstream having a format specified by `format`.
|
||||
///
|
||||
#[derive(Debug)]
|
||||
pub struct AudioFrameReader<R: Read + Seek> {
|
||||
inner : R,
|
||||
format: WaveFmt,
|
||||
start: u64,
|
||||
length: u64
|
||||
}
|
||||
|
||||
impl<R: Read + Seek> AudioFrameReader<R> {
|
||||
|
||||
/// Create a new `AudioFrameReader`
|
||||
///
|
||||
/// ### Panics
|
||||
///
|
||||
/// This method does a few sanity checks on the provided format
|
||||
/// parameter to confirm the `block_alignment` law is fulfilled
|
||||
/// and the format tag is readable by this implementation (only
|
||||
/// format 0x01 is supported at this time.)
|
||||
pub fn new(mut inner: R, format: WaveFmt, start: u64, length: u64) -> Result<Self, Error> {
|
||||
assert!(format.block_alignment * 8 == format.bits_per_sample * format.channel_count,
|
||||
"Unable to read audio frames from packed formats: block alignment is {}, should be {}",
|
||||
format.block_alignment, (format.bits_per_sample / 8 ) * format.channel_count);
|
||||
|
||||
assert!(format.common_format() == CommonFormat::IntegerPCM ,
|
||||
"Unsupported format tag {:?}", format.tag);
|
||||
|
||||
inner.seek(Start(start))?;
|
||||
Ok( AudioFrameReader { inner , format , start, length} )
|
||||
}
|
||||
|
||||
/// Unwrap the inner reader.
|
||||
pub fn into_inner(self) -> R {
|
||||
self.inner
|
||||
}
|
||||
|
||||
/// Locate the read position to a different frame
|
||||
///
|
||||
/// Seeks within the audio stream.
|
||||
///
|
||||
/// Returns the new location of the read position.
|
||||
///
|
||||
/// locate() behaves similarly to Read methods in that
|
||||
/// seeking after the end of the audio data is not an error.
|
||||
pub fn locate(&mut self, to :u64) -> Result<u64,Error> {
|
||||
let position = to * self.format.block_alignment as u64;
|
||||
let seek_result = self.inner.seek(Start(self.start + position))?;
|
||||
Ok( (seek_result - self.start) / self.format.block_alignment as u64 )
|
||||
}
|
||||
|
||||
|
||||
/// Read a frame
|
||||
///
|
||||
/// A single frame is read from the audio stream and the read location
|
||||
/// is advanced one frame.
|
||||
///
|
||||
/// Regardless of the number of bits in the audio sample, this method
|
||||
/// always writes `i32` samples back to the buffer. These samples are
|
||||
/// written back "right-aligned" so samples that are shorter than i32
|
||||
/// will leave the MSB bits empty.
|
||||
///
|
||||
/// For example: A full-code sample in 16 bit (0xFFFF) will be written
|
||||
/// back to the buffer as 0x0000FFFF.
|
||||
///
|
||||
///
|
||||
/// ### Panics
|
||||
///
|
||||
/// The `buffer` must have a number of elements equal to the number of
|
||||
/// channels and this method will panic if this is not the case.
|
||||
pub fn read_integer_frame(&mut self, buffer:&mut [i32]) -> Result<u64,Error> {
|
||||
assert!(buffer.len() as u16 == self.format.channel_count,
|
||||
"read_integer_frame was called with a mis-sized buffer, expected {}, was {}",
|
||||
self.format.channel_count, buffer.len());
|
||||
|
||||
let framed_bits_per_sample = self.format.block_alignment * 8 / self.format.channel_count;
|
||||
|
||||
let tell = self.inner.seek(Current(0))?;
|
||||
|
||||
if (tell - self.start) < self.length {
|
||||
for n in 0..(self.format.channel_count as usize) {
|
||||
buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
||||
(0..=8,8) => self.inner.read_u8()? as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||
(9..=16,16) => self.inner.read_i16::<LittleEndian>()? as i32,
|
||||
(10..=24,24) => self.inner.read_i24::<LittleEndian>()?,
|
||||
(25..=32,32) => self.inner.read_i32::<LittleEndian>()?,
|
||||
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||
b, self.format.channel_count, self.format.block_alignment)
|
||||
}
|
||||
}
|
||||
Ok( 1 )
|
||||
} else {
|
||||
Ok( 0 )
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_float_frame(&mut self, buffer:&mut [f32]) -> Result<u64, Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Wave, Broadcast-WAV and RF64/BW64 parser/reader.
|
||||
///
|
||||
/// ```
|
||||
@@ -28,7 +137,7 @@ use std::io::{Read, Seek};
|
||||
/// assert_eq!(format.channel_count, 1);
|
||||
///
|
||||
/// let mut frame_reader = r.audio_frame_reader().unwrap();
|
||||
/// let mut buffer = format.create_frame_buffer();
|
||||
/// let mut buffer = format.create_frame_buffer(1);
|
||||
///
|
||||
/// let read = frame_reader.read_integer_frame(&mut buffer).unwrap();
|
||||
///
|
||||
@@ -68,13 +177,22 @@ pub struct WaveReader<R: Read + Seek> {
|
||||
pub inner: R,
|
||||
}
|
||||
|
||||
impl WaveReader<BufReader<File>> {
|
||||
|
||||
pub fn open(path: &str) -> Result<Self, ParserError> {
|
||||
let f = File::open(path)?;
|
||||
let inner = BufReader::new(f);
|
||||
Ok( Self::new(inner)? )
|
||||
}
|
||||
}
|
||||
|
||||
impl WaveReader<File> {
|
||||
|
||||
/// Open a file for reading.
|
||||
/// Open a file for reading with unbuffered IO.
|
||||
///
|
||||
/// A convenience that opens `path` and calls `Self::new()`
|
||||
|
||||
pub fn open(path: &str) -> Result<Self, ParserError> {
|
||||
pub fn open_unbuffered(path: &str) -> Result<Self, ParserError> {
|
||||
let inner = File::open(path)?;
|
||||
return Ok( Self::new(inner)? )
|
||||
}
|
||||
@@ -206,19 +324,16 @@ impl<R: Read + Seek> WaveReader<R> {
|
||||
/// let cue_points = f.cue_points().unwrap();
|
||||
///
|
||||
/// assert_eq!(cue_points.len(), 3);
|
||||
/// assert_eq!(cue_points[0].ident, 1);
|
||||
/// assert_eq!(cue_points[0].frame, 12532);
|
||||
/// assert_eq!(cue_points[0].length, None);
|
||||
/// assert_eq!(cue_points[0].label, Some(String::from("Marker 1")));
|
||||
/// assert_eq!(cue_points[0].note, Some(String::from("Marker 1 Comment")));
|
||||
///
|
||||
/// assert_eq!(cue_points[1].ident, 2);
|
||||
/// assert_eq!(cue_points[1].frame, 20997);
|
||||
/// assert_eq!(cue_points[1].length, None);
|
||||
/// assert_eq!(cue_points[1].label, Some(String::from("Marker 2")));
|
||||
/// assert_eq!(cue_points[1].note, Some(String::from("Marker 2 Comment")));
|
||||
///
|
||||
/// assert_eq!(cue_points[2].ident, 3);
|
||||
/// assert_eq!(cue_points[2].frame, 26711);
|
||||
/// assert_eq!(cue_points[2].length, Some(6465));
|
||||
/// assert_eq!(cue_points[2].label, Some(String::from("Timed Region")));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::fs::File;
|
||||
use std::io::{Write,Seek,SeekFrom,Cursor};
|
||||
use std::io::{Write,Seek,SeekFrom,Cursor,BufWriter};
|
||||
|
||||
use super::Error;
|
||||
use super::fourcc::{FourCC, WriteFourCC, RIFF_SIG, RF64_SIG, DS64_SIG,
|
||||
@@ -26,7 +26,7 @@ impl<W> AudioFrameWriter<W> where W: Write + Seek {
|
||||
AudioFrameWriter { inner }
|
||||
}
|
||||
|
||||
fn write_integer_frames_to_buffer(&self, from_frames :&[i32], to_buffer : &mut Vec<u8>) -> () {
|
||||
fn write_integer_frames_to_buffer(&self, from_frames :&[i32], to_buffer : &mut [u8]) -> () {
|
||||
assert!(from_frames.len() % self.inner.inner.format.channel_count as usize == 0,
|
||||
"frames buffer does not contain a number of samples % channel_count == 0");
|
||||
self.inner.inner.format.pack_frames(&from_frames, to_buffer);
|
||||
@@ -40,7 +40,8 @@ impl<W> AudioFrameWriter<W> where W: Write + Seek {
|
||||
/// This function will panic if `buffer.len()` modulo the Wave file's channel count
|
||||
/// is not zero.
|
||||
pub fn write_integer_frames(&mut self, buffer: &[i32]) -> Result<u64,Error> {
|
||||
let mut write_buffer = vec![0u8; 0];
|
||||
let mut write_buffer = self.inner.inner.format
|
||||
.create_raw_buffer(buffer.len() / self.inner.inner.format.channel_count as usize);
|
||||
|
||||
self.write_integer_frames_to_buffer(&buffer, &mut write_buffer);
|
||||
|
||||
@@ -209,10 +210,19 @@ pub struct WaveWriter<W> where W: Write + Seek {
|
||||
|
||||
const DS64_RESERVATION_LENGTH : u32 = 96;
|
||||
|
||||
impl WaveWriter<File> {
|
||||
impl WaveWriter<BufWriter<File>> {
|
||||
|
||||
/// Create a new Wave file at `path`.
|
||||
pub fn create(path : &str, format : WaveFmt) -> Result<Self, Error> {
|
||||
let f = File::create(path)?;
|
||||
let b = BufWriter::new(f);
|
||||
Ok( Self::new(b, format)? )
|
||||
}
|
||||
}
|
||||
|
||||
impl WaveWriter<File> {
|
||||
/// Creare a new Wave file with unbuffered IO at `path`
|
||||
pub fn create_unbuffered(path : &str, format : WaveFmt) -> Result<Self, Error> {
|
||||
let f = File::create(path)?;
|
||||
Ok( Self::new(f, format)? )
|
||||
}
|
||||
@@ -265,6 +275,7 @@ impl<W> WaveWriter<W> where W: Write + Seek {
|
||||
/// the file; if you have already written and closed the audio data the
|
||||
/// bext chunk will be positioned after it.
|
||||
pub fn write_broadcast_metadata(&mut self, bext: &Bext) -> Result<(),Error> {
|
||||
//FIXME Implement re-writing
|
||||
let mut c = Cursor::new(vec![0u8; 0]);
|
||||
c.write_bext(&bext)?;
|
||||
let buf = c.into_inner();
|
||||
@@ -274,11 +285,13 @@ impl<W> WaveWriter<W> where W: Write + Seek {
|
||||
|
||||
/// Write iXML metadata
|
||||
pub fn write_ixml(&mut self, ixml: &[u8]) -> Result<(),Error> {
|
||||
//FIXME Implement re-writing
|
||||
self.write_chunk(IXML_SIG, &ixml)
|
||||
}
|
||||
|
||||
/// Write axml/ADM metadata
|
||||
pub fn write_axml(&mut self, axml: &[u8]) -> Result<(), Error> {
|
||||
//FIXME Implement re-writing
|
||||
self.write_chunk(AXML_SIG, &axml)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ fn assert_match_stream<T>(stream_key: &str,
|
||||
.for_each(|value| {
|
||||
let filen : &str = value["format"]["filename"].as_str().unwrap();
|
||||
let json_value : &Value = &value["streams"][0][stream_key];
|
||||
let mut wavfile = WaveReader::open(filen).unwrap();
|
||||
let mut wavfile = WaveReader::open_unbuffered(filen).unwrap();
|
||||
let wavfile_value: T = other(&mut wavfile);
|
||||
println!("asserting {} for {}",stream_key, filen);
|
||||
assert_eq!(Into::<Value>::into(wavfile_value), *json_value);
|
||||
|
||||
@@ -82,7 +82,7 @@ fn test_read() {
|
||||
let path = "tests/media/audacity_16bit.wav";
|
||||
|
||||
let mut w = WaveReader::open(path).expect("Failure opening test file");
|
||||
let mut buffer = w.format().unwrap().create_frame_buffer();
|
||||
let mut buffer = w.format().unwrap().create_frame_buffer(1);
|
||||
|
||||
let mut reader = w.audio_frame_reader().unwrap();
|
||||
|
||||
@@ -101,7 +101,7 @@ fn test_locate_multichannel_read() {
|
||||
let path = "tests/media/ff_pink.wav";
|
||||
|
||||
let mut w = WaveReader::open(path).expect("Failure opening test file");
|
||||
let mut buffer = w.format().unwrap().create_frame_buffer();
|
||||
let mut buffer = w.format().unwrap().create_frame_buffer(1);
|
||||
|
||||
let mut reader = w.audio_frame_reader().unwrap();
|
||||
|
||||
@@ -162,10 +162,9 @@ fn test_channels_stereo_no_fmt_extended() {
|
||||
#[test]
|
||||
fn test_frame_reader_consumes_reader() {
|
||||
// Issue #6
|
||||
use bwavfile::WaveFmt;
|
||||
use bwavfile::AudioFrameReader;
|
||||
use bwavfile::{WaveFmt, AudioFrameReader};
|
||||
use std::fs::File;
|
||||
fn from_wav_filename(wav_filename: &str) -> Result<(WaveFmt, AudioFrameReader<File>), ()> {
|
||||
fn from_wav_filename(wav_filename: &str) -> Result<(WaveFmt, AudioFrameReader<std::io::BufReader<File>>), ()> {
|
||||
if let Ok(mut r) = WaveReader::open(&wav_filename) {
|
||||
let format = r.format().unwrap();
|
||||
let frame_reader = r.audio_frame_reader().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user