Mercurial > hg > may
changeset 86:4e93d8ea1e70
Implement fillFixedSampleRate
author | Chris Cannam |
---|---|
date | Mon, 18 Mar 2013 10:01:50 +0000 |
parents | 718e0e6a9ca3 |
children | bf48110c0efa |
files | test/test_vamppost.yeti vamppost.yeti |
diffstat | 2 files changed, 32 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_vamppost.yeti Mon Mar 18 09:48:34 2013 +0000 +++ b/test/test_vamppost.yeti Mon Mar 18 10:01:50 2013 +0000 @@ -30,19 +30,21 @@ "fillFixedSampleRate": \( // "If the output feature's hasTimestamp field is true, the host - // should read and use the output feature's timestamp [...] If + // should read and use the output feature's timestamp. The host + // may round the timestamp according to the sample rate given in + // the output descriptor's sampleRate field [...] If // [hasTimestamp] is false, its time will be implicitly calculated // by incrementing the time of the previous feature according to // the [output descriptor's] sample rate" filled = vp.fillTimestamps { - output = { sampleType = FixedSampleRate 500 }, + output = { sampleType = FixedSampleRate 5 }, config = { sampleRate = 1000, stepSize = 100 }, features = [ [], [ untimed 1 ], [ untimed 1, untimed 2 ], [], - [ timed 1 1, untimed 2, timed 4 3 ] + [ timed 1.1 1, untimed 2, timed 4 3 ] ] }; compare filled [ @@ -58,7 +60,7 @@ // the plugin to return any features without valid timestamps, // but it isn't the job of fillTimestamps to handle that error filled = vp.fillTimestamps { - output = { sampleType = VariableSampleRate 500 }, + output = { sampleType = VariableSampleRate 5 }, config = { sampleRate = 1000, stepSize = 100 }, features = [ [],
--- a/vamppost.yeti Mon Mar 18 09:48:34 2013 +0000 +++ b/vamppost.yeti Mon Mar 18 10:01:50 2013 +0000 @@ -1,23 +1,36 @@ module vamppost; fillOneSamplePerStep config features = - (stepTime n = (n * config.stepSize) / config.sampleRate; - fillTimestamps' n pending features = + (fill' n pending features = case pending of feature::rest: - (feature with { timestamp = Time (stepTime n) }) - :. \(fillTimestamps' n rest features); - _: - case features of - here::rest: - fillTimestamps' (n+1) here rest; - _: - []; - esac; + stamped = feature with + { timestamp = Time ((n * config.stepSize) / config.sampleRate) }; + stamped :. \(fill' n rest features); + _: + if empty? features then [] + else fill' (n+1) (head features) (tail features); + fi; esac; - fillTimestamps' (-1) [] features); + fill' (-1) [] features); -fillFixedSampleRate config rate features = concat features; +fillFixedSampleRate config rate features = + (eps = 0.0001; + fill' n pending features = + case pending of + feature::rest: + n = case feature.timestamp of + Untimed (): n + 1; + Time t: int (t * rate + eps); + esac; + stamped = feature with { timestamp = Time (n / rate) }; + stamped :. \(fill' n rest features); + _: + if empty? features then [] + else fill' n (head features) (tail features); + fi; + esac; + fill' (-1) [] features); fillTimestamps { output, config, features } = case output.sampleType of