symphonium 0.9.2

An unofficial easy-to-use wrapper around Symphonia for loading audio files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
//! An unofficial easy-to-use wrapper around [Symphonia](https://github.com/pdeljanov/Symphonia)
//! for loading audio files. It also handles resampling at load-time.
//!
//! The resulting `DecodedAudio` resources are stored in their native sample format whenever
//! possible to save on memory, and have convenience methods to fill a buffer with `f32` samples
//! from any arbitrary position in the resource in realtime during playback. Alternatively you
//! can use the `DecodedAudioF32` resource if you only need samples in the `f32` format.
//!
//! ## Example
//!
//! ```no_run
//! // A struct used to load audio files.
//! # use std::num::NonZeroU32;
//! # use symphonium::{DecodeConfig, cache::SymphoniumCache};
//! # let file_path = std::path::PathBuf::default();
//! let target_sample_rate = NonZeroU32::new(44100).unwrap();
//!
//! // An optional cache to re-use decoders and resamplers.
//! let cache = SymphoniumCache::default();
//!
//! // Probe the audio file.
//! let probed = symphonium::probe_from_file(
//!     &file_path,
//!     // A custom codec prober. Set to `None` to use the default one from symphonia.
//!     None,
//! )
//! .unwrap();
//!
//! // Decode the probed data.
//! let audio_data = symphonium::decode(
//!     probed,
//!     &DecodeConfig::default(),
//!     // Set to `None` to keep the original sample rate of the file.
//!     Some(target_sample_rate),
//!     // Set to `None` if no cache is needed.
//!     Some(&cache),
//!     // A custom codec registry. Set to `None` to use the default one from symphonia.
//!     None,
//! )
//! .unwrap();
//!
//! // Fill a stereo buffer with samples starting at frame 100.
//! let mut buf_l = vec![0.0f32; 512];
//! let mut buf_r = vec![0.0f32; 512];
//! audio_data.fill_stereo(100, &mut buf_l, &mut buf_r);
//!
//! // Alternatively, if you don't need to save memory, you can
//! // decode directly to an `f32` format.
//! let probed = symphonium::probe_from_file(&file_path, None).unwrap();
//! let audio_data_f32 = symphonium::decode_f32(
//!         probed,
//!         &DecodeConfig::default(),
//!         Some(target_sample_rate),
//!         Some(&cache),
//!         None,
//!     )
//!     .unwrap();
//!
//! // Print info about the data (`data` is a `Vec<Vec<f32>>`).
//! println!("num channels: {}", audio_data_f32.data.len());
//! println!("num frames: {}", audio_data_f32.data[0].len());
//! ```
//! ## Features
//!
//! By default, only `wav` and `ogg` support is enabled. If you need more formats, enable them
//! as features in your `Cargo.toml` file like this:
//!
//! `symphonium = { version = "0.9", features = ["mp3", "flac"] }`
//!
//! Available codecs:
//!
//! * `aac`
//! * `adpcm`
//! * `alac`
//! * `flac`
//! * `mp1`
//! * `mp2`
//! * `mp3`
//! * `pcm`
//! * `vorbis`
//!
//! Available container formats:
//!
//! * `caf`
//! * `isomp4`
//! * `mkv`
//! * `ogg`
//! * `aiff`
//! * `wav`
//!
//! Alternatively you can enable the `all` feature if you want everything, or the `open-standards`
//! feature if you want all of the royalty-free open-source standards.

use std::fs::File;
use std::num::{NonZeroU32, NonZeroUsize};
use std::path::Path;

#[cfg(feature = "stretch-sinc-resampler")]
use fixed_resample::PacketResampler;

use symphonia::core::codecs::{CodecRegistry, Decoder};
use symphonia::core::formats::FormatOptions;
use symphonia::core::io::{MediaSource, MediaSourceStream};
use symphonia::core::meta::MetadataOptions;
use symphonia::core::probe::{Hint, Probe, ProbeResult};

