@@ -17,15 +17,15 @@ impl i24 {
17
17
}
18
18
}
19
19
20
- pub struct Requantizer {
20
+ pub struct Converter {
21
21
ditherer : Box < dyn Ditherer > ,
22
22
noise_shaper : Box < dyn NoiseShaper > ,
23
23
}
24
24
25
- impl Requantizer {
25
+ impl Converter {
26
26
pub fn new ( ditherer : Box < dyn Ditherer > , noise_shaper : Box < dyn NoiseShaper > ) -> Self {
27
27
info ! (
28
- "Requantizing with ditherer: {} and noise shaper: {}" ,
28
+ "Converting with ditherer: {} and noise shaper: {}" ,
29
29
ditherer, noise_shaper
30
30
) ;
31
31
Self {
@@ -67,43 +67,43 @@ impl Requantizer {
67
67
let noise = self . ditherer . noise ( sample) ;
68
68
self . noise_shaper . shape ( sample, noise)
69
69
}
70
- }
71
70
72
- // https://doc.rust-lang.org/nomicon/casts.html: casting float to integer
73
- // rounds towards zero, then saturates. Ideally halves should round to even to
74
- // prevent any bias, but since it is extremely unlikely that a float has
75
- // *exactly* .5 as fraction, this should be more than precise enough.
76
- pub fn to_s32 ( samples : & [ f32 ] , requantizer : & mut Requantizer ) -> Vec < i32 > {
77
- samples
78
- . iter ( )
79
- . map ( |sample| requantizer . scale ( * sample, std:: i32:: MAX ) as i32 )
80
- . collect ( )
81
- }
71
+ // https://doc.rust-lang.org/nomicon/casts.html: casting float to integer
72
+ // rounds towards zero, then saturates. Ideally halves should round to even to
73
+ // prevent any bias, but since it is extremely unlikely that a float has
74
+ // *exactly* .5 as fraction, this should be more than precise enough.
75
+ pub fn f32_to_s32 ( & mut self , samples : & [ f32 ] ) -> Vec < i32 > {
76
+ samples
77
+ . iter ( )
78
+ . map ( |sample| self . scale ( * sample, std:: i32:: MAX ) as i32 )
79
+ . collect ( )
80
+ }
82
81
83
- // S24 is 24-bit PCM packed in an upper 32-bit word
84
- pub fn to_s24 ( samples : & [ f32 ] , requantizer : & mut Requantizer ) -> Vec < i32 > {
85
- samples
86
- . iter ( )
87
- . map ( |sample| requantizer . clamping_scale ( * sample, i24:: MIN , i24:: MAX ) as i32 )
88
- . collect ( )
89
- }
82
+ // S24 is 24-bit PCM packed in an upper 32-bit word
83
+ pub fn f32_to_s24 ( & mut self , samples : & [ f32 ] ) -> Vec < i32 > {
84
+ samples
85
+ . iter ( )
86
+ . map ( |sample| self . clamping_scale ( * sample, i24:: MIN , i24:: MAX ) as i32 )
87
+ . collect ( )
88
+ }
90
89
91
- // S24_3 is 24-bit PCM in a 3-byte array
92
- pub fn to_s24_3 ( samples : & [ f32 ] , requantizer : & mut Requantizer ) -> Vec < i24 > {
93
- samples
94
- . iter ( )
95
- . map ( |sample| {
96
- // Not as DRY as calling to_s24 first, but this saves iterating
97
- // over all samples twice.
98
- let int_value = requantizer . clamping_scale ( * sample, i24:: MIN , i24:: MAX ) as i32 ;
99
- i24:: from_s24 ( int_value)
100
- } )
101
- . collect ( )
102
- }
90
+ // S24_3 is 24-bit PCM in a 3-byte array
91
+ pub fn f32_to_s24_3 ( & mut self , samples : & [ f32 ] ) -> Vec < i24 > {
92
+ samples
93
+ . iter ( )
94
+ . map ( |sample| {
95
+ // Not as DRY as calling f32_to_s24 first, but this saves iterating
96
+ // over all samples twice.
97
+ let int_value = self . clamping_scale ( * sample, i24:: MIN , i24:: MAX ) as i32 ;
98
+ i24:: from_s24 ( int_value)
99
+ } )
100
+ . collect ( )
101
+ }
103
102
104
- pub fn to_s16 ( samples : & [ f32 ] , requantizer : & mut Requantizer ) -> Vec < i16 > {
105
- samples
106
- . iter ( )
107
- . map ( |sample| requantizer. scale ( * sample, std:: i16:: MAX as i32 ) as i16 )
108
- . collect ( )
103
+ pub fn f32_to_s16 ( & mut self , samples : & [ f32 ] ) -> Vec < i16 > {
104
+ samples
105
+ . iter ( )
106
+ . map ( |sample| self . scale ( * sample, std:: i16:: MAX as i32 ) as i16 )
107
+ . collect ( )
108
+ }
109
109
}
0 commit comments