Revision 225:8e04d298741b
| TODO | ||
|---|---|---|
| 1 |
audiofile read tests |
|
| 2 |
feature tests - specdiff |
|
| 3 |
simplify packages |
|
| 4 |
resampling stream |
|
| 5 |
recording stream (javasound) -- how to interrupt record/playback? |
|
| 6 |
name! |
|
| yetilab/feature/feature.yeti | ||
|---|---|---|
| 1 |
|
|
| 2 |
module yetilab.feature.feature; |
|
| 3 |
|
|
| 4 |
vec = load yetilab.vector.vector; |
|
| 5 |
fr = load yetilab.stream.framer; |
|
| 6 |
|
|
| 7 |
// Utility functions for feature extractors |
|
| 8 |
|
|
| 9 |
magdiff frame1 frame2 = |
|
| 10 |
sum (map2 do a b: abs(a - b) done (vec.list frame1) (vec.list frame2)); |
|
| 11 |
|
|
| 12 |
emptyFrameFor frames = |
|
| 13 |
vec.zeros |
|
| 14 |
if empty? frames then 0 |
|
| 15 |
else vec.length (head frames) |
|
| 16 |
fi; |
|
| 17 |
|
|
| 18 |
features featureFunc frames = |
|
| 19 |
(featuresOf prev frames = |
|
| 20 |
case frames of |
|
| 21 |
frame::rest: featureFunc prev frame :. \(featuresOf frame rest); |
|
| 22 |
_: []; |
|
| 23 |
esac; |
|
| 24 |
featuresOf (emptyFrameFor frames) frames); |
|
| 25 |
|
|
| 26 |
{ magdiff, emptyFrameFor, features };
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| yetilab/feature/features.yeti | ||
|---|---|---|
| 1 |
|
|
| 2 |
module yetilab.feature.features; |
|
| 3 |
|
|
| 4 |
vec = load yetilab.vector.vector; |
|
| 5 |
cplx = load yetilab.vector.complex; |
|
| 6 |
fr = load yetilab.stream.framer; |
|
| 7 |
|
|
| 8 |
magdiff frame1 frame2 = |
|
| 9 |
sum (map2 do a b: abs(a - b) done (vec.list frame1) (vec.list frame2)); |
|
| 10 |
|
|
| 11 |
emptyFrameFor frames = |
|
| 12 |
vec.zeros |
|
| 13 |
if empty? frames then 0 |
|
| 14 |
else vec.length (head frames) |
|
| 15 |
fi; |
|
| 16 |
|
|
| 17 |
features featureFunc frames = |
|
| 18 |
(featuresOf prev frames = |
|
| 19 |
case frames of |
|
| 20 |
frame::rest: featureFunc prev frame :. \(featuresOf frame rest); |
|
| 21 |
_: []; |
|
| 22 |
esac; |
|
| 23 |
featuresOf (emptyFrameFor frames) frames); |
|
| 24 |
|
|
| 25 |
specdiff frames = |
|
| 26 |
features magdiff (map cplx.magnitudes frames); |
|
| 27 |
|
|
| 28 |
specdiffOfFile parameters filename = |
|
| 29 |
specdiff (fr.frequencyDomainFramesOfFile parameters filename); |
|
| 30 |
|
|
| 31 |
{
|
|
| 32 |
specdiff, |
|
| 33 |
specdiffOfFile, |
|
| 34 |
} |
|
| 35 |
|
|
| yetilab/feature/specdiff.yeti | ||
|---|---|---|
| 1 |
|
|
| 2 |
module yetilab.feature.specdiff; |
|
| 3 |
|
|
| 4 |
vec = load yetilab.vector.vector; |
|
| 5 |
fr = load yetilab.stream.framer; |
|
| 6 |
cplx = load yetilab.vector.complex; |
|
| 7 |
|
|
| 8 |
load yetilab.feature.feature; |
|
| 9 |
|
|
| 10 |
specdiff frames = |
|
| 11 |
features magdiff (map cplx.magnitudes frames); |
|
| 12 |
|
|
| 13 |
specdiffOfFile parameters filename = |
|
| 14 |
specdiff (fr.frequencyDomainFramesOfFile parameters filename); |
|
| 15 |
|
|
| 16 |
{
|
|
| 17 |
specdiff, |
|
| 18 |
specdiffOfFile, |
|
| 19 |
} |
|
| 20 |
|
|
| yetilab/feature/test/test_features.yeti | ||
|---|---|---|
| 1 |
|
|
| yetilab/stream/test/audiofile_reference.yeti | ||
|---|---|---|
| 5 | 5 |
filt = load yetilab.stream.filter; |
| 6 | 6 |
vec = load yetilab.vector.vector; |
| 7 | 7 |
|
| 8 |
//!!! docs from turbot |
|
| 9 |
|
|
| 8 | 10 |
pulseChannel rate = |
| 9 | 11 |
(pulseFreq = 2; |
| 10 | 12 |
pulseWidth = 0.01 * rate; |
| ... | ... | |
| 24 | 26 |
syn.sinusoid rate 600 :: pulseChannel rate :: leftovers rate 2); |
| 25 | 27 |
|
| 26 | 28 |
afReference rate channels = |
| 27 |
filt.multiplexed (take channels (referenceChannels rate)); |
|
| 29 |
filt.withDuration (2 * rate) |
|
| 30 |
(filt.multiplexed (take channels (referenceChannels rate))); |
|
| 28 | 31 |
|
| 29 | 32 |
{
|
| 30 | 33 |
afReference |
| yetilab/stream/test/test_audiofile.yeti | ||
|---|---|---|
| 5 | 5 |
vec = load yetilab.vector.vector; |
| 6 | 6 |
mat = load yetilab.matrix.matrix; |
| 7 | 7 |
|
| 8 |
{ compare } = load yetilab.test.test;
|
|
| 8 |
ref = load yetilab.stream.test.audiofile_reference; |
|
| 9 |
|
|
| 10 |
{ compare, compareUsing } = load yetilab.test.test;
|
|
| 9 | 11 |
|
| 10 | 12 |
testfile name = "yetilab/test/data/\(name).wav"; |
| 11 | 13 |
|
| ... | ... | |
| 15 | 17 |
arr[0] := n; |
| 16 | 18 |
arr[0]); |
| 17 | 19 |
|
| 20 |
readAll stream = |
|
| 21 |
case stream.available of |
|
| 22 |
Known n: stream.read n; |
|
| 23 |
_: failWith "Known-duration stream required"; |
|
| 24 |
esac; |
|
| 25 |
|
|
| 26 |
testReferenceFile rate channels bitdepth = |
|
| 27 |
(test = readAll (af.open (testfile "\(rate)-\(channels)-\(bitdepth)")); |
|
| 28 |
ref = readAll (ref.afReference rate channels); |
|
| 29 |
compareUsing mat.equal test ref); |
|
| 30 |
|
|
| 18 | 31 |
[ |
| 19 | 32 |
|
| 20 | 33 |
"20samples-open": \( |
| ... | ... | |
| 41 | 54 |
done [ af.open, af.openMono ]); |
| 42 | 55 |
), |
| 43 | 56 |
|
| 57 |
"8000-1-8": \( |
|
| 58 |
testReferenceFile 8000 1 8; |
|
| 59 |
), |
|
| 60 |
|
|
| 61 |
"44100-2-16": \( |
|
| 62 |
testReferenceFile 44100 2 16; |
|
| 63 |
), |
|
| 64 |
|
|
| 44 | 65 |
] is hash<string, () -> boolean> |
| 45 | 66 |
|
Also available in: Unified diff