#[cfg(all(feature = "log", not(feature = "tracing")))]
use log::warn;
#[cfg(feature = "tracing")]
use tracing::warn;

// Re-export symphonia
pub use symphonia;

#[cfg(feature = "resampler")]
pub mod resample;
#[cfg(feature = "resampler")]
pub use resample::ResampleQuality;

pub mod cache;
pub mod error;

mod decode;
mod resource;

pub use resource::*;

use error::LoadError;

use crate::cache::Cache;
#[cfg(feature = "resampler")]
use crate::resample::ResamplerKey;

/// The default maximum size of an audio file in bytes.
pub static DEFAULT_MAX_BYTES: usize = 1_000_000_000;

/// Load an audio file from the given path and probe its metadata.
///
/// This method does not decode the audio file.
///
/// * `path` - The path to the audio file.
/// * `custom_probe` - The custom [`Probe`] to use. If `None`, then the default symphonia
///   probe will be used.
pub fn probe_from_file<P: AsRef<Path>>(
    path: P,
    custom_probe: Option<&Probe>,
) -> Result<ProbedAudioSource, LoadError> {
    let path: &Path = path.as_ref();

    // Try to open the file.
    let file = File::open(path)?;

    // Create a hint to help the format registry guess what format reader is appropriate.
    let mut hint = Hint::new();

    // Provide the file extension as a hint.
    if let Some(extension) = path.extension()
        && let Some(extension_str) = extension.to_str()
    {
        hint.with_extension(extension_str);
    }

    probe_from_source(Box::new(file), Some(hint), custom_probe)
}

/// Load an audio source from RAM and probe its metadata.
///
/// This method does not decode the audio file.
///
/// * `source` - The [`MediaSource`] to probe.
/// * `hint` - An optional hint that the probe can use to determine the codec.
/// * `custom_probe` - The custom [`Probe`] to use. If `None`, then the default symphonia
///   probe will be used.
pub fn probe_from_source(
    source: Box<dyn MediaSource>,
    hint: Option<Hint>,
    custom_probe: Option<&Probe>,
) -> Result<ProbedAudioSource, LoadError> {
    let probe = custom_probe.unwrap_or_else(|| symphonia::default::get_probe());

    // Create the media source stream.
    let mss = MediaSourceStream::new(source, Default::default());

    // Use the default options for format reader, metadata reader, and decoder.
    let format_opts: FormatOptions = Default::default();
    let metadata_opts: MetadataOptions = Default::default();

    let hint = hint.unwrap_or_default();

    // Probe the media source stream for metadata and get the format reader.
    let probed = probe
        .format(&hint, mss, &format_opts, &metadata_opts)
        .map_err(LoadError::UnkownFormat)?;

    // Get the default track in the audio stream.
    let track = probed
        .format
        .default_track()
        .ok_or_else(|| LoadError::NoTrackFound)?;

    let sample_rate = track.codec_params.sample_rate.and_then(|sr| {
        let sr = NonZeroU32::new(sr);
        #[cfg(any(feature = "tracing", feature = "log"))]
        {
            if sr.is_none() {
                warn!("Audio source returned a sample rate of 0");
            }
        }
        sr
    });

    let num_channels = track
        .codec_params
        .channels
        .ok_or_else(|| LoadError::NoChannelsFound)?
        .count();

    if num_channels == 0 {
        return Err(LoadError::NoChannelsFound);
    }

    Ok(ProbedAudioSource {
        probed,
        sample_rate,
        num_channels: NonZeroUsize::new(num_channels).unwrap(),
    })
}

