From 84942a4186e219935f6b1a223019022e93a977d6 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Tue, 29 Dec 2020 14:26:34 -0800 Subject: [PATCH] Implented AXML/iXML writing functions --- src/fourcc.rs | 2 ++ src/wavereader.rs | 9 ++++----- src/wavewriter.rs | 13 ++++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/fourcc.rs b/src/fourcc.rs index 53486e9..6ea2c31 100644 --- a/src/fourcc.rs +++ b/src/fourcc.rs @@ -103,6 +103,8 @@ pub const FMT__SIG: FourCC = FourCC::make(b"fmt "); pub const BEXT_SIG: FourCC = FourCC::make(b"bext"); //pub const FACT_SIG: FourCC = FourCC::make(b"fact"); +pub const IXML_SIG: FourCC = FourCC::make(b"iXML"); +pub const AXML_SIG: FourCC = FourCC::make(b"axml"); pub const JUNK_SIG: FourCC = FourCC::make(b"JUNK"); pub const FLLR_SIG: FourCC = FourCC::make(b"FLLR"); diff --git a/src/wavereader.rs b/src/wavereader.rs index 33464e1..4849ca2 100644 --- a/src/wavereader.rs +++ b/src/wavereader.rs @@ -3,7 +3,8 @@ use std::io::SeekFrom; use std::fs::File; 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}; +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; @@ -250,8 +251,7 @@ impl WaveReader { /// If there are no iXML metadata present in the file, /// Ok(0) will be returned. pub fn read_ixml(&mut self, buffer: &mut Vec) -> Result { - let ixml_fourcc = FourCC::make(b"iXML"); - self.read_chunk(ixml_fourcc, 0, buffer) + self.read_chunk(IXML_SIG, 0, buffer) } /// Read AXML data. @@ -262,8 +262,7 @@ impl WaveReader { /// If there are no axml metadata present in the file, /// Ok(0) will be returned pub fn read_axml(&mut self, buffer: &mut Vec) -> Result { - let axml_fourcc = FourCC::make(b"axml"); - self.read_chunk(axml_fourcc, 0, buffer) + self.read_chunk(AXML_SIG, 0, buffer) } diff --git a/src/wavewriter.rs b/src/wavewriter.rs index 3247c34..8fed11f 100644 --- a/src/wavewriter.rs +++ b/src/wavewriter.rs @@ -3,7 +3,8 @@ use std::io::{Write,Seek,SeekFrom,Cursor}; use super::Error; use super::fourcc::{FourCC, WriteFourCC, RIFF_SIG, RF64_SIG, DS64_SIG, - WAVE_SIG, FMT__SIG, DATA_SIG, ELM1_SIG, JUNK_SIG, BEXT_SIG}; + WAVE_SIG, FMT__SIG, DATA_SIG, ELM1_SIG, JUNK_SIG, BEXT_SIG,AXML_SIG, + IXML_SIG}; use super::fmt::WaveFmt; //use super::common_format::CommonFormat; use super::chunks::WriteBWaveChunks; @@ -270,6 +271,16 @@ impl WaveWriter where W: Write + Seek { Ok(()) } + /// Write iXML metadata + pub fn write_ixml(&mut self, ixml: &[u8]) -> Result<(),Error> { + self.write_chunk(IXML_SIG, &ixml) + } + + /// Write axml/ADM metadata + pub fn write_axml(&mut self, axml: &[u8]) -> Result<(), Error> { + self.write_chunk(AXML_SIG, &axml) + } + /// Create an audio frame writer, which takes possession of the callee /// `WaveWriter`. ///