rescale_core/wav/
header.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum WavSampleFormat {
5 Pcm16Bit,
6 Pcm24Bit,
7 Pcm32BitFloat,
8}
9
10#[derive(Debug, Clone, PartialEq)]
11pub struct WavHeader {
12 pub num_channels: u16,
13 pub sample_rate: u32,
14 pub format: WavSampleFormat,
15 pub num_samples_per_channel: usize,
16}
17
18impl WavHeader {
19 pub fn new(
20 num_channels: u16,
21 sample_rate: u32,
22 format: WavSampleFormat,
23 num_samples_per_channel: usize,
24 ) -> Self {
25 Self {
26 num_channels,
27 sample_rate,
28 format,
29 num_samples_per_channel,
30 }
31 }
32
33 pub fn bits_per_sample(&self) -> u16 {
34 match self.format {
35 WavSampleFormat::Pcm16Bit => 16,
36 WavSampleFormat::Pcm24Bit => 24,
37 WavSampleFormat::Pcm32BitFloat => 32,
38 }
39 }
40
41 pub fn audio_format_tag(&self) -> u16 {
42 match self.format {
43 WavSampleFormat::Pcm16Bit | WavSampleFormat::Pcm24Bit => 1, WavSampleFormat::Pcm32BitFloat => 3, }
46 }
47}