annotate vamp-sdk/hostext/PluginBufferingAdapter.h @ 169:af8e59f43d1d

* Add capability for setting underlying plugin's step and block sizes to PluginBufferingAdapter
author cannam
date Fri, 25 Jul 2008 11:49:06 +0000
parents 92ca8e401044
children ff72d97823f7
rev   line source
cannam@92 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@92 2
cannam@92 3 /*
cannam@92 4 Vamp
cannam@92 5
cannam@92 6 An API for audio analysis and feature extraction plugins.
cannam@92 7
cannam@92 8 Centre for Digital Music, Queen Mary, University of London.
cannam@92 9 Copyright 2006-2007 Chris Cannam and QMUL.
cannam@92 10 This file by Mark Levy, Copyright 2007 QMUL.
cannam@92 11
cannam@92 12 Permission is hereby granted, free of charge, to any person
cannam@92 13 obtaining a copy of this software and associated documentation
cannam@92 14 files (the "Software"), to deal in the Software without
cannam@92 15 restriction, including without limitation the rights to use, copy,
cannam@92 16 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@92 17 of the Software, and to permit persons to whom the Software is
cannam@92 18 furnished to do so, subject to the following conditions:
cannam@92 19
cannam@92 20 The above copyright notice and this permission notice shall be
cannam@92 21 included in all copies or substantial portions of the Software.
cannam@92 22
cannam@92 23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@92 24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@92 25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@92 26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@92 27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@92 28 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@92 29 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@92 30
cannam@92 31 Except as contained in this notice, the names of the Centre for
cannam@92 32 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@92 33 shall not be used in advertising or otherwise to promote the sale,
cannam@92 34 use or other dealings in this Software without prior written
cannam@92 35 authorization.
cannam@92 36 */
cannam@92 37
cannam@92 38 #ifndef _VAMP_PLUGIN_BUFFERING_ADAPTER_H_
cannam@92 39 #define _VAMP_PLUGIN_BUFFERING_ADAPTER_H_
cannam@92 40
cannam@92 41 #include "PluginWrapper.h"
cannam@92 42
cannam@92 43 namespace Vamp {
cannam@92 44
cannam@92 45 namespace HostExt {
cannam@92 46
cannam@92 47 /**
cannam@92 48 * \class PluginBufferingAdapter PluginBufferingAdapter.h <vamp-sdk/hostext/PluginBufferingAdapter.h>
cannam@92 49 *
cannam@92 50 * PluginBufferingAdapter is a Vamp plugin adapter that allows plugins
cannam@92 51 * to be used by a host supplying an audio stream in non-overlapping
cannam@92 52 * buffers of arbitrary size.
cannam@92 53 *
cannam@92 54 * A host using PluginBufferingAdapter may ignore the preferred step
cannam@92 55 * and block size reported by the plugin, and still expect the plugin
cannam@92 56 * to run. The value of blockSize and stepSize passed to initialise
cannam@92 57 * should be the size of the buffer which the host will supply; the
cannam@92 58 * stepSize should be equal to the blockSize.
cannam@92 59 *
cannam@92 60 * If the internal step size used for the plugin differs from that
cannam@133 61 * supplied by the host, the adapter will modify the sample type and
cannam@133 62 * rate specifications for the plugin outputs appropriately, and set
cannam@133 63 * timestamps on the output features for outputs that formerly used a
cannam@133 64 * different sample rate specification. This is necessary in order to
cannam@133 65 * obtain correct time stamping.
cannam@92 66 *
cannam@92 67 * In other respects, the PluginBufferingAdapter behaves identically
cannam@92 68 * to the plugin that it wraps. The wrapped plugin will be deleted
cannam@92 69 * when the wrapper is deleted.
cannam@92 70 */
cannam@92 71
cannam@92 72 class PluginBufferingAdapter : public PluginWrapper
cannam@92 73 {
cannam@92 74 public:
cannam@92 75 PluginBufferingAdapter(Plugin *plugin); // I take ownership of plugin
cannam@92 76 virtual ~PluginBufferingAdapter();
cannam@169 77
cannam@169 78 /**
cannam@169 79 * Return the preferred step size for this adapter.
cannam@169 80 *
cannam@169 81 * Because of the way this adapter works, its preferred step size
cannam@169 82 * will always be the same as its preferred block size. This may
cannam@169 83 * or may not be the same as the preferred step size of the
cannam@169 84 * underlying plugin, which may be obtained by calling
cannam@169 85 * getPluginPreferredStepSize().
cannam@169 86 */
cannam@169 87 size_t getPreferredStepSize() const;
cannam@169 88
cannam@169 89 /**
cannam@169 90 * Return the preferred block size for this adapter.
cannam@169 91 *
cannam@169 92 * This may or may not be the same as the preferred block size of
cannam@169 93 * the underlying plugin, which may be obtained by calling
cannam@169 94 * getPluginPreferredBlockSize().
cannam@169 95 *
cannam@169 96 * Note that this adapter may be initialised with any block size,
cannam@169 97 * not just its supposedly preferred one.
cannam@169 98 */
cannam@169 99 size_t getPreferredBlockSize() const;
cannam@169 100
cannam@169 101 /**
cannam@169 102 * Return the preferred step size of the plugin wrapped by this
cannam@169 103 * adapter.
cannam@169 104 *
cannam@169 105 * This is included mainly for informational purposes. This value
cannam@169 106 * is not likely to be a valid step size for the adapter itself,
cannam@169 107 * and it is not usually of any use in interpreting the results
cannam@169 108 * (because the adapter re-writes OneSamplePerStep outputs to
cannam@169 109 * FixedSampleRate so that the hop size no longer needs to be
cannam@169 110 * known beforehand in order to interpret them).
cannam@169 111 */
cannam@169 112 size_t getPluginPreferredStepSize() const;
cannam@169 113
cannam@169 114 /**
cannam@169 115 * Return the preferred block size of the plugin wrapped by this
cannam@169 116 * adapter.
cannam@169 117 *
cannam@169 118 * This is included mainly for informational purposes.
cannam@169 119 */
cannam@169 120 size_t getPluginPreferredBlockSize() const;
cannam@169 121
cannam@169 122 /**
cannam@169 123 * Set the step size that will be used for the underlying plugin
cannam@169 124 * when initialise() is called. If this is not set, the plugin's
cannam@169 125 * own preferred step size will be used. You will not usually
cannam@169 126 * need to call this function. If you do call it, it must be
cannam@169 127 * before the first call to initialise().
cannam@169 128 */
cannam@169 129 void setPluginStepSize(size_t stepSize);
cannam@169 130
cannam@169 131 /**
cannam@169 132 * Set the block size that will be used for the underlying plugin
cannam@169 133 * when initialise() is called. If this is not set, the plugin's
cannam@169 134 * own preferred block size will be used. You will not usually
cannam@169 135 * need to call this function. If you do call it, it must be
cannam@169 136 * before the first call to initialise().
cannam@169 137 */
cannam@169 138 void setPluginBlockSize(size_t blockSize);
cannam@169 139
cannam@169 140 /**
cannam@169 141 * Initialise the adapter (and therefore the plugin) for the given
cannam@169 142 * number of channels. Initialise the adapter for the given step
cannam@169 143 * and block size, which must be equal.
cannam@169 144 *
cannam@169 145 * The step and block size used for the underlying plugin will
cannam@169 146 * depend on its preferences, or any values previously passed to
cannam@169 147 * setPluginStepSize and setPluginBlockSize.
cannam@169 148 */
cannam@92 149 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
cannam@92 150
cannam@92 151 OutputList getOutputDescriptors() const;
cannam@92 152
cannam@104 153 void reset();
cannam@104 154
cannam@92 155 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
cannam@92 156
cannam@92 157 FeatureSet getRemainingFeatures();
cannam@92 158
cannam@92 159 protected:
cannam@92 160 class Impl;
cannam@92 161 Impl *m_impl;
cannam@92 162 };
cannam@92 163
cannam@92 164 }
cannam@92 165
cannam@92 166 }
cannam@92 167
cannam@92 168 #endif