voirs-evaluation 0.1.0-rc.1

Quality evaluation and assessment framework for VoiRS
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
715
//! Format-specific audio decoders and utilities.
//!
//! This module provides implementations for loading various audio formats,
//! with fallback implementations that create placeholder data for formats
//! that don't have full decoder implementations yet.

use super::{AudioFormat, AudioIoError, AudioIoResult, AudioMetadata, LoadOptions};
use std::fs::File;
use std::path::Path;
use symphonia::core::audio::{AudioBufferRef, Signal};
use symphonia::core::formats::FormatOptions;
use symphonia::core::io::MediaSourceStream;
use symphonia::core::meta::MetadataOptions;
use symphonia::core::probe::Hint;
use voirs_sdk::AudioBuffer;

/// Apply audio conversion (sample rate and channel conversion) if needed
fn apply_audio_conversion(
    samples: Vec<f32>,
    sample_rate: u32,
    channels: u32,
    options: &LoadOptions,
) -> AudioIoResult<(Vec<f32>, u32, u32)> {
    let mut final_samples = samples;
    let mut final_sample_rate = sample_rate;
    let mut final_channels = channels;

    // Apply target sample rate conversion if needed
    if let Some(target_rate) = options.target_sample_rate {
        if target_rate != sample_rate {
            final_samples = resample_audio(final_samples, sample_rate, target_rate, channels)?;
            final_sample_rate = target_rate;
        }
    }

    // Apply channel conversion if needed
    if let Some(target_channels) = options.target_channels {
        if target_channels != channels {
            final_samples = convert_channels(final_samples, channels, target_channels)?;
            final_channels = target_channels;
        }
    }

    Ok((final_samples, final_sample_rate, final_channels))
}

/// Simple resampling using linear interpolation
fn resample_audio(
    samples: Vec<f32>,
    from_rate: u32,
    to_rate: u32,
    channels: u32,
) -> AudioIoResult<Vec<f32>> {
    if from_rate == to_rate {
        return Ok(samples);
    }

    let ratio = from_rate as f64 / to_rate as f64;
    let frames_in = samples.len() / channels as usize;
    let frames_out = (frames_in as f64 / ratio).ceil() as usize;

    let mut resampled = Vec::with_capacity(frames_out * channels as usize);

    for frame_out in 0..frames_out {
        let pos = frame_out as f64 * ratio;
        let input_frame = pos.floor() as usize;
        let frac = pos - input_frame as f64;

        for ch in 0..channels as usize {
            let sample = if input_frame + 1 < frames_in {
                let s0 = samples[input_frame * channels as usize + ch];
                let s1 = samples[(input_frame + 1) * channels as usize + ch];
                s0 + frac as f32 * (s1 - s0)
            } else if input_frame < frames_in {
                samples[input_frame * channels as usize + ch]
            } else {
                0.0
            };
            resampled.push(sample);
        }
    }

    Ok(resampled)
}

/// Convert between different channel counts
fn convert_channels(
    samples: Vec<f32>,
    from_channels: u32,
    to_channels: u32,
) -> AudioIoResult<Vec<f32>> {
    if from_channels == to_channels {
        return Ok(samples);
    }

    let frames = samples.len() / from_channels as usize;
    let mut converted = Vec::with_capacity(frames * to_channels as usize);

    for frame in 0..frames {
        match (from_channels, to_channels) {
            (1, 2) => {
                // Mono to stereo - duplicate the channel
                let sample = samples[frame];
                converted.push(sample);
                converted.push(sample);
            }
            (2, 1) => {
                // Stereo to mono - average the channels
                let left = samples[frame * 2];
                let right = samples[frame * 2 + 1];
                converted.push((left + right) / 2.0);
            }
            (from, to) => {
                // General case - simple downmix/upmix
                for ch in 0..to as usize {
                    if ch < from as usize {
                        converted.push(samples[frame * from as usize + ch]);
                    } else {
                        converted.push(0.0);
                    }
                }
            }
        }
    }

    Ok(converted)
}

