]>
| Commit | Line | Data |
|---|---|---|
| 1 | #!/usr/bin/perl | |
| 2 | use strict; | |
| 3 | use warnings; | |
| 4 | use constant EPSILON => 0.1; | |
| 5 | ||
| 6 | use Test::More tests => 7; | |
| 7 | BEGIN { use_ok('Audio::LibSampleRate') }; | |
| 8 | ||
| 9 | sub isf { | |
| 10 | my ($xx, $yy, $name) = @_; | |
| 11 | for (0 .. $#{$xx}) { | |
| 12 | my ($x, $y) = ($xx->[$_], $yy->[$_]); | |
| 13 | do { diag "$x != $y"; return fail $name } if abs ($x - $y) > EPSILON; | |
| 14 | } | |
| 15 | pass $name; | |
| 16 | } | |
| 17 | ||
| 18 | isf [src_simple([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6], 2)], [1.1, 1.1, 1.7, 1.7, 1.9, 1.9, 2.2, 2.2, 3.1, 3.1, 3.8, 3.8], 'src_simple doubling'; | |
| 19 | isf [src_simple([1..10], 1/2, SRC_LINEAR, 1)], [1, 2, 4, 6, 8], 'src_simple halving'; | |
| 20 | ||
| 21 | my @out; | |
| 22 | my $src = Audio::LibSampleRate->new(SRC_ZERO_ORDER_HOLD, 1); | |
| 23 | @out = ($src->process([1.. 5], 1/2), $src->process([6..10], 2, 1)); | |
| 24 | isf \@out, [1, 2, 4, 6, 8, 9], 'process, smooth transition'; | |
| 25 | ||
| 26 | $src->reset; | |
| 27 | @out = $src->process([1..5], 1/2); | |
| 28 | $src->set_ratio(2); | |
| 29 | push @out, $src->process([6..10], 2, 1); | |
| 30 | isf \@out, [1, 2, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10], 'process, step transition'; | |
| 31 | ||
| 32 | is src_get_name(SRC_SINC_FASTEST), 'Fastest Sinc Interpolator', 'src_get_name'; | |
| 33 | like src_get_description(SRC_SINC_FASTEST), qr/band limited sinc interpolation/i, 'src_get_description'; |