cubeb_core/
format.rs

1// Copyright © 2017-2018 Mozilla Foundation
2//
3// This program is made available under an ISC-style license.  See the
4// accompanying file LICENSE for details.
5
6use ffi;
7
8#[derive(PartialEq, Eq, Clone, Debug, Copy)]
9pub enum SampleFormat {
10    S16LE,
11    S16BE,
12    Float32LE,
13    Float32BE,
14    // Maps to the platform native endian
15    S16NE,
16    Float32NE,
17}
18
19impl From<ffi::cubeb_sample_format> for SampleFormat {
20    fn from(x: ffi::cubeb_sample_format) -> SampleFormat {
21        match x {
22            ffi::CUBEB_SAMPLE_S16LE => SampleFormat::S16LE,
23            ffi::CUBEB_SAMPLE_S16BE => SampleFormat::S16BE,
24            ffi::CUBEB_SAMPLE_FLOAT32LE => SampleFormat::Float32LE,
25            ffi::CUBEB_SAMPLE_FLOAT32BE => SampleFormat::Float32BE,
26            // TODO: Implement TryFrom
27            _ => SampleFormat::S16NE,
28        }
29    }
30}
31
32impl From<SampleFormat> for ffi::cubeb_sample_format {
33    fn from(x: SampleFormat) -> Self {
34        use SampleFormat::*;
35        match x {
36            S16LE => ffi::CUBEB_SAMPLE_S16LE,
37            S16BE => ffi::CUBEB_SAMPLE_S16BE,
38            Float32LE => ffi::CUBEB_SAMPLE_FLOAT32LE,
39            Float32BE => ffi::CUBEB_SAMPLE_FLOAT32BE,
40            S16NE => ffi::CUBEB_SAMPLE_S16NE,
41            Float32NE => ffi::CUBEB_SAMPLE_FLOAT32NE,
42        }
43    }
44}