annotate src/vamp-plugin-sdk-2.5/vamp-hostsdk/PluginSummarisingAdapter.h @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents
children
rev   line source
Chris@23 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@23 2
Chris@23 3 /*
Chris@23 4 Vamp
Chris@23 5
Chris@23 6 An API for audio analysis and feature extraction plugins.
Chris@23 7
Chris@23 8 Centre for Digital Music, Queen Mary, University of London.
Chris@23 9 Copyright 2006-2009 Chris Cannam and QMUL.
Chris@23 10
Chris@23 11 Permission is hereby granted, free of charge, to any person
Chris@23 12 obtaining a copy of this software and associated documentation
Chris@23 13 files (the "Software"), to deal in the Software without
Chris@23 14 restriction, including without limitation the rights to use, copy,
Chris@23 15 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@23 16 of the Software, and to permit persons to whom the Software is
Chris@23 17 furnished to do so, subject to the following conditions:
Chris@23 18
Chris@23 19 The above copyright notice and this permission notice shall be
Chris@23 20 included in all copies or substantial portions of the Software.
Chris@23 21
Chris@23 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@23 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@23 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@23 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@23 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@23 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@23 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@23 29
Chris@23 30 Except as contained in this notice, the names of the Centre for
Chris@23 31 Digital Music; Queen Mary, University of London; and Chris Cannam
Chris@23 32 shall not be used in advertising or otherwise to promote the sale,
Chris@23 33 use or other dealings in this Software without prior written
Chris@23 34 authorization.
Chris@23 35 */
Chris@23 36
Chris@23 37 #ifndef _VAMP_PLUGIN_SUMMARISING_ADAPTER_H_
Chris@23 38 #define _VAMP_PLUGIN_SUMMARISING_ADAPTER_H_
Chris@23 39
Chris@23 40 #include "hostguard.h"
Chris@23 41 #include "PluginWrapper.h"
Chris@23 42
Chris@23 43 #include <set>
Chris@23 44
Chris@23 45 _VAMP_SDK_HOSTSPACE_BEGIN(PluginSummarisingAdapter.h)
Chris@23 46
Chris@23 47 namespace Vamp {
Chris@23 48
Chris@23 49 namespace HostExt {
Chris@23 50
Chris@23 51 /**
Chris@23 52 * \class PluginSummarisingAdapter PluginSummarisingAdapter.h <vamp-hostsdk/PluginSummarisingAdapter.h>
Chris@23 53 *
Chris@23 54 * PluginSummarisingAdapter is a Vamp plugin adapter that provides
Chris@23 55 * summarisation methods such as mean and median averages of output
Chris@23 56 * features, for use in any context where an available plugin produces
Chris@23 57 * individual values but the result that is actually needed is some
Chris@23 58 * sort of aggregate.
Chris@23 59 *
Chris@23 60 * To make use of PluginSummarisingAdapter, the host should configure,
Chris@23 61 * initialise and run the plugin through the adapter interface just as
Chris@23 62 * normal. Then, after the process and getRemainingFeatures methods
Chris@23 63 * have been properly called and processing is complete, the host may
Chris@23 64 * call getSummaryForOutput or getSummaryForAllOutputs to obtain
Chris@23 65 * summarised features: averages, maximum values, etc, depending on
Chris@23 66 * the SummaryType passed to the function.
Chris@23 67 *
Chris@23 68 * By default PluginSummarisingAdapter calculates a single summary of
Chris@23 69 * each output's feature across the whole duration of processed audio.
Chris@23 70 * A host needing summaries of sub-segments of the whole audio may
Chris@23 71 * call setSummarySegmentBoundaries before retrieving the summaries,
Chris@23 72 * providing a list of times such that one summary will be provided
Chris@23 73 * for each segment between two consecutive times.
Chris@23 74 *
Chris@23 75 * PluginSummarisingAdapter is straightforward rather than fast. It
Chris@23 76 * calculates all of the summary types for all outputs always, and
Chris@23 77 * then returns only the ones that are requested. It is designed on
Chris@23 78 * the basis that, for most features, summarising and storing
Chris@23 79 * summarised results is far cheaper than calculating the results in
Chris@23 80 * the first place. If this is not true for your particular feature,
Chris@23 81 * PluginSummarisingAdapter may not be the best approach for you.
Chris@23 82 *
Chris@23 83 * \note This class was introduced in version 2.0 of the Vamp plugin SDK.
Chris@23 84 */
Chris@23 85
Chris@23 86 class PluginSummarisingAdapter : public PluginWrapper
Chris@23 87 {
Chris@23 88 public:
Chris@23 89 /**
Chris@23 90 * Construct a PluginSummarisingAdapter wrapping the given plugin.
Chris@23 91 * The adapter takes ownership of the plugin, which will be
Chris@23 92 * deleted when the adapter is deleted.
Chris@23 93 */
Chris@23 94 PluginSummarisingAdapter(Plugin *plugin);
Chris@23 95 virtual ~PluginSummarisingAdapter();
Chris@23 96
Chris@23 97 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
Chris@23 98
Chris@23 99 void reset();
Chris@23 100
Chris@23 101 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
Chris@23 102 FeatureSet getRemainingFeatures();
Chris@23 103
Chris@23 104 typedef std::set<RealTime> SegmentBoundaries;
Chris@23 105
Chris@23 106 /**
Chris@23 107 * Specify a series of segment boundaries, such that one summary
Chris@23 108 * will be returned for each of the contiguous intra-boundary
Chris@23 109 * segments. This function must be called before
Chris@23 110 * getSummaryForOutput or getSummaryForAllOutputs.
Chris@23 111 *
Chris@23 112 * Note that you cannot retrieve results with multiple different
Chris@23 113 * segmentations by repeatedly calling this function followed by
Chris@23 114 * one of the getSummary functions. The summaries are all
Chris@23 115 * calculated at the first call to any getSummary function, and
Chris@23 116 * once the summaries have been calculated, they remain
Chris@23 117 * calculated.
Chris@23 118 */
Chris@23 119 void setSummarySegmentBoundaries(const SegmentBoundaries &);
Chris@23 120
Chris@23 121 enum SummaryType {
Chris@23 122 Minimum = 0,
Chris@23 123 Maximum = 1,
Chris@23 124 Mean = 2,
Chris@23 125 Median = 3,
Chris@23 126 Mode = 4,
Chris@23 127 Sum = 5,
Chris@23 128 Variance = 6,
Chris@23 129 StandardDeviation = 7,
Chris@23 130 Count = 8,
Chris@23 131
Chris@23 132 UnknownSummaryType = 999
Chris@23 133 };
Chris@23 134
Chris@23 135 /**
Chris@23 136 * AveragingMethod indicates how the adapter should handle
Chris@23 137 * average-based summaries of features whose results are not
Chris@23 138 * equally spaced in time.
Chris@23 139 *
Chris@23 140 * If SampleAverage is specified, summary types based on averages
Chris@23 141 * will be calculated by treating each result individually without
Chris@23 142 * regard to its time: for example, the mean will be the sum of
Chris@23 143 * all values divided by the number of values.
Chris@23 144 *
Chris@23 145 * If ContinuousTimeAverage is specified, each feature will be
Chris@23 146 * considered to have a duration, either as specified in the
Chris@23 147 * feature's duration field, or until the following feature: thus,
Chris@23 148 * for example, the mean will be the sum of the products of values
Chris@23 149 * and durations, divided by the total duration.
Chris@23 150 *
Chris@23 151 * Although SampleAverage is useful for many types of feature,
Chris@23 152 * ContinuousTimeAverage is essential for some situations, for
Chris@23 153 * example finding the result that spans the largest proportion of
Chris@23 154 * the input given a feature that emits a new result only when the
Chris@23 155 * value changes (the modal value integrated over time).
Chris@23 156 */
Chris@23 157 enum AveragingMethod {
Chris@23 158 SampleAverage = 0,
Chris@23 159 ContinuousTimeAverage = 1
Chris@23 160 };
Chris@23 161
Chris@23 162 /**
Chris@23 163 * Return summaries of the features that were returned on the
Chris@23 164 * given output, using the given SummaryType and AveragingMethod.
Chris@23 165 *
Chris@23 166 * The plugin must have been fully run (process() and
Chris@23 167 * getRemainingFeatures() calls all made as appropriate) before
Chris@23 168 * this function is called.
Chris@23 169 */
Chris@23 170 FeatureList getSummaryForOutput(int output,
Chris@23 171 SummaryType type,
Chris@23 172 AveragingMethod method = SampleAverage);
Chris@23 173
Chris@23 174 /**
Chris@23 175 * Return summaries of the features that were returned on all of
Chris@23 176 * the plugin's outputs, using the given SummaryType and
Chris@23 177 * AveragingMethod.
Chris@23 178 *
Chris@23 179 * The plugin must have been fully run (process() and
Chris@23 180 * getRemainingFeatures() calls all made as appropriate) before
Chris@23 181 * this function is called.
Chris@23 182 */
Chris@23 183 FeatureSet getSummaryForAllOutputs(SummaryType type,
Chris@23 184 AveragingMethod method = SampleAverage);
Chris@23 185
Chris@23 186 protected:
Chris@23 187 class Impl;
Chris@23 188 Impl *m_impl;
Chris@23 189 };
Chris@23 190
Chris@23 191 }
Chris@23 192
Chris@23 193 }
Chris@23 194
Chris@23 195 _VAMP_SDK_HOSTSPACE_END(PluginSummarisingAdapter.h)
Chris@23 196
Chris@23 197 #endif