/// Decode a probed audio source, and resample if the source sample rate does not match
/// the given target sample rate.
///
/// The probed audio source can be loaded with [`probe_from_file`] or
/// [`probe_from_source`].
///
/// * `probed` - The probed audio source.
/// * `config` - Additional decoding settings like resampling quality.
/// * `target_sample_rate` - The sample rate the file will be resampled to. (No
///   resampling will occur if the audio file's sample rate is already
///   the target sample rate).
///     * If this is `None`, or if the `resample` feature is disabled, then the
///       file will not be resampled.
///     * Resampling will always convert the sample format to `f32`.
/// * `cache` - An optional cache to use. You can use a [`Cache`]
///   instance. If `None`, then no caching will occur.
/// * `custom_registry` - The custom [`CodecRegistry`] to use. If `None`, then the default
///   symphonia codec registry will be used.
pub fn decode(
    probed: ProbedAudioSource,
    config: &DecodeConfig,
    target_sample_rate: Option<NonZeroU32>,
    cache: Option<&dyn Cache>,
    custom_registry: Option<&CodecRegistry>,
) -> Result<DecodedAudio, LoadError> {
    #[cfg(not(feature = "resampler"))]
    let _ = target_sample_rate;

    let mut pcm = None;

    with_decoder(
        probed,
        config,
        custom_registry,
        cache,
        |mut probed: ProbedAudioSource,
         decoder: &mut dyn Decoder,
         original_sample_rate: NonZeroU32| {
            #[cfg(feature = "resampler")]
            if let Some(target_sample_rate) = target_sample_rate
                && original_sample_rate != target_sample_rate
            {
                // Resampling is needed.
                pcm = Some(
                    resample(
                        probed,
                        config,
                        target_sample_rate,
                        original_sample_rate,
                        cache,
                        decoder,
                    )
                    .map(|pcm| pcm.into()),
                );

                return;
            }

            pcm = Some(decode::decode_native_bitdepth(
                &mut probed.probed,
                config,
                probed.num_channels,
                original_sample_rate,
                original_sample_rate,
                decoder,
            ));
        },
    )?;

    pcm.unwrap()
}

/// Decode the probed audio source and convert to an f32 sample format.
///
/// The probed audio source can be loaded with [`probe_from_file`] or
/// [`probe_from_source`].
///
/// * `probed` - The probed audio source.
/// * `config` - Additional decoding settings like resampling quality.
/// * `target_sample_rate` - The sample rate the file will be resampled to. (No
///   resampling will occur if the audio file's sample rate is already
///   the target sample rate).
///     * If this is `None`, or if the `resample` feature is disabled, then the
///       file will not be resampled.
/// * `cache` - An optional cache to use. You can use a [`Cache`]
///   instance. If `None`, then no caching will occur.
/// * `custom_registry` - The custom [`CodecRegistry`] to use. If `None`, then the default
///   symphonia codec registry will be used.
pub fn decode_f32(
    probed: ProbedAudioSource,
    config: &DecodeConfig,
    target_sample_rate: Option<NonZeroU32>,
    cache: Option<&dyn Cache>,
    custom_registry: Option<&CodecRegistry>,
) -> Result<DecodedAudioF32, LoadError> {
    #[cfg(not(feature = "resampler"))]
    let _ = target_sample_rate;

    let mut pcm = None;

    with_decoder(
        probed,
        config,
        custom_registry,
        cache,
        |mut probed: ProbedAudioSource,
         decoder: &mut dyn Decoder,
         original_sample_rate: NonZeroU32| {
            #[cfg(feature = "resampler")]
            if let Some(target_sample_rate) = target_sample_rate
                && original_sample_rate != target_sample_rate
            {
                // Resampling is needed.
                pcm = Some(resample(
                    probed,
                    config,
                    target_sample_rate,
                    original_sample_rate,
                    cache,
                    decoder,
                ));

                return;
            }

            pcm = Some(decode::decode_f32(
                &mut probed.probed,
                config,
                probed.num_channels,
                original_sample_rate,
                original_sample_rate,
                decoder,
            ));
        },
    )?;

    pcm.unwrap()
}

