mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2026-01-01 01:10:43 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69fd5f310c | ||
|
|
a8bb5e8c8e | ||
|
|
468ed12304 | ||
|
|
a015d7cf8a | ||
|
|
e89e87045c | ||
|
|
ecc1db703d | ||
|
|
4cd28c9efe | ||
|
|
663b9fad43 | ||
|
|
9fe741d913 | ||
|
|
2ecae51e8d | ||
|
|
56dc4d1048 | ||
|
|
1af4c675c7 | ||
|
|
a625b485d9 | ||
|
|
d17c6badfa | ||
|
|
bc6be79715 | ||
|
|
763e9a10a3 | ||
|
|
319845ae49 | ||
|
|
6375567af1 | ||
|
|
1a169da48f | ||
|
|
50b7b7b640 | ||
|
|
94eb36bbb5 | ||
|
|
80be74c8fb | ||
|
|
75fc40d638 | ||
|
|
2780bfb31b |
38
Cargo.lock
generated
38
Cargo.lock
generated
@@ -22,13 +22,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bwavfile"
|
name = "bwavfile"
|
||||||
version = "0.9.3"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"clap",
|
"clap",
|
||||||
@@ -39,9 +39,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.3.4"
|
version = "1.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
@@ -124,24 +124,24 @@ checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.17"
|
version = "0.1.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
|
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.7"
|
version = "0.4.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.81"
|
version = "0.2.103"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
@@ -151,15 +151,15 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.118"
|
version = "1.0.130"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.61"
|
version = "1.0.68"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a"
|
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
@@ -183,15 +183,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "0.8.1"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
|
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bwavfile"
|
name = "bwavfile"
|
||||||
version = "0.9.3"
|
version = "1.1.0"
|
||||||
authors = ["Jamie Hardt <jamiehardt@me.com>"]
|
authors = ["Jamie Hardt <jamiehardt@me.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
87
README.md
87
README.md
@@ -4,72 +4,45 @@
|
|||||||
[](https://github.com/iluvcapra/bwavfile/actions?query=workflow%3ARust)
|
[](https://github.com/iluvcapra/bwavfile/actions?query=workflow%3ARust)
|
||||||
|
|
||||||
# bwavfile
|
# 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|
|
`WaveReader` and `WaveWriter` support:
|
||||||
|---------------------------------------|:---:|:-----:|
|
* A unified interface for standard RIFF and RF64/BW64 64-bit Wave files.
|
||||||
| Standard .wav files | ☑️ | ☑️ |
|
* When using `WaveWriter`, wave files are transparently upgraded from RIFF
|
||||||
| Transparent promotion to RF64/BW64 | ☑️ | ☑️ |
|
to RF64 when required.
|
||||||
| Unified interface for regular and extended Wave format | ☑️ | ☑️ |
|
* Unpacked reading and writing of Integer PCM and IEEE float audio data
|
||||||
| Channel/speaker map metadata | ☑️ | ☑️ |
|
formats.
|
||||||
| Ambisonic B-format metadata | ☑️ | ☑️ |
|
* A unified interface for standard `WaveFormat` and extended `WaveFormatEx`
|
||||||
| EBU Broadcast-WAVE metadata | ☑️ | ☑️ |
|
wave data format specification.
|
||||||
| Basic iXML/ADM metadata | ☑️ | ☑️ |
|
* Multichannel, surround, and ambisonic audio data description including
|
||||||
| Enhanced iXML metadata support | | |
|
surround channel maps, ADM `AudioTrackFormat`, `AudioChannelFormatRef` and
|
||||||
| ADM `chna` channel metadata | | |
|
`AudioPackRef` data structures.
|
||||||
| Broadcast-WAVE Level overview `levl` metadata | | |
|
* Broadcast-Wave metdata extension, including long description, originator
|
||||||
| Cue list metadata | ☑️ | |
|
information, SMPTE UMID and coding history.
|
||||||
| Sampler and instrument metadata | | |
|
* Reading and writing of embedded iXML and axml/ADM metadata.
|
||||||
| Enhanced Wave file form validation | ☑️ | |
|
* Reading and writing of timed cues and and timed cue regions.
|
||||||
|
|
||||||
|
### Feature Roadmap
|
||||||
|
|
||||||
|
Some features that may be included in the future include:
|
||||||
|
* Broadcast-Wave `levl` waveform overview data reading and writing.
|
||||||
|
* Sampler and Instrument metadata.
|
||||||
|
* Performance improvements.
|
||||||
|
|
||||||
|
|
||||||
## Use Examples
|
## Use Examples
|
||||||
|
|
||||||
### Examples Directory
|
|
||||||
|
|
||||||
Check out the [examples](examples) directory for some practical use cases:
|
|
||||||
|
|
||||||
* [blits](examples/blits.rs) shows how to use `WaveWriter` to create a new
|
* [blits](examples/blits.rs) shows how to use `WaveWriter` to create a new
|
||||||
file with BLITS alignment tones.
|
file with BLITS alignment tones.
|
||||||
|
* [wave-inter](examples/wave-inter.rs) uses `WaveReader` and `WaveWriter` to
|
||||||
### Reading Audio Frames From a File
|
interleave several input Wave files into a single polyphonic Wave file.
|
||||||
|
* [wave-deinter](examples/wave-deinter.rs) uses `WaveReader` and `WaveWriter`
|
||||||
```rust
|
to de-interleave an input Wave file into several monoarual Wave files.
|
||||||
|
|
||||||
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);
|
|
||||||
```
|
|
||||||
|
|
||||||
## Note on Testing
|
## Note on Testing
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use std::io;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
extern crate bwavfile;
|
extern crate bwavfile;
|
||||||
use bwavfile::{Error,WaveReader, WaveWriter, ChannelDescriptor, ChannelMask, WaveFmt, AudioFrameWriter};
|
use bwavfile::{Error,WaveReader, WaveWriter, ChannelDescriptor, ChannelMask, WaveFmt};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
@@ -70,7 +70,7 @@ fn process_file(infile: &str, delim : &str, numeric_channel_names : bool) -> Res
|
|||||||
let output_file = WaveWriter::create(&outfile_name, ouptut_format).expect("Failed to create new file");
|
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 output_wave_writer = output_file.audio_frame_writer()?;
|
||||||
let mut buffer = input_format.create_frame_buffer();
|
let mut buffer = input_format.create_frame_buffer(1);
|
||||||
|
|
||||||
while input_wave_reader.read_integer_frame(&mut buffer)? > 0 {
|
while input_wave_reader.read_integer_frame(&mut buffer)? > 0 {
|
||||||
output_wave_writer.write_integer_frames(&buffer[n..=n])?;
|
output_wave_writer.write_integer_frames(&buffer[n..=n])?;
|
||||||
|
|||||||
18
src/cue.rs
18
src/cue.rs
@@ -281,7 +281,16 @@ pub struct Cue {
|
|||||||
pub label : Option<String>,
|
pub label : Option<String>,
|
||||||
|
|
||||||
/// The text "note"/comment of this marker if provided
|
/// The text "note"/comment of this marker if provided
|
||||||
pub note : Option<String>
|
pub note : Option<String>,
|
||||||
|
|
||||||
|
/// The offser of this marker
|
||||||
|
///
|
||||||
|
/// **Note:** Applications use the `frame` and `offset` fields
|
||||||
|
/// in different ways. iZotope RX Audio Editor writes the
|
||||||
|
/// marker position to *both* fields, while a Sound Devices
|
||||||
|
/// recorder writes the marker position to *only* the `offset`
|
||||||
|
/// field.
|
||||||
|
pub offset : u32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -306,7 +315,7 @@ impl Cue {
|
|||||||
chunk_id: DATA_SIG,
|
chunk_id: DATA_SIG,
|
||||||
chunk_start: 0,
|
chunk_start: 0,
|
||||||
block_start: 0,
|
block_start: 0,
|
||||||
frame_offset: cue.frame
|
frame_offset: cue.offset
|
||||||
};
|
};
|
||||||
|
|
||||||
let raw_label = cue.label.as_ref().map(|val| {
|
let raw_label = cue.label.as_ref().map(|val| {
|
||||||
@@ -380,10 +389,11 @@ impl Cue {
|
|||||||
//.filter_map(|x| str::from_utf8(&x.text).ok())
|
//.filter_map(|x| str::from_utf8(&x.text).ok())
|
||||||
.map(|s| convert_to_cue_string(&s.text))
|
.map(|s| convert_to_cue_string(&s.text))
|
||||||
.next()
|
.next()
|
||||||
}
|
},
|
||||||
|
offset: i.frame_offset
|
||||||
}
|
}
|
||||||
}).collect()
|
}).collect()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::io;
|
use std::{fmt::{Debug,Display}, io};
|
||||||
|
use std::error::Error as StdError;
|
||||||
use super::fourcc::FourCC;
|
use super::fourcc::FourCC;
|
||||||
|
|
||||||
use uuid;
|
use uuid;
|
||||||
@@ -43,6 +44,14 @@ pub enum Error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StdError for Error {}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
Debug::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl From<io::Error> for Error {
|
impl From<io::Error> for Error {
|
||||||
fn from(error: io::Error) -> Error {
|
fn from(error: io::Error) -> Error {
|
||||||
|
|||||||
92
src/fmt.rs
92
src/fmt.rs
@@ -3,7 +3,7 @@ use super::common_format::{CommonFormat, UUID_PCM,UUID_BFORMAT_PCM};
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use byteorder::LittleEndian;
|
use byteorder::LittleEndian;
|
||||||
use byteorder::WriteBytesExt;
|
use byteorder::{WriteBytesExt, ReadBytesExt};
|
||||||
|
|
||||||
// Need more test cases for ADMAudioID
|
// Need more test cases for ADMAudioID
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -18,6 +18,7 @@ use byteorder::WriteBytesExt;
|
|||||||
/// `AudioProgramme`.
|
/// `AudioProgramme`.
|
||||||
///
|
///
|
||||||
/// See BS.2088-1 § 8, also BS.2094, also blahblahblah...
|
/// See BS.2088-1 § 8, also BS.2094, also blahblahblah...
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ADMAudioID {
|
pub struct ADMAudioID {
|
||||||
pub track_uid: [char; 12],
|
pub track_uid: [char; 12],
|
||||||
pub channel_format_ref: [char; 14],
|
pub channel_format_ref: [char; 14],
|
||||||
@@ -28,6 +29,7 @@ pub struct ADMAudioID {
|
|||||||
///
|
///
|
||||||
/// This information is correlated from the Wave format ChannelMap field and
|
/// This information is correlated from the Wave format ChannelMap field and
|
||||||
/// the `chna` chunk, if present.
|
/// the `chna` chunk, if present.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ChannelDescriptor {
|
pub struct ChannelDescriptor {
|
||||||
/// Index, the offset of this channel's samples in one frame.
|
/// Index, the offset of this channel's samples in one frame.
|
||||||
pub index: u16,
|
pub index: u16,
|
||||||
@@ -290,22 +292,23 @@ impl WaveFmt {
|
|||||||
CommonFormat::make( self.tag, self.extended_format.map(|ext| ext.type_guid))
|
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
|
/// This is a conveneince method that creates a `Vec<i32>` with
|
||||||
/// as many elements as there are channels in the underlying stream.
|
/// as many elements as there are channels in the underlying stream.
|
||||||
pub fn create_frame_buffer(&self) -> Vec<i32> {
|
pub fn create_frame_buffer(&self, length : usize) -> Vec<i32> {
|
||||||
vec![0i32; self.channel_count as usize]
|
vec![0i32; self.channel_count as usize * length]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate the size of a byte buffer needed to hold audio data of this
|
/// Create a raw byte buffer to hold `length` blocks from a reader or
|
||||||
/// format for a given number of frames
|
/// writer
|
||||||
pub fn buffer_length(&self, frame_count: u64) -> usize {
|
pub fn create_raw_buffer(&self, length : usize) -> Vec<u8> {
|
||||||
(self.block_alignment as u64 * frame_count) as usize
|
vec![0u8; self.block_alignment as usize * length]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write frames into a byte vector
|
/// Write frames into a byte vector
|
||||||
pub fn pack_frames(&self, from_frames: &[i32], into_bytes: &mut Vec<u8>) -> () {
|
pub fn pack_frames(&self, from_frames: &[i32], into_bytes: &mut [u8]) -> () {
|
||||||
let mut write_cursor = Cursor::new(into_bytes);
|
let mut write_cursor = Cursor::new(into_bytes);
|
||||||
|
|
||||||
assert!(from_frames.len() % self.channel_count as usize == 0,
|
assert!(from_frames.len() % self.channel_count as usize == 0,
|
||||||
@@ -325,18 +328,19 @@ impl WaveFmt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Read bytes into frames
|
/// Read bytes into frames
|
||||||
// pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut Vec<i32>) -> () {
|
pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32]) -> () {
|
||||||
// for n in 0..(from_bytes.len()) {
|
let mut rdr = Cursor::new(from_bytes);
|
||||||
// buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
for n in 0..(into_frames.len()) {
|
||||||
// (0..=8,8) => self.inner.read_u8()? as i32 - 0x80_i32, // EBU 3285 §A2.2
|
into_frames[n] = match (self.valid_bits_per_sample(), self.bits_per_sample) {
|
||||||
// (9..=16,16) => self.inner.read_i16::<LittleEndian>()? as i32,
|
(0..=8,8) => rdr.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||||
// (10..=24,24) => self.inner.read_i24::<LittleEndian>()?,
|
(9..=16,16) => rdr.read_i16::<LittleEndian>().unwrap() as i32,
|
||||||
// (25..=32,32) => self.inner.read_i32::<LittleEndian>()?,
|
(10..=24,24) => rdr.read_i24::<LittleEndian>().unwrap(),
|
||||||
// (b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
(25..=32,32) => rdr.read_i32::<LittleEndian>().unwrap(),
|
||||||
// b, self.format.channel_count, self.format.block_alignment)
|
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||||
// }
|
b, self.channel_count, self.block_alignment)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Channel descriptors for each channel.
|
/// Channel descriptors for each channel.
|
||||||
@@ -379,3 +383,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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,16 +31,11 @@ Apps we test against:
|
|||||||
- iZotope RX Audio Editor
|
- iZotope RX Audio Editor
|
||||||
- FFMpeg
|
- FFMpeg
|
||||||
- Audacity
|
- Audacity
|
||||||
|
- Sound Devices field recorders: 702T, MixPre-10 II
|
||||||
|
|
||||||
[github]: https://github.com/iluvcapra/bwavfile
|
[github]: https://github.com/iluvcapra/bwavfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// #![feature(external_doc)]
|
|
||||||
|
|
||||||
// #[doc(include="../README.md")]
|
|
||||||
// #[cfg(doctest)]
|
|
||||||
// pub struct ReadmeDoctests;
|
|
||||||
|
|
||||||
extern crate encoding;
|
extern crate encoding;
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
|
|||||||
3
src/wavebuffer.rs
Normal file
3
src/wavebuffer.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub struct WaveBuffer {
|
||||||
|
pub format : WaveFmt
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
|||||||
"Unable to read audio frames from packed formats: block alignment is {}, should be {}",
|
"Unable to read audio frames from packed formats: block alignment is {}, should be {}",
|
||||||
format.block_alignment, (format.bits_per_sample / 8 ) * format.channel_count);
|
format.block_alignment, (format.bits_per_sample / 8 ) * format.channel_count);
|
||||||
|
|
||||||
assert!(format.common_format() == CommonFormat::IntegerPCM ,
|
assert!(format.common_format() == CommonFormat::IntegerPCM || format.common_format() == CommonFormat::IeeeFloatPCM,
|
||||||
"Unsupported format tag {:?}", format.tag);
|
"Unsupported format tag {:?}", format.tag);
|
||||||
|
|
||||||
inner.seek(Start(start))?;
|
inner.seek(Start(start))?;
|
||||||
@@ -120,6 +120,29 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
|||||||
Ok( 0 )
|
Ok( 0 )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_float_frame(&mut self, buffer: &mut [f32]) -> Result<u64, Error> {
|
||||||
|
assert!(buffer.len() as u16 == self.format.channel_count,
|
||||||
|
"read_float_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) {
|
||||||
|
(25..=32,32) => self.inner.read_f32::<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 )
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wave, Broadcast-WAV and RF64/BW64 parser/reader.
|
/// Wave, Broadcast-WAV and RF64/BW64 parser/reader.
|
||||||
@@ -133,7 +156,7 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
|||||||
/// assert_eq!(format.channel_count, 1);
|
/// assert_eq!(format.channel_count, 1);
|
||||||
///
|
///
|
||||||
/// let mut frame_reader = r.audio_frame_reader().unwrap();
|
/// 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();
|
/// let read = frame_reader.read_integer_frame(&mut buffer).unwrap();
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ impl<W> AudioFrameWriter<W> where W: Write + Seek {
|
|||||||
AudioFrameWriter { inner }
|
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,
|
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");
|
"frames buffer does not contain a number of samples % channel_count == 0");
|
||||||
self.inner.inner.format.pack_frames(&from_frames, to_buffer);
|
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
|
/// This function will panic if `buffer.len()` modulo the Wave file's channel count
|
||||||
/// is not zero.
|
/// is not zero.
|
||||||
pub fn write_integer_frames(&mut self, buffer: &[i32]) -> Result<u64,Error> {
|
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);
|
self.write_integer_frames_to_buffer(&buffer, &mut write_buffer);
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fn test_read() {
|
|||||||
let path = "tests/media/audacity_16bit.wav";
|
let path = "tests/media/audacity_16bit.wav";
|
||||||
|
|
||||||
let mut w = WaveReader::open(path).expect("Failure opening test file");
|
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();
|
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 path = "tests/media/ff_pink.wav";
|
||||||
|
|
||||||
let mut w = WaveReader::open(path).expect("Failure opening test file");
|
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();
|
let mut reader = w.audio_frame_reader().unwrap();
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ fn test_channels_stereo_no_fmt_extended() {
|
|||||||
assert_eq!(channels[1].speaker,ChannelMask::FrontRight);
|
assert_eq!(channels[1].speaker,ChannelMask::FrontRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
//See issue 6 and 7
|
///See issue 6 and 7
|
||||||
#[test]
|
#[test]
|
||||||
fn test_frame_reader_consumes_reader() {
|
fn test_frame_reader_consumes_reader() {
|
||||||
// Issue #6
|
// Issue #6
|
||||||
@@ -175,4 +175,48 @@ fn test_frame_reader_consumes_reader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _result = from_wav_filename("tests/media/pt_24bit_stereo.wav").unwrap();
|
let _result = from_wav_filename("tests/media/pt_24bit_stereo.wav").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
///See to PR#10
|
||||||
|
#[test]
|
||||||
|
fn test_cue_read_sounddevices() {
|
||||||
|
let mut f = WaveReader::open("tests/media/sounddevices_6_cue_points.wav").unwrap();
|
||||||
|
let cue_points = f.cue_points().unwrap();
|
||||||
|
assert_eq!(cue_points.len(), 6);
|
||||||
|
|
||||||
|
assert_eq!(cue_points[0].frame, 0);
|
||||||
|
assert_eq!(cue_points[0].length, None);
|
||||||
|
assert_eq!(cue_points[0].label, None);
|
||||||
|
assert_eq!(cue_points[0].note, None);
|
||||||
|
assert_eq!(cue_points[0].offset, 90112);
|
||||||
|
|
||||||
|
assert_eq!(cue_points[1].frame, 0);
|
||||||
|
assert_eq!(cue_points[1].length, None);
|
||||||
|
assert_eq!(cue_points[1].label, None);
|
||||||
|
assert_eq!(cue_points[1].note, None);
|
||||||
|
assert_eq!(cue_points[1].offset, 176128);
|
||||||
|
|
||||||
|
assert_eq!(cue_points[2].frame, 0);
|
||||||
|
assert_eq!(cue_points[2].length, None);
|
||||||
|
assert_eq!(cue_points[2].label, None);
|
||||||
|
assert_eq!(cue_points[2].note, None);
|
||||||
|
assert_eq!(cue_points[2].offset, 237568);
|
||||||
|
|
||||||
|
assert_eq!(cue_points[3].frame, 0);
|
||||||
|
assert_eq!(cue_points[3].length, None);
|
||||||
|
assert_eq!(cue_points[3].label, None);
|
||||||
|
assert_eq!(cue_points[3].note, None);
|
||||||
|
assert_eq!(cue_points[3].offset, 294912);
|
||||||
|
|
||||||
|
assert_eq!(cue_points[4].frame, 0);
|
||||||
|
assert_eq!(cue_points[4].length, None);
|
||||||
|
assert_eq!(cue_points[4].label, None);
|
||||||
|
assert_eq!(cue_points[4].note, None);
|
||||||
|
assert_eq!(cue_points[4].offset, 380928);
|
||||||
|
|
||||||
|
assert_eq!(cue_points[5].frame, 0);
|
||||||
|
assert_eq!(cue_points[5].length, None);
|
||||||
|
assert_eq!(cue_points[5].label, None);
|
||||||
|
assert_eq!(cue_points[5].note, None);
|
||||||
|
assert_eq!(cue_points[5].offset, 385024);
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user