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
|
# Commands covered: sound dBPowerSpectrum
#
package require -exact snack 2.0
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
test dbpower-1.1 {dBPowerSpectrum command} {
set s [snack::sound snd -load ex1.wav]
set tcl_precision 5
set res [$s dBPowerSpectrum -start 0 -fftlength 32 -windowlength 32 \
-channel 0 -preemphasisfactor 0.97]
$s destroy
set res
} {-76.131 -82.843 -107.69 -102.82 -101.37 -102.09 -95.375 -95.568 -95.339 -98.854 -101.56 -98.987 -126.39 -106.92 -107.49 -105.77}
test dbpower-1.2 {dBPowerSpectrum command, -end option} {
set s [snack::sound snd -load ex1.wav]
set tcl_precision 5
set res [$s dBPowerSpectrum -start 1000 -end 2000 -fftlength 32 \
-windowlength 32]
$s destroy
set res
} {-44.959 -52.004 -84.505 -93.468 -98.013 -100.0 -99.64 -102.35 -102.39 -102.32 -104.67 -104.66 -105.31 -106.86 -107.17 -112.66}
test dbpower-1.3 {dBPowerSpectrum command, -end and -skip options} {
set s [snack::sound snd -load ex1.wav]
set tcl_precision 5
set res [$s dBPowerSpectrum -start 1000 -end 2000 -skip 10 -fftlength 32 \
-windowlength 32]
$s destroy
set res
} {-44.96 -52.016 -85.245 -92.607 -97.372 -99.939 -100.97 -102.55 -101.93 -101.45 -104.44 -105.91 -107.07 -107.84 -107.57 -110.55}
test dbpower-1.4 {dBPowerSpectrum command, -channel -1} {
set s [snack::sound snd -load ex1.wav]
set tcl_precision 5
set res [$s dBPowerSpectrum -start 0 -end 1 -fftlength 32 -windowlength 32 \
-channel -1]
$s destroy
set res
} {-46.206 -53.295 -86.135 -95.745 -95.521 -98.841 -98.824 -96.341 -98.931 -102.45 -104.78 -104.59 -116.6 -110.38 -115.77 -109.94}
test dbpower-2.1 {dBPowerSpectrum command, bad -fftlength option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -fftlength 33} msg
$s destroy
set msg
} {-fftlength must be one of { 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 }}
test dbpower-2.2 {dBPowerSpectrum command, bad -windowlength option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -windowlength 0} msg
$s destroy
set msg
} {-winlength must be > 0}
test dbpower-2.3 {dBPowerSpectrum command, bad -start option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -start -1} msg
$s destroy
set msg
} {FFT window out of bounds}
test dbpower-2.4 {dBPowerSpectrum command, bad -start option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -start 100000} msg
$s destroy
set msg
} {FFT window out of bounds}
test dbpower-2.5 {dBPowerSpectrum command, bad -end option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -end 100000} msg
$s destroy
set msg
} {FFT window out of bounds}
test dbpower-3.1 {dBPowerSpectrum command, -windowtype option} {
set s [snack::sound snd -load ex1.wav]
set tcl_precision 5
set res [$s dBPowerSpectrum -start 1000 -end 2000 -skip 10 -fftlength 32 \
-windowlength 32 -windowtype hanning]
$s destroy
set res
} {-45.67 -51.291 -84.481 -92.034 -97.201 -99.898 -101.07 -102.59 -102.13 -101.8 -104.24 -106.03 -107.43 -108.14 -108.13 -110.85}
test dbpower-4.1 {dBPowerSpectrum command, bad -end option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -end 100000} msg
$s destroy
set msg
} {FFT window out of bounds}
test dbpower-5.1 {dBPowerSpectrum command, with missing value for -start option} {
set s [snack::sound snd -load ex1.wav]
catch {$s dBPowerSpectrum -start} msg
$s destroy
set msg
} {No argument given for -start option}
# cleanup
::tcltest::cleanupTests
return
|