HexoDSP/tests/quant.rs

148 lines
3.9 KiB
Rust
Raw Normal View History

// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
// See README.md and COPYING for details.
mod common;
use common::*;
use hexodsp::dsp::helpers::Quantizer;
use hexodsp::d_pit;
#[test]
fn check_quant_pos_neg_exact() {
let mut q = Quantizer::new();
q.set_keys(0x0);
let v =
(0..=12).map(|i|
2021-08-28 09:04:28 +00:00
d_pit!(
q.process(
i as f32 * (0.1 / 12.0)))
).collect::<Vec<f32>>();
assert_vec_feq!(v, vec![
440.0,
2021-08-28 09:04:28 +00:00
466.1638,
493.8833,
523.2511,
554.3653,
587.3295,
622.25397,
659.2551,
698.4565,
739.98883,
783.9909,
830.6094,
880.0
]);
let v =
(0..=12).map(|i|
d_pit!(q.process(i as f32 * (-0.1 / 12.0)))
).collect::<Vec<f32>>();
assert_vec_feq!(v, vec![
440.0,
415.3047,
391.99542,
369.99442,
349.22824,
329.62756,
311.12698,
293.66476,
277.18265,
261.62555,
246.94165,
233.08186,
220.0
]);
}
#[test]
fn check_quant_precise_01_range() {
let mut q = Quantizer::new();
q.set_keys(0x0);
let v =
(0..=48).map(|i|
d_pit!(
q.process(
i as f32 * ((0.1 * 0.25) / 12.0)))
).collect::<Vec<f32>>();
assert_vec_feq!(v, vec![
440.0,
466.1638, 466.1638, 466.1638, 466.1638,
493.8833, 493.8833, 493.8833, 493.8833,
523.2511, 523.2511, 523.2511, 523.2511,
554.3653, 554.3653, 554.3653, 554.3653,
587.3295, 587.3295, 587.3295, 587.3295,
622.25397, 622.25397, 622.25397, 622.25397,
659.2551, 659.2551, 659.2551, 659.2551,
698.4565, 698.4565, 698.4565, 698.4565,
739.98883, 739.98883, 739.98883, 739.98883,
783.9909, 783.9909, 783.9909, 783.9909,
830.6094, 830.6094, 830.6094, 830.6094,
880.0, 880.0, 880.0, 880.0
]);
}
#[test]
fn check_quant_neg_pos_range() {
let mut q = Quantizer::new();
q.set_keys(0x0);
let v =
(0..=48).map(|i| {
let i = i - 24;
d_pit!(
q.process(
i as f32 * ((0.1 * 0.25) / 12.0)))
}).collect::<Vec<f32>>();
assert_vec_feq!(v, vec![
311.12698, 311.12698,
329.62756, 329.62756, 329.62756, 329.62756,
349.22824, 349.22824, 349.22824, 349.22824,
369.99442, 369.99442, 369.99442, 369.99442,
391.99542, 391.99542, 391.99542, 391.99542,
415.3047, 415.3047, 415.3047, 415.3047,
440.0, 440.0, 440.0,
466.1638, 466.1638, 466.1638, 466.1638,
493.8833, 493.8833, 493.8833, 493.8833,
523.2511, 523.2511, 523.2511, 523.2511,
554.3653, 554.3653, 554.3653, 554.3653,
587.3295, 587.3295, 587.3295, 587.3295,
622.25397, 622.25397, 622.25397, 622.25397
]);
}
#[test]
fn check_quant_edge_oct_offs() {
let mut q = Quantizer::new();
q.set_keys(0b1001_0000_0000);
let v =
(0..=24).map(|i| {
d_pit!(
q.process(
i as f32 * ((0.1 * 0.5) / 12.0)))
}).collect::<Vec<f32>>();
assert_vec_feq!(v, vec![
311.12698, 311.12698,
329.62756, 329.62756, 329.62756, 329.62756,
349.22824, 349.22824, 349.22824, 349.22824,
369.99442, 369.99442, 369.99442, 369.99442,
391.99542, 391.99542, 391.99542, 391.99542,
415.3047, 415.3047, 415.3047, 415.3047,
440.0, 440.0, 440.0,
466.1638, 466.1638, 466.1638, 466.1638,
493.8833, 493.8833, 493.8833, 493.8833,
523.2511, 523.2511, 523.2511, 523.2511,
554.3653, 554.3653, 554.3653, 554.3653,
587.3295, 587.3295, 587.3295, 587.3295,
622.25397, 622.25397, 622.25397, 622.25397
]);
}