diff options
| author | Eskil Q <eskilq@kth.se> | 2020-12-25 00:47:52 +0100 |
|---|---|---|
| committer | Eskil Q <eskilq@kth.se> | 2020-12-25 00:47:52 +0100 |
| commit | b9ac36af4059a9c48288c6e9c252b2cbacd4c0d5 (patch) | |
| tree | 24c180d1163c6d74601caa775e7a1268ea4f8d0a /mumd/src/audio.rs | |
| parent | 58947a7a3acaa1ae04887723643a49db76479f00 (diff) | |
| download | mum-b9ac36af4059a9c48288c6e9c252b2cbacd4c0d5.tar.gz | |
solve pitch bug
Diffstat (limited to 'mumd/src/audio.rs')
| -rw-r--r-- | mumd/src/audio.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 812bb4c..b578256 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -231,12 +231,18 @@ impl Audio { .map(|e| cpal::Sample::to_f32(&e.unwrap())) .collect::<Vec<_>>(), }; - let mut signal = signal::from_iter(samples.iter().cloned()); + let iter: Box<dyn Iterator<Item = f32>> = match spec.channels { + 1 => Box::new(samples.into_iter().flat_map(|e| vec![e, e])), + 2 => Box::new(samples.into_iter()), + _ => unimplemented!() // TODO handle gracefully (this might not even happen) + }; + let mut signal = signal::from_interleaved_samples_iter::<_, [f32; 2]>(iter); let interp = Linear::new(signal.next(), signal.next()); let samples = signal .from_hz_to_hz(interp, spec.sample_rate as f64, SAMPLE_RATE as f64) .until_exhausted() - .collect::<Vec<_>>(); + .flat_map(|e| if output_config.channels == 1 { vec![e[0]] } else { e.to_vec() }) + .collect::<Vec<f32>>(); (*event, samples) }) .collect(); |