/// Decode the probed audio source and convert to an f32 sample format. The sample will
/// be stretched (pitch/time shifted) by the given amount.
///
/// The probed audio source can be loaded with [`probe_from_file`] or
/// [`probe_from_source`].
///
/// * `probed` - The probed audio source.
/// * `stretch` - The amount of stretching (`new_length / old_length`). A value of `1.0` is no
///   change, a value less than `1.0` will increase the pitch & decrease the length, and a value
///   greater than `1.0` will decrease the pitch & increase the length. If a `target_sample_rate`
///   is given, then the final amount will automatically be adjusted to account for that.
/// * `target_sample_rate` - If this is `Some`, then the file will be resampled to that
///   sample rate. If this is `None`, then the file will not be resampled and it will stay its
///   original sample rate.
/// * `config` - Extra configuration.
/// * `cache` - An optional cache to use. You can use a [`Cache`]
///   instance. If `None`, then no caching will occur.
/// * `custom_registry` - The custom [`CodecRegistry`] to use. If `None`, then the default
///   symphonia codec registry will be used.
#[cfg(feature = "stretch-sinc-resampler")]
pub fn decode_stretched(
    probed: ProbedAudioSource,
    stretch: f64,
    target_sample_rate: Option<NonZeroU32>,
    config: &DecodeStretchedConfig,
    cache: Option<&dyn Cache>,
    custom_registry: Option<&CodecRegistry>,
) -> Result<DecodedAudioF32, LoadError> {
    use fixed_resample::rubato;

    let mut pcm = None;

    with_decoder(
        probed,
        &config.config,
        custom_registry,
        cache,
        |mut probed: ProbedAudioSource,
         decoder: &mut dyn Decoder,
         original_sample_rate: NonZeroU32| {
            let mut needs_resample = stretch != 1.0;
            if let Some(target_sample_rate) = target_sample_rate
                && !needs_resample
            {
                needs_resample = original_sample_rate != target_sample_rate;
            }

            pcm = if needs_resample {
                let out_sample_rate = target_sample_rate.unwrap_or(original_sample_rate);
                let ratio =
                    (out_sample_rate.get() as f64 / original_sample_rate.get() as f64) * stretch;

                let mut resampler = PacketResampler::from_custom(Box::new(
                    rubato::Async::new_sinc(
                        ratio,
                        1.0,
                        &rubato::SincInterpolationParameters {
                            sinc_len: config.sinc_len,
                            f_cutoff: rubato::calculate_cutoff(config.sinc_len, config.window),
                            oversampling_factor: config.oversampling_factor,
                            interpolation: config.interpolation,
                            window: config.window,
                        },
                        512,
                        probed.num_channels.get(),
                        rubato::FixedAsync::Input,
                    )
                    .unwrap(),
                ));

                Some(decode::decode_resampled(
                    &mut probed.probed,
                    &config.config,
                    out_sample_rate,
                    original_sample_rate,
                    probed.num_channels,
                    &mut resampler,
                    decoder,
                ))
            } else {
                Some(decode::decode_f32(
                    &mut probed.probed,
                    &config.config,
                    probed.num_channels,
                    original_sample_rate,
                    original_sample_rate,
                    decoder,
                ))
            };
        },
    )?;

    pcm.unwrap()
}

