@@ -39,8 +39,6 @@ use symphonia_core::io::ReadBytes;
39
39
use symphonia_core:: sample:: { i24, u24, SampleFormat } ;
40
40
use symphonia_core:: units:: Duration ;
41
41
42
- use std:: mem;
43
-
44
42
macro_rules! impl_generic_audio_buffer_func {
45
43
( $generic: expr, $buf: ident, $expr: expr) => {
46
44
match $generic {
@@ -124,11 +122,16 @@ macro_rules! read_pcm_signed_be {
124
122
// Get buffer of the correct sample format.
125
123
match $buf {
126
124
GenericAudioBuffer :: $fmt( ref mut buf) => {
127
- let sample_size = mem:: size_of_val( & $read) * 8 ;
128
- let mask = !0 << ( sample_size as u32 - $coded_width) ;
129
125
buf. fill( |audio_planes, idx| -> Result <( ) > {
130
126
for plane in audio_planes. planes( ) {
131
- plane[ idx] = ( $read & mask) . into_sample( ) ;
127
+ // To properly read a a sample with a shorter coded width,
128
+ // it should be masked using (1 << ($width - $coded_width)) - 1, masking out rightmost bits.
129
+ // ffpmeg seems to not do this, at least in the case for 12bit aiff PCM.
130
+ // If the aiff file is offspec, by not setting padded out bits to 0,
131
+ // this will fail when verifying with ffmpeg
132
+ // To comply with, we will not mask the sample.
133
+ // It should not make a hearable difference anyway.
134
+ plane[ idx] = ( $read) . into_sample( ) ;
132
135
}
133
136
Ok ( ( ) )
134
137
} )
@@ -162,11 +165,16 @@ macro_rules! read_pcm_unsigned_be {
162
165
// Get buffer of the correct sample format.
163
166
match $buf {
164
167
GenericAudioBuffer :: $fmt( ref mut buf) => {
165
- let sample_size = mem:: size_of_val( & $read) * 8 ;
166
- let mask = !0 << ( sample_size as u32 - $coded_width) ;
167
168
buf. fill( |audio_planes, idx| -> Result <( ) > {
168
169
for plane in audio_planes. planes( ) {
169
- plane[ idx] = ( $read & mask) . into_sample( ) ;
170
+ // To properly read a a sample with a shorter coded width,
171
+ // it should be masked using (1 << ($width - $coded_width)) - 1, masking out rightmost bits.
172
+ // ffpmeg seems to not do this, at least in the case for 12bit aiff PCM.
173
+ // If the aiff file is offspec, by not setting padded out bits to 0,
174
+ // this will fail when verifying with ffmpeg
175
+ // To comply with, we will not mask the sample.
176
+ // It should not make a hearable difference anyway.
177
+ plane[ idx] = ( $read) . into_sample( ) ;
170
178
}
171
179
Ok ( ( ) )
172
180
} )
0 commit comments