SampleType » History » Version 50

Chris Cannam, 2014-02-10 05:21 PM

1 1 Chris Cannam
h1. Output Sample Type and Sample Rate
2 1 Chris Cannam
3 15 Chris Cannam
{{>toc}}
4 15 Chris Cannam
5 30 Chris Cannam
h2. Who should read this document
6 29 Chris Cannam
7 30 Chris Cannam
This is a detailed document about the "sample type" and "sample rate" properties of a Vamp plugin's output descriptor.
8 29 Chris Cannam
9 29 Chris Cannam
 * If you are new to the Vamp plugin API, read the "Programmer's Guide":http://vamp-plugins.org/guide.pdf first. The section "Sample Types and Timestamps" starting on page 9 introduces this subject.
10 29 Chris Cannam
11 31 Chris Cannam
 * If you are writing a plugin, read the "Rules of Thumb" section (below) after the Programmer's Guide. You probably won't need to read the rest of this document. You should use the "Vamp Plugin Tester":/projects/vamp-plugin-tester to test your plugin.
12 29 Chris Cannam
13 29 Chris Cannam
 * If you are writing a host, you should probably read the whole of this as well as the Guide. You should also use the "Vamp Test Plugin":/projects/vamp-test-plugin to test your host's interpretation of the feature structures.
14 29 Chris Cannam
15 29 Chris Cannam
h2. Rules of Thumb for Plugin Developers
16 29 Chris Cannam
17 29 Chris Cannam
The tl;dr summary:
18 29 Chris Cannam
19 34 Chris Cannam
 * If your output returns things that are always regularly-spaced in time, and there is one such thing returned for every @process@ block, and the calculation is causal so that results are available immediately, and there is no latency added beyond the length of the processing block, then you probably want to use @OneSamplePerStep@ sample type and omit the feature timestamps.
20 29 Chris Cannam
21 35 Chris Cannam
 * If your output returns things that are regularly-spaced in time but the other limitations above are not true, use @FixedSampleRate@ sample type, set the output sample rate to the (perhaps fractional) number of returned features per second, and use a timestamp for each feature.
22 29 Chris Cannam
23 32 Chris Cannam
 * If your output returns anything else, use @VariableSampleRate@ sample type, set the output sample rate to zero unless you know better, and use a timestamp for each feature.
24 29 Chris Cannam
25 29 Chris Cannam
h2. Introduction
26 29 Chris Cannam
27 12 Chris Cannam
A Vamp plugin receives audio and produces a series of descriptive feature structures.
28 1 Chris Cannam
29 12 Chris Cannam
The audio input is provided as a series of fixed-length sample blocks, equally spaced in time, provided to successive calls to the plugin's @process@ function. The plugin may return any number of features from each @process@ call, and may also return any number of features from @getRemainingFeatures@ after all the audio has been received.
30 11 Chris Cannam
31 11 Chris Cannam
Features are each associated with a particular output of the plugin. The plugin declares that each output has certain properties, which constrain the sort of feature data the host can expect to see. (See diagram.)
32 10 Chris Cannam
33 7 Chris Cannam
!/attachments/download/980/feature-structures-20pc.png!
34 9 Chris Cannam
35 22 Chris Cannam
A feature may or may not have a timestamp (as well as, optionally, a duration). Whether a timestamp is needed -- and, if it is provided, what it means -- are determined by the @sampleType@ and @sampleRate@ properties of the output on which the feature is returned.
36 7 Chris Cannam
37 50 Chris Cannam
An output's @sampleType@ property may be either @OneSamplePerStep@, @FixedSampleRate@, or @VariableSampleRate@. Here's what they mean, in order of complexity.
38 1 Chris Cannam
39 27 Chris Cannam
h2. OneSamplePerStep
40 1 Chris Cannam
41 23 Chris Cannam
This is the simplest option.
42 1 Chris Cannam
43 23 Chris Cannam
If an output is declared as having a @sampleType@ of @OneSamplePerStep@, then any features returned from a @process@ call are assumed to match up with the audio block provided to that @process@ call.
44 23 Chris Cannam
45 14 Chris Cannam
The @sampleRate@ and @hasDuration@ output properties are ignored for outputs of this type.
46 1 Chris Cannam
47 14 Chris Cannam
For any features returned through an output declared with @OneSamplePerStep@ type,
48 14 Chris Cannam
49 24 Chris Cannam
 * The plugin _should not_ set timestamps on these features and _should_ set their @hasTimestamp@ property to @false@;