fn with_decoder(
    probed: ProbedAudioSource,
    config: &DecodeConfig,
    custom_registry: Option<&CodecRegistry>,
    cache: Option<&dyn Cache>,
    mut f: impl FnMut(ProbedAudioSource, &mut dyn Decoder, NonZeroU32),
) -> Result<(), LoadError> {
    let original_sample_rate = probed.sample_rate.unwrap_or_else(|| {
        #[cfg(any(feature = "tracing", feature = "log"))]
        warn!("Audio resource has an unkown sample rate. Assuming a sample rate of 44100...");
        NonZeroU32::new(44100).unwrap()
    });

    let codec_registry = custom_registry.unwrap_or_else(|| symphonia::default::get_codecs());

    let opts = symphonia::core::codecs::DecoderOptions {
        verify: config.verify,
    };

    if let Some(cache) = cache
        && config.cache_decoder
    {
        cache.with_decoder_mut(probed, &opts, codec_registry, &mut |probed, decoder| {
            (f)(probed, decoder, original_sample_rate)
        })?;
    } else {
        // Get the default track in the audio stream.
        let track = probed
            .probed
            .format
            .default_track()
            .ok_or_else(|| LoadError::NoTrackFound)?;

        let mut decoder = codec_registry
            .make(&track.codec_params, &opts)
            .map_err(LoadError::CouldNotCreateDecoder)?;

        (f)(probed, &mut *decoder, original_sample_rate);
    }

    Ok(())
}

#[cfg(feature = "resampler")]
fn resample(
    mut probed: ProbedAudioSource,
    config: &DecodeConfig,
    target_sample_rate: NonZeroU32,
    original_sample_rate: NonZeroU32,
    cache: Option<&dyn Cache>,
    decoder: &mut dyn Decoder,
) -> Result<DecodedAudioF32, LoadError> {
    let mut pcm = None;

    let key = ResamplerKey {
        source_sample_rate: original_sample_rate,
        target_sample_rate,
        channels: probed.num_channels.get() as u16,
        quality: match config.resample_quality {
            ResampleQuality::VeryLow => 0,
            ResampleQuality::Low => 1,
            ResampleQuality::High => 2,
            ResampleQuality::HighWithLowLatency => 3,
        },
    };

    if let Some(cache) = cache
        && config.cache_resampler
    {
        cache.with_resampler_mut(key, probed, &mut |mut probed, resampler| {
            if resampler.nbr_channels() != probed.num_channels.get() {
                pcm = Some(Err(LoadError::InvalidResampler {
                    needed_channels: probed.num_channels.get(),
                    got_channels: resampler.nbr_channels(),
                }));
                return;
            }

            pcm = Some(decode::decode_resampled(
                &mut probed.probed,
                config,
                target_sample_rate,
                original_sample_rate,
                probed.num_channels,
                resampler,
                decoder,
            ));

            resampler.reset();
        });
    } else {
        let mut resampler = key.create_resampler();

        pcm = Some(decode::decode_resampled(
            &mut probed.probed,
            config,
            target_sample_rate,
            original_sample_rate,
            probed.num_channels,
            &mut resampler,
            decoder,
        ));
    }

    pcm.unwrap()
}

/// An audio source which has had its metadata probed, but has not been decoded yet.
pub struct ProbedAudioSource {
    probed: ProbeResult,
    sample_rate: Option<NonZeroU32>,
    num_channels: NonZeroUsize,
}

impl ProbedAudioSource {
    pub fn probe_result(&self) -> &ProbeResult {
        &self.probed
    }

    pub fn probe_result_mut(&mut self) -> &mut ProbeResult {
        &mut self.probed
    }

    /// The sample rate of the audio source.
    ///
    /// Returns `None` if the sample rate is unkown.
    pub fn sample_rate(&self) -> Option<NonZeroU32> {
        self.sample_rate
    }

    /// Override the sample rate of this resource with the given sample rate. This
    /// can be useful if [`ProbedAudioSource::sample_rate`] returns `None`, but you
    /// know what the sample rate is ahead of time.
    pub fn override_sample_rate(&mut self, sample_rate: NonZeroU32) {
        self.sample_rate = Some(sample_rate);
    }

    pub fn num_channels(&self) -> NonZeroUsize {
        self.num_channels
    }
}

