@@ -126,8 +126,6 @@ impl Iterator for MediaDecoder {
126
126
// Get the track.
127
127
let track = format. tracks ( ) . get ( * track_index) ?;
128
128
let track_id = track. id ;
129
- let number_of_channels = track. codec_params . channels ?. count ( ) ;
130
- let input_sample_rate = track. codec_params . sample_rate ? as f32 ;
131
129
132
130
loop {
133
131
// Get the next packet from the format reader.
@@ -166,8 +164,8 @@ impl Iterator for MediaDecoder {
166
164
167
165
// Decode the packet into audio samples.
168
166
match decoder. decode ( & packet) {
169
- Ok ( audio_buf ) => {
170
- let output = convert_buf ( audio_buf , number_of_channels , input_sample_rate ) ;
167
+ Ok ( input ) => {
168
+ let output = convert_buf ( input ) ;
171
169
return Some ( Ok ( output) ) ;
172
170
}
173
171
Err ( SymphoniaError :: DecodeError ( err) ) => {
@@ -188,52 +186,49 @@ impl Iterator for MediaDecoder {
188
186
}
189
187
190
188
/// Convert a Symphonia AudioBufferRef to our own AudioBuffer
191
- fn convert_buf (
192
- input : AudioBufferRef < ' _ > ,
193
- number_of_channels : usize ,
194
- input_sample_rate : f32 ,
195
- ) -> AudioBuffer {
196
- let chans = 0 ..number_of_channels;
189
+ fn convert_buf ( input : AudioBufferRef < ' _ > ) -> AudioBuffer {
190
+ let channels = 0 ..input. spec ( ) . channels . count ( ) ;
191
+ let sample_rate = input. spec ( ) . rate as f32 ;
197
192
198
193
// This looks a bit awkward but this may be the only way to get the f32 samples
199
194
// out without making double copies.
200
195
use symphonia:: core:: audio:: AudioBufferRef :: * ;
201
196
202
197
let data: Vec < Vec < f32 > > = match input {
203
- U8 ( buf) => chans
198
+ U8 ( buf) => channels
204
199
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
205
200
. collect ( ) ,
206
- U16 ( buf) => chans
201
+ U16 ( buf) => channels
207
202
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
208
203
. collect ( ) ,
209
- U24 ( buf) => chans
204
+ U24 ( buf) => channels
210
205
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
211
206
. collect ( ) ,
212
- U32 ( buf) => chans
207
+ U32 ( buf) => channels
213
208
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
214
209
. collect ( ) ,
215
- S8 ( buf) => chans
210
+ S8 ( buf) => channels
216
211
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
217
212
. collect ( ) ,
218
- S16 ( buf) => chans
213
+ S16 ( buf) => channels
219
214
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
220
215
. collect ( ) ,
221
- S24 ( buf) => chans
216
+ S24 ( buf) => channels
222
217
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
223
218
. collect ( ) ,
224
- S32 ( buf) => chans
219
+ S32 ( buf) => channels
225
220
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
226
221
. collect ( ) ,
227
- F32 ( buf) => chans
222
+ F32 ( buf) => channels
228
223
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
229
224
. collect ( ) ,
230
- F64 ( buf) => chans
225
+ F64 ( buf) => channels
231
226
. map ( |i| buf. chan ( i) . iter ( ) . copied ( ) . map ( f32:: from_sample) . collect ( ) )
232
227
. collect ( ) ,
233
228
} ;
234
229
235
230
let channels = data. into_iter ( ) . map ( ChannelData :: from) . collect ( ) ;
236
- AudioBuffer :: from_channels ( channels, input_sample_rate )
231
+ AudioBuffer :: from_channels ( channels, sample_rate )
237
232
}
238
233
239
234
#[ cfg( test) ]
0 commit comments