50 1 Chris Cannam
 * The plugin _should not_ set durations on these features and _should_ set their @hasDuration@ property to @false@;
51 33 Chris Cannam
 * The host _must_ ignore any timestamps or durations that the plugin may set on these features;
52 24 Chris Cannam
 * The host _must_ treat all such features returned from a given @process@ call as if they had the same timestamp as it passed to that @process@ call;
53 1 Chris Cannam
 * The host _must_ treat all such features returned from @getRemainingFeatures@ as if they were immediately following the final @process@ block (i.e. with the same time as the next equally-spaced @process@ block would have had if the input had not ended);
54 22 Chris Cannam
 * The host _must_ treat all such features has having duration equal to the spacing between process blocks.
55 1 Chris Cannam
56 47 Chris Cannam
h3. Handling non-compliant plugins
57 47 Chris Cannam
58 47 Chris Cannam
Not an issue: there is no required behaviour from plugins for features on @OneSamplePerStep@ outputs. The host always ignores any timing information in these features whether present or not.
59 47 Chris Cannam
60 27 Chris Cannam
h3. Examples
61 14 Chris Cannam
62 14 Chris Cannam
@OneSamplePerStep@ is most often used for simple measurements and visualisations, in which some internal calculation is updated on each process call and a new result returned. For example: envelope trackers; power calculations; spectrograms. These outputs are typically visualised using line graphs or colour matrix plots.
63 14 Chris Cannam
64 1 Chris Cannam
@OneSamplePerStep@ is often used for intermediate results calculated during processing of a more sophisticated feature. For example, a beat tracker might have an auxiliary output with @OneSamplePerStep@ type returning its internal onset detection function value.
65 14 Chris Cannam
66 27 Chris Cannam
h2. VariableSampleRate
67 20 Chris Cannam
68 21 Chris Cannam
If the @OneSamplePerStep@ output type essentially means that the plugin leaves all time calculations up to the host, @VariableSampleRate@ is the opposite.
69 22 Chris Cannam
70 1 Chris Cannam
If an output is declared as having a @SampleType@ of @VariableSampleRate@, the features returned through it will have timestamps set by the plugin, and they won't necessarily have any relationship to the process block timestamps provided by the host.
71 1 Chris Cannam
72 27 Chris Cannam
h3. Timestamps
73 25 Chris Cannam
74 1 Chris Cannam
For any features returned through an output declared with @VariableSampleRate@ type,
75 24 Chris Cannam
76 24 Chris Cannam
 * The plugin _must_ set timestamps on these features and _must_ set their @hasTimestamp@ property to @true@;
77 28 Chris Cannam
 * The host _must_ obtain the features' start times from their timestamps rather than calculating them itself.
78 25 Chris Cannam
79 27 Chris Cannam
h3. Durations
80 25 Chris Cannam
81 1 Chris Cannam
Features returned through @VariableSampleRate@ outputs may optionally have durations.
82 25 Chris Cannam
83 26 Chris Cannam
If the output's @hasDuration@ property is @true@, then
84 26 Chris Cannam
85 45 Chris Cannam
 * The plugin _must_ set the @duration@ property of features returned through this output and _must_ set their the @hasDuration@ property to @true@;
86 43 Chris Cannam
 * The host _must_ use the feature's @duration@ property as the feature duration.
87 1 Chris Cannam
88 28 Chris Cannam
If the output's @hasDuration@ property is @false@, then
89 43 Chris Cannam
90 46 Chris Cannam
 * The plugin _should not_ set the @duration@ property of that output's features;
91 46 Chris Cannam
 * The host _must_ ignore the @hasDuration@ and @duration@ properties of the output's features, and treat them as having "minimal" duration (see below).
92 46 Chris Cannam
93 28 Chris Cannam
h3. Sample rate and "minimal" duration
94 28 Chris Cannam
95 28 Chris Cannam
The plugin may optionally set a @sampleRate@ property for each @VariableSampleRate@ output. A @sampleRate@ of zero indicates no value.
96 28 Chris Cannam
97 28 Chris Cannam
If a @sampleRate@ is set,
98 28 Chris Cannam
99 28 Chris Cannam
 * The host _must_ use 1/@sampleRate@ seconds as the "minimal" duration assigned to features that have no duration supplied.