/// Load audio file using Symphonia (supports multiple formats)
fn load_with_symphonia(
    path: &Path,
    options: &LoadOptions,
) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
    let file = File::open(path).map_err(|e| AudioIoError::IoError {
        message: format!("Failed to open file: {}", path.display()),
        source: Some(Box::new(e)),
    })?;

    let mss = MediaSourceStream::new(Box::new(file), Default::default());
    let mut hint = Hint::new();

    // Add file extension hint
    if let Some(extension) = path.extension() {
        if let Some(ext_str) = extension.to_str() {
            hint.with_extension(ext_str);
        }
    }

    let meta_opts = MetadataOptions::default();
    let fmt_opts = FormatOptions::default();

    let mut probed = symphonia::default::get_probe()
        .format(&hint, mss, &fmt_opts, &meta_opts)
        .map_err(|e| AudioIoError::IoError {
            message: format!("Symphonia error: {}", e),
            source: Some(Box::new(e)),
        })?;

    let mut format = probed.format;

    // Find the default track
    let track = format
        .tracks()
        .iter()
        .find(|t| t.codec_params.codec != symphonia::core::codecs::CODEC_TYPE_NULL)
        .ok_or_else(|| AudioIoError::IoError {
            message: "No audio track found".to_string(),
            source: None,
        })?;

    let track_id = track.id;
    let codec_params = &track.codec_params;

    // Get basic audio info
    let sample_rate = codec_params.sample_rate.unwrap_or(44100);
    let channels = codec_params.channels.map(|c| c.count()).unwrap_or(2) as u32;

    // Create decoder
    let mut decoder = symphonia::default::get_codecs()
        .make(&codec_params, &Default::default())
        .map_err(|e| AudioIoError::IoError {
            message: format!("Symphonia error: {}", e),
            source: Some(Box::new(e)),
        })?;

    let mut samples = Vec::new();

    // Decode audio
    loop {
        let packet = match format.next_packet() {
            Ok(packet) => packet,
            Err(symphonia::core::errors::Error::ResetRequired) => {
                // Reset decoder
                decoder.reset();
                continue;
            }
            Err(symphonia::core::errors::Error::IoError(e))
                if e.kind() == std::io::ErrorKind::UnexpectedEof =>
            {
                break;
            }
            Err(e) => {
                return Err(AudioIoError::IoError {
                    message: format!("Audio decoding error: {}", e),
                    source: Some(Box::new(e)),
                })
            }
        };

        if packet.track_id() != track_id {
            continue;
        }

        match decoder.decode(&packet) {
            Ok(audio_buffer) => {
                // Convert to f32 samples
                match audio_buffer {
                    AudioBufferRef::F32(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = sample;
                            }
                        }
                    }
                    AudioBufferRef::U8(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = (sample as f32 - 128.0) / 128.0;
                            }
                        }
                    }
                    AudioBufferRef::U16(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = (sample as f32 - 32768.0) / 32768.0;
                            }
                        }
                    }
                    AudioBufferRef::U24(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] =
                                    (sample.inner() as f32 - 8_388_608.0) / 8_388_608.0;
                            }
                        }
                    }
                    AudioBufferRef::U32(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] =
                                    (sample as f32 - 2_147_483_648.0) / 2_147_483_648.0;
                            }
                        }
                    }
                    AudioBufferRef::S8(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = sample as f32 / 128.0;
                            }
                        }
                    }
                    AudioBufferRef::S16(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = sample as f32 / 32768.0;
                            }
                        }
                    }
                    AudioBufferRef::S24(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = sample.inner() as f32 / 8_388_608.0;
                            }
                        }
                    }
                    AudioBufferRef::S32(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = sample as f32 / 2_147_483_648.0;
                            }
                        }
                    }
                    AudioBufferRef::F64(buf) => {
                        for ch in 0..buf.spec().channels.count() {
                            let channel_samples = buf.chan(ch);
                            for (i, &sample) in channel_samples.iter().enumerate() {
                                let sample_index = i * channels as usize + ch;
                                if sample_index >= samples.len() {
                                    samples.resize(sample_index + 1, 0.0);
                                }
                                samples[sample_index] = sample as f32;
                            }
                        }
                    }
                }
            }
            Err(symphonia::core::errors::Error::IoError(e))
                if e.kind() == std::io::ErrorKind::UnexpectedEof =>
            {
                break;
            }
            Err(symphonia::core::errors::Error::DecodeError(_)) => {
                // Skip decode errors
            }
            Err(e) => {
                return Err(AudioIoError::IoError {
                    message: format!("Audio decoding error: {}", e),
                    source: Some(Box::new(e)),
                })
            }
        }
    }

    if samples.is_empty() {
        return Err(AudioIoError::IoError {
            message: "No audio data found".to_string(),
            source: None,
        });
    }

    let duration = samples.len() as f64 / (sample_rate as f64 * channels as f64);

    // Apply target sample rate and channel conversion if needed
    let (final_samples, final_sample_rate, final_channels) =
        apply_audio_conversion(samples, sample_rate, channels, options)?;

    let audio = AudioBuffer::new(final_samples, final_sample_rate, final_channels);

    // Extract metadata
    let metadata =
        if let Some(metadata_rev) = probed.metadata.get().as_ref().and_then(|m| m.current()) {
            let mut meta = AudioMetadata::default();

            for tag in metadata_rev.tags() {
                match tag.key.as_str() {
                    "TITLE" => meta.title = Some(tag.value.to_string()),
                    "ARTIST" => meta.artist = Some(tag.value.to_string()),
                    "ALBUM" => meta.album = Some(tag.value.to_string()),
                    "GENRE" => meta.genre = Some(tag.value.to_string()),
                    "DATE" | "YEAR" => {
                        if let Ok(year) = tag.value.to_string().parse::<u32>() {
                            meta.year = Some(year);
                        }
                    }
                    "TRACKNUMBER" => {
                        if let Ok(track) = tag.value.to_string().parse::<u32>() {
                            meta.track = Some(track);
                        }
                    }
                    _ => {}
                }
            }

            meta.duration = Some(duration);
            meta
        } else {
            AudioMetadata {
                title: path
                    .file_stem()
                    .and_then(|s| s.to_str())
                    .map(|s| s.to_string()),
                duration: Some(duration),
                ..Default::default()
            }
        };

    Ok((audio, metadata))
}

