# HG changeset patch # User Chris Cannam # Date 1363600910 0 # Node ID 4e93d8ea1e700854fcef14a08f955ec3f684c2ce # Parent 718e0e6a9ca3a5bcea8a3f7653d7fd63302dd52e Implement fillFixedSampleRate diff -r 718e0e6a9ca3 -r 4e93d8ea1e70 test/test_vamppost.yeti --- 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 = [ [], diff -r 718e0e6a9ca3 -r 4e93d8ea1e70 vamppost.yeti --- 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