/// Additional settings for decoding audio data.
#[derive(Clone, Copy)]
pub struct DecodeConfig {
    /// The maximum size in bytes that the resulting `DecodedAudio`
    /// resource can be in RAM. If the resulting resource is larger than
    /// this, then an error will be returned instead. This is useful to
    /// avoid locking up or crashing the system if the user tries to load
    /// a really large audio file.
    ///
    /// By default, this is set to `1_000_000_000` (1GB).
    pub max_bytes: usize,

    /// Whether the decoded audio should be verified if possible during the
    /// decode process.
    ///
    /// By default, this is set to `false`.
    pub verify: bool,

    /// If a [`Cache`] is present, then the decoder will be cached.
    ///
    /// By default, this is set to `true`.
    pub cache_decoder: bool,

    /// If a [`Cache`] is present, then the resampler will be cached if it
    /// is needed.
    ///
    /// This has no effect if the `resampler` feature is disabled, or when
    /// using `decode_stretched`.
    ///
    /// By default, this is set to `true`.
    pub cache_resampler: bool,

    /// The quality of the resampler to use if the `target_sample_rate`
    /// doesn't match the source sample rate.
    ///
    /// This has no effect if the source sample rate matches the target
    /// sample rate, or when using `decode_stretched`.
    ///
    /// By default, this is set to `ResampleQuality::default()` (High).
    #[cfg(feature = "resampler")]
    pub resample_quality: ResampleQuality,
}

impl Default for DecodeConfig {
    fn default() -> Self {
        Self {
            max_bytes: DEFAULT_MAX_BYTES,
            verify: false,
            cache_decoder: true,
            cache_resampler: true,
            #[cfg(feature = "resampler")]
            resample_quality: ResampleQuality::default(),
        }
    }
}

/// Additional settings for stretching audio data.
#[cfg(feature = "stretch-sinc-resampler")]
pub struct DecodeStretchedConfig {
    pub config: DecodeConfig,

    /// Length of the windowed sinc interpolation filter.
    /// Higher values can allow a higher cut-off frequency leading to less high frequency roll-off
    /// at the expense of higher CPU usage. 256 is a good starting point.
    /// The value will be rounded up to the nearest multiple of 8.
    ///
    /// By default this is set to `256`.
    pub sinc_len: usize,

    /// The window function to use.
    ///
    /// By default this is set to
    /// [`WindowFunction::Blackman2`](fixed_resample::rubato::WindowFunction::Blackman2).
    pub window: fixed_resample::rubato::WindowFunction,

    /// The number of intermediate points to use for interpolation.
    /// Higher values use more memory for storing the sinc filters.
    /// Only the points actually needed are calculated during processing
    /// so a larger number does not directly lead to higher CPU usage.
    /// A lower value helps in keeping the sincs in the CPU cache. Start at 128.
    ///
    /// By default this is set to `256`.
    pub oversampling_factor: usize,

    /// Interpolation methods that can be selected. For asynchronous interpolation where the
    /// ratio between input and output sample rates can be any number, it's not possible to
    /// pre-calculate all the needed interpolation filters.
    /// Instead they have to be computed as needed, which becomes impractical since the
    /// sincs are very expensive to generate in terms of CPU time.
    /// It's more efficient to combine the sinc filters with some other interpolation technique.
    /// Then, sinc filters are used to provide a fixed number of interpolated points between input samples,
    /// and then, the new value is calculated by interpolation between those points.
    ///
    /// By default this is set to
    /// [`SincInterpolationType::Quadratic`](fixed_resample::rubato::SincInterpolationType::Quadratic).
    pub interpolation: fixed_resample::rubato::SincInterpolationType,
}

#[cfg(feature = "stretch-sinc-resampler")]
impl Default for DecodeStretchedConfig {
    fn default() -> Self {
        Self {
            config: DecodeConfig::default(),
            sinc_len: 256,
            oversampling_factor: 256,
            interpolation: fixed_resample::rubato::SincInterpolationType::Quadratic,
            window: fixed_resample::rubato::WindowFunction::Blackman2,
        }
    }
}