mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2026-01-01 09:20:45 +00:00
prettify code
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use uuid::Uuid;
|
||||
|
||||
const BASIC_PCM: u16 = 0x0001;
|
||||
const BASIC_FLOAT: u16 = 0x0003;
|
||||
const BASIC_MPEG: u16 = 0x0050;
|
||||
const BASIC_EXTENDED: u16 = 0xFFFE;
|
||||
const BASIC_PCM: u16 = 0x0001;
|
||||
const BASIC_FLOAT: u16 = 0x0003;
|
||||
const BASIC_MPEG: u16 = 0x0050;
|
||||
const BASIC_EXTENDED: u16 = 0xFFFE;
|
||||
|
||||
/* RC 2361 §4:
|
||||
|
||||
@@ -15,50 +15,54 @@ const BASIC_EXTENDED: u16 = 0xFFFE;
|
||||
|
||||
*/
|
||||
|
||||
pub const UUID_PCM: Uuid = Uuid::from_bytes([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]);
|
||||
pub const UUID_PCM: Uuid = Uuid::from_bytes([
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71,
|
||||
]);
|
||||
|
||||
pub const UUID_FLOAT: Uuid = Uuid::from_bytes([0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]);
|
||||
pub const UUID_FLOAT: Uuid = Uuid::from_bytes([
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71,
|
||||
]);
|
||||
|
||||
pub const UUID_MPEG: Uuid = Uuid::from_bytes([0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]);
|
||||
pub const UUID_MPEG: Uuid = Uuid::from_bytes([
|
||||
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71,
|
||||
]);
|
||||
|
||||
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]);
|
||||
|
||||
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]);
|
||||
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,
|
||||
]);
|
||||
|
||||
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,
|
||||
]);
|
||||
|
||||
fn uuid_from_basic_tag(tag: u16) -> Uuid {
|
||||
let tail : [u8; 6] = [0x00,0xaa,0x00,0x38,0x9b,0x71];
|
||||
let tail: [u8; 6] = [0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71];
|
||||
Uuid::from_fields_le(tag as u32, 0x0000, 0x0010, &tail).unwrap()
|
||||
}
|
||||
|
||||
/// Sample format of the Wave file.
|
||||
///
|
||||
///
|
||||
///
|
||||
///
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum CommonFormat {
|
||||
/// Integer linear PCM
|
||||
IntegerPCM,
|
||||
|
||||
|
||||
/// IEEE Floating-point Linear PCM
|
||||
IeeeFloatPCM,
|
||||
|
||||
|
||||
/// MPEG
|
||||
Mpeg,
|
||||
|
||||
|
||||
/// Ambisonic B-Format Linear PCM
|
||||
AmbisonicBFormatIntegerPCM,
|
||||
|
||||
|
||||
/// Ambisonic B-Format Float PCM
|
||||
AmbisonicBFormatIeeeFloatPCM,
|
||||
|
||||
|
||||
/// An unknown format identified by a basic format tag.
|
||||
UnknownBasic(u16),
|
||||
|
||||
|
||||
/// An unknown format identified by an extension UUID.
|
||||
UnknownExtended(Uuid),
|
||||
}
|
||||
@@ -70,18 +74,18 @@ impl CommonFormat {
|
||||
(BASIC_PCM, _) => Self::IntegerPCM,
|
||||
(BASIC_FLOAT, _) => Self::IeeeFloatPCM,
|
||||
(BASIC_MPEG, _) => Self::Mpeg,
|
||||
(BASIC_EXTENDED, Some(UUID_PCM)) => Self::IntegerPCM,
|
||||
(BASIC_EXTENDED, Some(UUID_FLOAT))=> Self::IeeeFloatPCM,
|
||||
(BASIC_EXTENDED, Some(UUID_PCM)) => Self::IntegerPCM,
|
||||
(BASIC_EXTENDED, Some(UUID_FLOAT)) => Self::IeeeFloatPCM,
|
||||
(BASIC_EXTENDED, Some(UUID_BFORMAT_PCM)) => Self::AmbisonicBFormatIntegerPCM,
|
||||
(BASIC_EXTENDED, Some(UUID_BFORMAT_FLOAT)) => Self::AmbisonicBFormatIeeeFloatPCM,
|
||||
(BASIC_EXTENDED, Some(x)) => CommonFormat::UnknownExtended(x),
|
||||
(x, _) => CommonFormat::UnknownBasic(x)
|
||||
(x, _) => CommonFormat::UnknownBasic(x),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the appropriate tag and `Uuid` for the callee.
|
||||
///
|
||||
/// If there is no appropriate tag for the format of the callee, the
|
||||
///
|
||||
/// If there is no appropriate tag for the format of the callee, the
|
||||
/// returned tag will be 0xFFFE and the `Uuid` will describe the format.
|
||||
pub fn take(self) -> (u16, Uuid) {
|
||||
match self {
|
||||
@@ -90,8 +94,8 @@ impl CommonFormat {
|
||||
Self::Mpeg => (BASIC_MPEG, UUID_MPEG),
|
||||
Self::AmbisonicBFormatIntegerPCM => (BASIC_EXTENDED, UUID_BFORMAT_PCM),
|
||||
Self::AmbisonicBFormatIeeeFloatPCM => (BASIC_EXTENDED, UUID_BFORMAT_FLOAT),
|
||||
Self::UnknownBasic(x) => ( x, uuid_from_basic_tag(x) ),
|
||||
Self::UnknownExtended(x) => ( BASIC_EXTENDED, x)
|
||||
Self::UnknownBasic(x) => (x, uuid_from_basic_tag(x)),
|
||||
Self::UnknownExtended(x) => (BASIC_EXTENDED, x),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user