annotate osx/include/vamp-hostsdk/PluginSummarisingAdapter.h @ 36:55ece8862b6d

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