mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2025-12-31 08:50:44 +00:00
Wavewriter impl
This commit is contained in:
@@ -22,19 +22,19 @@ const BASIC_EXTENDED: u16 = 0xFFFE;
|
||||
|
||||
*/
|
||||
|
||||
const UUID_PCM: Uuid = Uuid::from_bytes([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
pub const UUID_PCM: Uuid = Uuid::from_bytes([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]);
|
||||
|
||||
const UUID_FLOAT: Uuid = Uuid::from_bytes([0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
pub const UUID_FLOAT: Uuid = Uuid::from_bytes([0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]);
|
||||
|
||||
const UUID_MPEG: Uuid = Uuid::from_bytes([0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
pub const UUID_MPEG: Uuid = Uuid::from_bytes([0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]);
|
||||
|
||||
const UUID_BFORMAT_PCM: Uuid = Uuid::from_bytes([0x01, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11,
|
||||
pub const UUID_BFORMAT_PCM: Uuid = Uuid::from_bytes([0x01, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11,
|
||||
0x86, 0x44, 0xc8, 0xc1, 0xca, 0x00, 0x00, 0x00]);
|
||||
|
||||
const UUID_BFORMAT_FLOAT: Uuid = Uuid::from_bytes([0x03, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11,
|
||||
pub const UUID_BFORMAT_FLOAT: Uuid = Uuid::from_bytes([0x03, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11,
|
||||
0x86, 0x44, 0xc8, 0xc1, 0xca, 0x00, 0x00, 0x00]);
|
||||
|
||||
|
||||
|
||||
14
src/fmt.rs
14
src/fmt.rs
@@ -1,5 +1,5 @@
|
||||
use uuid::Uuid;
|
||||
use super::common_format::CommonFormat;
|
||||
use super::common_format::{CommonFormat, UUID_PCM};
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -200,7 +200,17 @@ impl WaveFmt {
|
||||
bytes_per_second: container_bytes_per_sample as u32 * sample_rate * channel_count as u32,
|
||||
block_alignment: container_bytes_per_sample * channel_count,
|
||||
bits_per_sample: container_bits_per_sample,
|
||||
extended_format: None
|
||||
extended_format: {
|
||||
if channel_count > 2 {
|
||||
Some( WaveFmtExtended {
|
||||
channel_mask : !(0xFFFF_FFFF << channel_count),
|
||||
type_guid: UUID_PCM,
|
||||
valid_bits_per_sample: bits_per_sample
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ use std::fs::File;
|
||||
use std::io::{Write,Seek,SeekFrom};
|
||||
|
||||
use super::Error;
|
||||
use super::fourcc::{FourCC, WriteFourCC, RIFF_SIG, WAVE_SIG, FMT__SIG,};
|
||||
use super::fourcc::{FourCC, WriteFourCC, RIFF_SIG, WAVE_SIG, FMT__SIG,FACT_SIG};
|
||||
use super::fmt::WaveFmt;
|
||||
use super::common_format::CommonFormat;
|
||||
use super::chunks::WriteBWaveChunks;
|
||||
|
||||
use byteorder::LittleEndian;
|
||||
@@ -66,7 +67,9 @@ impl<W> Write for WaveChunkWriter<W> where W: Write + Seek {
|
||||
pub struct WaveWriter<W> where W: Write + Seek {
|
||||
inner : W,
|
||||
form_length: u64,
|
||||
format: WaveFmt
|
||||
|
||||
/// Format of the wave file.
|
||||
pub format: WaveFmt
|
||||
}
|
||||
|
||||
impl WaveWriter<File> {
|
||||
@@ -97,7 +100,14 @@ impl<W> WaveWriter<W> where W: Write + Seek {
|
||||
chunk.write_wave_fmt(&format)?;
|
||||
let retval = chunk.end();
|
||||
|
||||
Ok( retval )
|
||||
if format.common_format() != CommonFormat::IntegerPCM {
|
||||
let mut chunk = retval.begin_chunk(FACT_SIG)?;
|
||||
chunk.write_u32::<LittleEndian>(0)?;
|
||||
let retval = chunk.end();
|
||||
Ok( retval )
|
||||
} else {
|
||||
Ok( retval )
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new chunk writer, which takes posession of the `WaveWriter`.
|
||||
@@ -136,3 +146,4 @@ fn test_new() {
|
||||
assert_eq!(form_size, fmt_size + 8 + 4);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user