[][src]Struct bwavfile::WaveReader

pub struct WaveReader<R: Read + Seek> {
    pub inner: R,
}

Wave, Broadcast-WAV and RF64/BW64 parser/reader.

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 frame_reader = r.audio_frame_reader().unwrap();
let mut buffer = frame_reader.create_frame_buffer();
 
let read = frame_reader.read_integer_frame(&mut buffer).unwrap();
 
assert_eq!(buffer, [0i32]);
assert_eq!(read, 1);
 

Fields

inner: R

Implementations

impl WaveReader<File>[src]

pub fn open(path: &str) -> Result<Self, ParserError>[src]

Open a file for reading.

A convenience that opens path and calls Self::new()

impl<R: Read + Seek> WaveReader<R>[src]

pub fn new(inner: R) -> Result<Self, ParserError>[src]

Wrap a Read struct in a new WaveReader.

This is the primary entry point into the WaveReader interface. The stream passed as inner must be at the beginning of the header of the WAVE data. For a .wav file, this means it must be at the start of the file.

This function does a minimal validation on the provided stream and 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 impoossible.

use std::fs::File;
use std::io::{Error,ErrorKind};
use bwavfile::{WaveReader, Error as WavError};
 
let f = File::open("tests/media/error.wav").unwrap();
 
let reader = WaveReader::new(f);
 
match reader {
     Ok(_) => panic!("error.wav should not be openable"),
     Err( WavError::IOError( e ) ) => {
         assert_eq!(e.kind(), ErrorKind::UnexpectedEof)
     }
     Err(e) => panic!("Unexpected error was returned {:?}", e)
}
 

pub fn into_inner(self) -> R[src]

Unwrap the inner reader.

pub fn audio_frame_reader(
    &mut self
) -> Result<AudioFrameReader<RawChunkReader<'_, R>>, ParserError>
[src]

Create an AudioFrameReader for reading each audio frame.

pub fn frame_length(&mut self) -> Result<u64, ParserError>[src]

The count of audio frames in the file.

pub fn format(&mut self) -> Result<WaveFmt, ParserError>[src]

Sample and frame format of this wave file.

pub fn broadcast_extension(&mut self) -> Result<Bext, ParserError>[src]

The Broadcast-WAV metadata record for this file.

pub fn validate_readable(&mut self) -> Result<(), ParserError>[src]

Validate file is readable.

Ok(()) if the source meets the minimum standard of readability by a permissive client:

  • fmt chunk and data chunk are present
  • fmt chunk appears before data chunk

pub fn validate_minimal(&mut self) -> Result<(), ParserError>[src]

Validate minimal WAVE file.

Ok(()) if the source is validate_readable() AND

  • Contains only a fmt chunk and data chunk, with no other chunks present
  • is not an RF64/BW64

Some clients require a WAVE file to only contain format and data without any other metadata and this function is provided to validate this condition.

Examples

 
let mut w = WaveReader::open("tests/media/ff_minimal.wav").unwrap();
w.validate_minimal().expect("Minimal wav did not validate not minimal!");
 
let mut x = WaveReader::open("tests/media/pt_24bit_51.wav").unwrap();
x.validate_minimal().expect_err("Complex WAV validated minimal!");

pub fn validate_broadcast_wave(&mut self) -> Result<(), ParserError>[src]

Validate Broadcast-WAVE file format

Returns Ok(()) if validate_readable() and file contains a Broadcast-WAV metadata record (a bext chunk).

Examples

 
let mut w = WaveReader::open("tests/media/ff_bwav_stereo.wav").unwrap();
w.validate_broadcast_wave().expect("BWAVE file did not validate BWAVE");
 
let mut x = WaveReader::open("tests/media/pt_24bit.wav").unwrap();
x.validate_broadcast_wave().expect("BWAVE file did not validate BWAVE");
 
let mut y = WaveReader::open("tests/media/audacity_16bit.wav").unwrap();
y.validate_broadcast_wave().expect_err("Plain WAV file DID validate BWAVE");

pub fn validate_data_chunk_alignment(&mut self) -> Result<(), ParserError>[src]

Verify data is aligned to a block boundary.

Returns Ok(()) if validate_readable() and the start of the data chunk's content begins at 0x4000.

pub fn validate_prepared_for_append(&mut self) -> Result<(), ParserError>[src]

Verify audio data can be appended immediately to this file.

Returns Ok(()) if:

  • validate_readable()
  • there is a JUNK or FLLR immediately at the beginning of the chunk list adequately large enough to be overwritten by a ds64 (92 bytes)
  • data is the final chunk

Trait Implementations

impl<R: Debug + Read + Seek> Debug for WaveReader<R>[src]

Auto Trait Implementations

impl<R> RefUnwindSafe for WaveReader<R> where
    R: RefUnwindSafe

impl<R> Send for WaveReader<R> where
    R: Send

impl<R> Sync for WaveReader<R> where
    R: Sync

impl<R> Unpin for WaveReader<R> where
    R: Unpin

impl<R> UnwindSafe for WaveReader<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.