From 70bf402776ef215b7cf19042a02ce1cc011b2dac Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sat, 26 Dec 2020 13:52:52 -0800 Subject: [PATCH] Ambisonic format create/write --- README.md | 2 +- src/fmt.rs | 19 +++++++++++++++++-- src/wavewriter.rs | 6 +++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c3053cc..02eb4b5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This is currently a work-in-progress! However many features presently work: | Transparent promotion to RF64/BW64 | ☑️ | | | Unified interface for regular and extended Wave format | ☑️ | | | Channel/speaker map metadata | ☑️ | ☑️ | -| Ambisonic B-format metadata | ☑️ | | +| Ambisonic B-format metadata | ☑️ | ☑️ | | EBU Broadcast-WAVE metadata | ☑️ | ☑️ | | Basic iXML/ADM metadata | ☑️ | | | Enhanced iXML metadata support | | | diff --git a/src/fmt.rs b/src/fmt.rs index b5f0d6b..1c1b53b 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -1,5 +1,5 @@ use uuid::Uuid; -use super::common_format::{CommonFormat, UUID_PCM}; +use super::common_format::{CommonFormat, UUID_PCM,UUID_BFORMAT_PCM}; #[allow(dead_code)] @@ -195,7 +195,22 @@ impl WaveFmt { /// Create a new integer PCM format for ambisonic b-format. pub fn new_pcm_ambisonic(sample_rate: u32, bits_per_sample: u16, channel_count: u16) -> Self { - todo!() + let container_bits_per_sample = bits_per_sample + (bits_per_sample % 8); + let container_bytes_per_sample= container_bits_per_sample / 8; + + WaveFmt { + tag : 0xFFFE, + channel_count, + sample_rate, + 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: Some(WaveFmtExtended { + valid_bits_per_sample: bits_per_sample, + channel_mask: ChannelMask::DirectOut as u32, + type_guid: UUID_BFORMAT_PCM + }) + } } /// Create a new integer PCM format `WaveFmt` with a custom channel bitmap. diff --git a/src/wavewriter.rs b/src/wavewriter.rs index 566d179..24724ac 100644 --- a/src/wavewriter.rs +++ b/src/wavewriter.rs @@ -191,9 +191,9 @@ impl WaveWriter where W: Write + Seek { /// Write Broadcast-Wave metadata to the file. /// - /// This function will write the metadata chunk immediately; if you have - /// already written and closed the audio data the bext chunk will be - /// positioned after it. + /// This function will write the metadata chunk immediately to the end of + /// the file; if you have already written and closed the audio data the + /// bext chunk will be positioned after it. fn write_broadcast_metadata(self, bext: &Bext) -> Result { let mut b = self.chunk(BEXT_SIG)?; b.write_bext(bext)?;