diff options
| author | Kapten Z∅∅m <55669224+default-username-852@users.noreply.github.com> | 2020-12-25 22:01:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-25 22:01:58 +0100 |
| commit | 4db4520ce2da54f0974e758bf3e001f1605154ed (patch) | |
| tree | e9c2c23a66019dd43767b1434ac7e5bfeda2a79e /mumd | |
| parent | 4ffcc76813b0c4fd88ec587e6bef55466c9066c6 (diff) | |
| parent | 68e5f1d39e6a1e7216ffb3574ca48627f8fca294 (diff) | |
| download | mum-4db4520ce2da54f0974e758bf3e001f1605154ed.tar.gz | |
Merge pull request #36 from sornas/pitch-bug
Solve pitch bug
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/src/audio.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 812bb4c..8f9e2ab 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -231,12 +231,19 @@ 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<_>>(); + // if the source audio is stereo and is being played as mono, discard the right audio + .flat_map(|e| if output_config.channels == 1 { vec![e[0]] } else { e.to_vec() }) + .collect::<Vec<f32>>(); (*event, samples) }) .collect(); |