/// Validate audio file using Symphonia
fn validate_with_symphonia(path: &Path) -> bool {
    let file = match File::open(path) {
        Ok(f) => f,
        Err(_) => return false,
    };

    let mss = MediaSourceStream::new(Box::new(file), Default::default());
    let mut hint = Hint::new();

    // Add file extension hint
    if let Some(extension) = path.extension() {
        if let Some(ext_str) = extension.to_str() {
            hint.with_extension(ext_str);
        }
    }

    let meta_opts = MetadataOptions::default();
    let fmt_opts = FormatOptions::default();

    match symphonia::default::get_probe().format(&hint, mss, &fmt_opts, &meta_opts) {
        Ok(probed) => {
            // Check if there's at least one valid audio track
            probed
                .format
                .tracks()
                .iter()
                .any(|t| t.codec_params.codec != symphonia::core::codecs::CODEC_TYPE_NULL)
        }
        Err(_) => false,
    }
}

/// WAV format decoder using hound
pub struct WavDecoder;

impl WavDecoder {
    /// Load WAV file
    pub fn load(path: &Path, options: &LoadOptions) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
        let mut reader = hound::WavReader::open(path).map_err(|e| AudioIoError::IoError {
            message: format!("Symphonia error: {}", e),
            source: Some(Box::new(e)),
        })?;

        let spec = reader.spec();
        let sample_rate = spec.sample_rate;
        let channels = spec.channels as u32;

        // Convert samples to f32
        let samples: Result<Vec<f32>, _> = match spec.sample_format {
            hound::SampleFormat::Float => reader.samples::<f32>().collect(),
            hound::SampleFormat::Int => match spec.bits_per_sample {
                16 => reader
                    .samples::<i16>()
                    .map(|s| s.map(|sample| sample as f32 / 32768.0))
                    .collect(),
                24 => reader
                    .samples::<i32>()
                    .map(|s| s.map(|sample| sample as f32 / 8_388_608.0))
                    .collect(),
                32 => reader
                    .samples::<i32>()
                    .map(|s| s.map(|sample| sample as f32 / 2_147_483_648.0))
                    .collect(),
                _ => {
                    return Err(AudioIoError::UnsupportedFormat {
                        format: AudioFormat::Wav,
                    })
                }
            },
        };

        let samples = samples.map_err(|e| AudioIoError::IoError {
            message: format!("Symphonia error: {}", e),
            source: Some(Box::new(e)),
        })?;

        let duration = samples.len() as f64 / (sample_rate as f64 * channels as f64);

        // Apply target sample rate and channel conversion if needed
        let (final_samples, final_sample_rate, final_channels) =
            apply_audio_conversion(samples, sample_rate, channels, options)?;

        let audio = AudioBuffer::new(final_samples, final_sample_rate, final_channels);
        let metadata = AudioMetadata {
            title: path
                .file_stem()
                .and_then(|s| s.to_str())
                .map(|s| s.to_string()),
            duration: Some(duration),
            ..Default::default()
        };

        Ok((audio, metadata))
    }

    /// Check if file is valid WAV format
    pub fn is_valid_format(path: &Path) -> bool {
        hound::WavReader::open(path).is_ok()
    }
}

/// FLAC format decoder using symphonia
pub struct FlacDecoder;

impl FlacDecoder {
    /// Load FLAC file
    pub fn load(path: &Path, options: &LoadOptions) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
        load_with_symphonia(path, options)
    }

    /// Check if file is valid FLAC format
    pub fn is_valid_format(path: &Path) -> bool {
        validate_with_symphonia(path)
    }
}

/// MP3 format decoder using symphonia
pub struct Mp3Decoder;

impl Mp3Decoder {
    /// Load MP3 file
    pub fn load(path: &Path, options: &LoadOptions) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
        load_with_symphonia(path, options)
    }

    /// Check if file is valid MP3 format
    pub fn is_valid_format(path: &Path) -> bool {
        validate_with_symphonia(path)
    }
}

/// OGG Vorbis format decoder using symphonia
pub struct OggDecoder;

