Mercurial > hg > may
changeset 225:8e04d298741b
More on audiofile reference tests
author | Chris Cannam |
---|---|
date | Sun, 12 May 2013 13:31:49 +0100 |
parents | 1cfa054e3077 |
children | c00d8f7e2708 |
files | TODO yetilab/feature/feature.yeti yetilab/feature/features.yeti yetilab/feature/specdiff.yeti yetilab/feature/test/test_features.yeti yetilab/stream/test/audiofile_reference.yeti yetilab/stream/test/test_audiofile.yeti |
diffstat | 7 files changed, 82 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TODO Sun May 12 13:31:49 2013 +0100 @@ -0,0 +1,6 @@ +audiofile read tests +feature tests - specdiff +simplify packages +resampling stream +recording stream (javasound) -- how to interrupt record/playback? +name!
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/feature/feature.yeti Sun May 12 13:31:49 2013 +0100 @@ -0,0 +1,29 @@ + +module yetilab.feature.feature; + +vec = load yetilab.vector.vector; +fr = load yetilab.stream.framer; + +// Utility functions for feature extractors + +magdiff frame1 frame2 = + sum (map2 do a b: abs(a - b) done (vec.list frame1) (vec.list frame2)); + +emptyFrameFor frames = + vec.zeros + if empty? frames then 0 + else vec.length (head frames) + fi; + +features featureFunc frames = + (featuresOf prev frames = + case frames of + frame::rest: featureFunc prev frame :. \(featuresOf frame rest); + _: []; + esac; + featuresOf (emptyFrameFor frames) frames); + +{ magdiff, emptyFrameFor, features }; + + +
--- a/yetilab/feature/features.yeti Sat May 11 16:29:30 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ - -module yetilab.feature.features; - -vec = load yetilab.vector.vector; -cplx = load yetilab.vector.complex; -fr = load yetilab.stream.framer; - -magdiff frame1 frame2 = - sum (map2 do a b: abs(a - b) done (vec.list frame1) (vec.list frame2)); - -emptyFrameFor frames = - vec.zeros - if empty? frames then 0 - else vec.length (head frames) - fi; - -features featureFunc frames = - (featuresOf prev frames = - case frames of - frame::rest: featureFunc prev frame :. \(featuresOf frame rest); - _: []; - esac; - featuresOf (emptyFrameFor frames) frames); - -specdiff frames = - features magdiff (map cplx.magnitudes frames); - -specdiffOfFile parameters filename = - specdiff (fr.frequencyDomainFramesOfFile parameters filename); - -{ - specdiff, - specdiffOfFile, -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/feature/specdiff.yeti Sun May 12 13:31:49 2013 +0100 @@ -0,0 +1,20 @@ + +module yetilab.feature.specdiff; + +vec = load yetilab.vector.vector; +fr = load yetilab.stream.framer; +cplx = load yetilab.vector.complex; + +load yetilab.feature.feature; + +specdiff frames = + features magdiff (map cplx.magnitudes frames); + +specdiffOfFile parameters filename = + specdiff (fr.frequencyDomainFramesOfFile parameters filename); + +{ + specdiff, + specdiffOfFile, +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/feature/test/test_features.yeti Sun May 12 13:31:49 2013 +0100 @@ -0,0 +1,1 @@ +
--- a/yetilab/stream/test/audiofile_reference.yeti Sat May 11 16:29:30 2013 +0100 +++ b/yetilab/stream/test/audiofile_reference.yeti Sun May 12 13:31:49 2013 +0100 @@ -5,6 +5,8 @@ filt = load yetilab.stream.filter; vec = load yetilab.vector.vector; +//!!! docs from turbot + pulseChannel rate = (pulseFreq = 2; pulseWidth = 0.01 * rate; @@ -24,7 +26,8 @@ syn.sinusoid rate 600 :: pulseChannel rate :: leftovers rate 2); afReference rate channels = - filt.multiplexed (take channels (referenceChannels rate)); + filt.withDuration (2 * rate) + (filt.multiplexed (take channels (referenceChannels rate))); { afReference
--- a/yetilab/stream/test/test_audiofile.yeti Sat May 11 16:29:30 2013 +0100 +++ b/yetilab/stream/test/test_audiofile.yeti Sun May 12 13:31:49 2013 +0100 @@ -5,7 +5,9 @@ vec = load yetilab.vector.vector; mat = load yetilab.matrix.matrix; -{ compare } = load yetilab.test.test; +ref = load yetilab.stream.test.audiofile_reference; + +{ compare, compareUsing } = load yetilab.test.test; testfile name = "yetilab/test/data/\(name).wav"; @@ -15,6 +17,17 @@ arr[0] := n; arr[0]); +readAll stream = + case stream.available of + Known n: stream.read n; + _: failWith "Known-duration stream required"; + esac; + +testReferenceFile rate channels bitdepth = + (test = readAll (af.open (testfile "\(rate)-\(channels)-\(bitdepth)")); + ref = readAll (ref.afReference rate channels); + compareUsing mat.equal test ref); + [ "20samples-open": \( @@ -41,5 +54,13 @@ done [ af.open, af.openMono ]); ), +"8000-1-8": \( + testReferenceFile 8000 1 8; +), + +"44100-2-16": \( + testReferenceFile 44100 2 16; +), + ] is hash<string, () -> boolean>