Debian Codegraph @

third_party/rust/cubeb/src/sample.rs

raw
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
6 /// An extension trait which allows the implementation of converting
7 /// void* buffers from libcubeb-sys into rust slices of the appropriate
8 /// type.
9 pub trait Sample: Send + Copy {
10 /// Map f32 in range [-1,1] to sample type
11 fn from_float(_: f32) -> Self;
12 }
13
14 impl Sample for i16 {
15 fn from_float(x: f32) -> i16 {
16 (x * f32::from(i16::MAX)) as i16
17 }
18 }
19
20 impl Sample for f32 {
21 fn from_float(x: f32) -> f32 {
22 x
23 }
24 }