impl OggDecoder {
    /// Load OGG file
    pub fn load(path: &Path, options: &LoadOptions) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
        load_with_symphonia(path, options)
    }

    /// Check if file is valid OGG format
    pub fn is_valid_format(path: &Path) -> bool {
        validate_with_symphonia(path)
    }
}

/// M4A/AAC format decoder using symphonia
pub struct M4aDecoder;

impl M4aDecoder {
    /// Load M4A file
    pub fn load(path: &Path, options: &LoadOptions) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
        load_with_symphonia(path, options)
    }

    /// Check if file is valid M4A format
    pub fn is_valid_format(path: &Path) -> bool {
        validate_with_symphonia(path)
    }
}

/// AIFF format decoder using symphonia
pub struct AiffDecoder;

impl AiffDecoder {
    /// Load AIFF file
    pub fn load(path: &Path, options: &LoadOptions) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
        load_with_symphonia(path, options)
    }

    /// Check if file is valid AIFF format
    pub fn is_valid_format(path: &Path) -> bool {
        validate_with_symphonia(path)
    }
}

/// Universal format loader that dispatches to appropriate decoder
pub fn load_audio_file(
    path: &Path,
    options: &LoadOptions,
) -> AudioIoResult<(AudioBuffer, AudioMetadata)> {
    let format = AudioFormat::from_extension(path);

    match format {
        AudioFormat::Wav => WavDecoder::load(path, options),
        AudioFormat::Flac => FlacDecoder::load(path, options),
        AudioFormat::Mp3 => Mp3Decoder::load(path, options),
        AudioFormat::Ogg => OggDecoder::load(path, options),
        AudioFormat::M4a => M4aDecoder::load(path, options),
        AudioFormat::Aiff => AiffDecoder::load(path, options),
        AudioFormat::Unknown => Err(AudioIoError::UnsupportedFormat { format }),
    }
}

/// Validate that a file can be loaded
pub fn validate_audio_file(path: &Path) -> AudioIoResult<AudioFormat> {
    let format = AudioFormat::from_extension(path);

    let is_valid = match format {
        AudioFormat::Wav => WavDecoder::is_valid_format(path),
        AudioFormat::Flac => FlacDecoder::is_valid_format(path),
        AudioFormat::Mp3 => Mp3Decoder::is_valid_format(path),
        AudioFormat::Ogg => OggDecoder::is_valid_format(path),
        AudioFormat::M4a => M4aDecoder::is_valid_format(path),
        AudioFormat::Aiff => AiffDecoder::is_valid_format(path),
        AudioFormat::Unknown => false,
    };

    if is_valid {
        Ok(format)
    } else {
        Err(AudioIoError::UnsupportedFormat { format })
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::path::PathBuf;

    #[test]
    fn test_wav_decoder() {
        let path = PathBuf::from("test.wav");

        // Skip test if file doesn't exist
        if !path.exists() {
            return;
        }

        let options = LoadOptions::default();
        let result = WavDecoder::load(&path, &options);
        assert!(result.is_ok());

        let (audio, metadata) = result.unwrap();
        assert_eq!(audio.sample_rate(), 16000);
        assert_eq!(audio.channels(), 1);
        assert!(metadata.title.is_some());
    }

    #[test]
    fn test_format_validation() {
        let wav_path = PathBuf::from("test.wav");

        // Only test if file exists
        if wav_path.exists() {
            let result = validate_audio_file(&wav_path);
            assert!(result.is_ok());
            assert_eq!(result.unwrap(), AudioFormat::Wav);
        }

        let unknown_path = PathBuf::from("test.xyz");
        let result = validate_audio_file(&unknown_path);
        assert!(result.is_err());
    }

    #[test]
    fn test_universal_loader() {
        let paths = [
            "test.wav",
            "test.flac",
            "test.mp3",
            "test.ogg",
            "test.m4a",
            "test.aiff",
        ];

        let options = LoadOptions::new().target_sample_rate(16000);

        for path_str in &paths {
            let path = PathBuf::from(path_str);

            // Only test files that exist
            if path.exists() {
                let result = load_audio_file(&path, &options);
                assert!(result.is_ok(), "Failed to load {}", path_str);

                let (audio, _metadata) = result.unwrap();
                assert_eq!(audio.sample_rate(), 16000);
            }
        }
    }

    #[test]
    fn test_metadata_extraction() {
        let path = PathBuf::from("test.mp3");

        // Skip test if file doesn't exist
        if !path.exists() {
            return;
        }

        let options = LoadOptions::default();
        let result = Mp3Decoder::load(&path, &options);
        assert!(result.is_ok());

        let (_audio, metadata) = result.unwrap();
        // Only test basic metadata properties that should be present
        assert!(metadata.title.is_some() || metadata.duration.is_some());
    }
}