100 1 Chris Cannam
101 37 Chris Cannam
If no @sampleRate@ is set, i.e. if the @sampleRate@ property is zero,
102 1 Chris Cannam
103 1 Chris Cannam
 * The host _must_ use zero as the "minimal" duration used for features with no duration supplied.
104 1 Chris Cannam
105 47 Chris Cannam
h3. Handling non-compliant plugins
106 47 Chris Cannam
107 47 Chris Cannam
If a feature returned through a @VariableSampleRate@ output has @hasTimestamp@ set to @false@, the host should ignore that feature entirely rather than attempt to read (or guess) its timestamp.
108 47 Chris Cannam
109 47 Chris Cannam
If a feature's @hasDuration@ value does not match the output's @hasDuration@ value, the host should assign the feature "minimal" duration.
110 47 Chris Cannam
111 1 Chris Cannam
h2. FixedSampleRate
112 1 Chris Cannam
113 49 Chris Cannam
This is a more complex case than @OneSamplePerStep@ or @VariableSampleRate@.
114 49 Chris Cannam
115 49 Chris Cannam
A @OneSamplePerStep@ output never uses individual feature timestamps; a @VariableSampleRate@ output always uses them; a @FixedSampleRate@ output sometimes does.
116 37 Chris Cannam
117 1 Chris Cannam
h3. Timestamps
118 1 Chris Cannam
119 39 Chris Cannam
An output with @FixedSampleRate@ type _must_ also have a non-zero @sampleRate@ property.
120 1 Chris Cannam
121 43 Chris Cannam
Conceptually the @sampleRate@ property defines a set of discrete sample times, spaced at @sampleRate@ points per second, starting at time zero. Every returned feature must start at one of these times, whether the time is calculated and assigned by the plugin (through the timestamp of the feature) or by the host (for features without timestamps).
122 1 Chris Cannam
123 39 Chris Cannam
For any features returned through an output declared with @FixedSampleRate@ type,
124 39 Chris Cannam
125 40 Chris Cannam
 * The plugin _may_ set timestamps on these features, and it _must_ set the feature's corresponding @hasTimestamp@ property to @true@ or @false@ depending on whether it has set a timestamp;
126 39 Chris Cannam
 * Where a feature has a timestamp, the host _must_ take that timestamp, round it to the nearest 1/@sampleRate@ seconds, and use that as the time of the feature;
127 42 Chris Cannam
 * Where a feature has no timestamp, the host _must_ take the time of the previous feature, add 1/@sampleRate@ seconds to it, and use that as the time of the new feature;
128 1 Chris Cannam
 * Where the very first feature has no timestamp, the host _must_ take its time as zero.
129 43 Chris Cannam
130 43 Chris Cannam
The "Programmer's Guide":http://vamp-plugins.org/guide.pdf leaves this behaviour incompletely defined, saying "The host may round the timestamp according to the sample rate given in the output descriptor's sampleRate field". Here we are declaring that the host _must_ round the timestamp in this way. Note that the "Vamp Test Plugin":/projects/vamp-test-plugin/wiki assumes this behaviour.
131 43 Chris Cannam
132 43 Chris Cannam
h3. Durations
133 1 Chris Cannam
134 1 Chris Cannam
Features returned through @FixedSampleRate@ outputs may optionally have durations.
135 43 Chris Cannam
136 43 Chris Cannam
If the output's @hasDuration@ property is @true@, then
137 43 Chris Cannam
138 47 Chris Cannam
 * The plugin _must_ set the @duration@ property of features returned through this output and _must_ set their the @hasDuration@ property to @true@;
139 47 Chris Cannam
 * The host _must_ take the value of the feature's @duration@ property, round it to the nearest 1/@sampleRate@ seconds, and use that as the feature duration.
140 1 Chris Cannam
141 43 Chris Cannam
If the output's @hasDuration@ property is @false@, then
142 1 Chris Cannam
143 1 Chris Cannam
 * The plugin _should not_ set the @duration@ property of that output's features;
144 47 Chris Cannam
 * The host _must_ ignore the @hasDuration@ and @duration@ properties of the output's features, giving the features a duration of zero.
145 1 Chris Cannam
146 1 Chris Cannam
h3. Handling non-compliant plugins
147 47 Chris Cannam
148 48 Chris Cannam
If a @FixedSampleRate@ feature's @hasDuration@ value does not match its output's @hasDuration@ value, the host should assign the feature a duration of zero.
149 47 Chris Cannam
150 48 Chris Cannam
h3. Examples