BrstmInformation

Struct BrstmInformation 

Source
pub struct BrstmInformation {
    pub info: Head1,
    pub tracks: Vec<TrackDescription>,
    pub channels: Vec<AdpcmChannelInformation>,
    /* private fields */
}

Fields§

§info: Head1§tracks: Vec<TrackDescription>§channels: Vec<AdpcmChannelInformation>

Implementations§

Source§

impl BrstmInformation

Source

pub fn from_reader<RS: Read + Seek>(f: &mut RS) -> BinResult<Self>

Examples found in repository?
examples/brstm-check.rs (line 9)
5pub fn try_main() -> binrw::BinResult<()> {
6    let mut files = args().skip(1);
7    let in_filename = files.next().expect("no in filename");
8    let mut f = File::open(&in_filename)?;
9    let src = BrstmInformation::from_reader(&mut f)?;
10    drop(f);
11    if !src.check_tracks_valid() {
12        println!("{in_filename} has invalid tracks!!!");
13    }
14    Ok(())
15}
More examples
Hide additional examples
examples/brstm-fix.rs (line 10)
5pub fn try_main() -> binrw::BinResult<()> {
6    let mut files = args().skip(1);
7    let in_filename = files.next().expect("no in filename");
8    let out_filename = files.next().expect("no out filename");
9    let mut f = File::open(in_filename)?;
10    let mut src = BrstmInformation::from_reader(&mut f)?.into_with_data(&mut f)?;
11    drop(f);
12    src.info.fix_tracks();
13    let mut outf = File::create(out_filename)?;
14    src.write_brstm(&mut outf)?;
15    Ok(())
16}
examples/rw-check.rs (line 14)
8pub fn main() {
9    for src in std::env::args().skip(1) {
10        let orig = fs::read(&src).unwrap();
11        let mut dest = Vec::with_capacity(orig.len());
12        println!("{src}");
13        let mut cursor = Cursor::new(&orig);
14        let parsed = BrstmInformation::from_reader(&mut cursor).unwrap();
15        let data_parsed = parsed.into_with_data(&mut cursor).unwrap();
16        data_parsed
17            .write_brstm(&mut Cursor::new(&mut dest))
18            .unwrap();
19        if orig != dest {
20            println!("missmatch: {src}");
21        }
22    }
23}
examples/all-sizes.rs (line 8)
5pub fn main() {
6    let mut name_to_duration = Vec::new();
7    for filename in args().skip(1) {
8        let read = BrstmInformation::from_reader(&mut File::open(&filename).unwrap()).unwrap();
9        let name = filename.split_terminator('/').last().unwrap();
10        // if read.info.loop_flag == 0 {
11        name_to_duration.push((
12            name.to_string(),
13            read.info.loop_flag,
14            read.info.total_samples,
15        ));
16        // }
17    }
18    name_to_duration.sort_unstable_by_key(|(_, _, count)| *count);
19    for (name, loop_flag, count) in name_to_duration.iter() {
20        println!("{name}:{loop_flag}:{count}");
21    }
22}
Source

pub fn write_brstm<WS: Write + Seek>( &self, ws: &mut WS, adpcm_bytes: &[u8], data_bytes: &[u8], ) -> BinResult<()>

Source

pub fn channel_count(&self) -> u8

Source

pub fn channels_per_track(&self) -> Option<u8>

returns None if it cannot be determined

Source

pub fn is_stereo(&self) -> bool

Source

pub fn is_mono(&self) -> bool

Source

pub fn check_tracks_valid(&self) -> bool

determine if track information is broken:

  • channels are referenced that don’t exist
  • channels exist but aren’t referenced
Examples found in repository?
examples/brstm-check.rs (line 11)
5pub fn try_main() -> binrw::BinResult<()> {
6    let mut files = args().skip(1);
7    let in_filename = files.next().expect("no in filename");
8    let mut f = File::open(&in_filename)?;
9    let src = BrstmInformation::from_reader(&mut f)?;
10    drop(f);
11    if !src.check_tracks_valid() {
12        println!("{in_filename} has invalid tracks!!!");
13    }
14    Ok(())
15}
Source

pub fn fix_tracks(&mut self) -> bool

fixes songs with tracks that point to invalid channels or if no tracks exist returns if tracks had to be fixed

Examples found in repository?
examples/brstm-fix.rs (line 12)
5pub fn try_main() -> binrw::BinResult<()> {
6    let mut files = args().skip(1);
7    let in_filename = files.next().expect("no in filename");
8    let out_filename = files.next().expect("no out filename");
9    let mut f = File::open(in_filename)?;
10    let mut src = BrstmInformation::from_reader(&mut f)?.into_with_data(&mut f)?;
11    drop(f);
12    src.info.fix_tracks();
13    let mut outf = File::create(out_filename)?;
14    src.write_brstm(&mut outf)?;
15    Ok(())
16}
Source

pub fn into_with_data<RS: Read + Seek>( self, f: &mut RS, ) -> Result<BrstmInfoWithData>

Examples found in repository?
examples/brstm-fix.rs (line 10)
5pub fn try_main() -> binrw::BinResult<()> {
6    let mut files = args().skip(1);
7    let in_filename = files.next().expect("no in filename");
8    let out_filename = files.next().expect("no out filename");
9    let mut f = File::open(in_filename)?;
10    let mut src = BrstmInformation::from_reader(&mut f)?.into_with_data(&mut f)?;
11    drop(f);
12    src.info.fix_tracks();
13    let mut outf = File::create(out_filename)?;
14    src.write_brstm(&mut outf)?;
15    Ok(())
16}
More examples
Hide additional examples
examples/rw-check.rs (line 15)
8pub fn main() {
9    for src in std::env::args().skip(1) {
10        let orig = fs::read(&src).unwrap();
11        let mut dest = Vec::with_capacity(orig.len());
12        println!("{src}");
13        let mut cursor = Cursor::new(&orig);
14        let parsed = BrstmInformation::from_reader(&mut cursor).unwrap();
15        let data_parsed = parsed.into_with_data(&mut cursor).unwrap();
16        data_parsed
17            .write_brstm(&mut Cursor::new(&mut dest))
18            .unwrap();
19        if orig != dest {
20            println!("missmatch: {src}");
21        }
22    }
23}

Trait Implementations§

Source§

impl Clone for BrstmInformation

Source§

fn clone(&self) -> BrstmInformation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BrstmInformation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.