cannam@108: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@108: cannam@108: /* cannam@108: Vamp cannam@108: cannam@108: An API for audio analysis and feature extraction plugins. cannam@108: cannam@108: Centre for Digital Music, Queen Mary, University of London. cannam@108: Copyright 2006-2009 Chris Cannam and QMUL. cannam@108: cannam@108: Permission is hereby granted, free of charge, to any person cannam@108: obtaining a copy of this software and associated documentation cannam@108: files (the "Software"), to deal in the Software without cannam@108: restriction, including without limitation the rights to use, copy, cannam@108: modify, merge, publish, distribute, sublicense, and/or sell copies cannam@108: of the Software, and to permit persons to whom the Software is cannam@108: furnished to do so, subject to the following conditions: cannam@108: cannam@108: The above copyright notice and this permission notice shall be cannam@108: included in all copies or substantial portions of the Software. cannam@108: cannam@108: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@108: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@108: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND cannam@108: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR cannam@108: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@108: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@108: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@108: cannam@108: Except as contained in this notice, the names of the Centre for cannam@108: Digital Music; Queen Mary, University of London; and Chris Cannam cannam@108: shall not be used in advertising or otherwise to promote the sale, cannam@108: use or other dealings in this Software without prior written cannam@108: authorization. cannam@108: */ cannam@108: cannam@108: #ifndef _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_ cannam@108: #define _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_ cannam@108: cannam@108: #include "hostguard.h" cannam@108: #include "PluginWrapper.h" cannam@108: cannam@108: _VAMP_SDK_HOSTSPACE_BEGIN(PluginInputDomainAdapter.h) cannam@108: cannam@108: namespace Vamp { cannam@108: cannam@108: namespace HostExt { cannam@108: cannam@108: /** cannam@108: * \class PluginInputDomainAdapter PluginInputDomainAdapter.h cannam@108: * cannam@108: * PluginInputDomainAdapter is a Vamp plugin adapter that converts cannam@108: * time-domain input into frequency-domain input for plugins that need cannam@108: * it. This permits a host to use time- and frequency-domain plugins cannam@108: * interchangeably without needing to handle the conversion itself. cannam@108: * cannam@108: * This adapter uses a basic windowed FFT (using Hann window by cannam@108: * default) that supports power-of-two block sizes only. If a cannam@108: * frequency domain plugin requests a non-power-of-two blocksize, the cannam@108: * adapter will adjust it to a nearby power of two instead. Thus, cannam@108: * getPreferredBlockSize() will always return a power of two if the cannam@108: * wrapped plugin is a frequency domain one. If the plugin doesn't cannam@108: * accept the adjusted power of two block size, initialise() will cannam@108: * fail. cannam@108: * cannam@108: * The adapter provides no way for the host to discover whether the cannam@108: * underlying plugin is actually a time or frequency domain plugin cannam@108: * (except that if the preferred block size is not a power of two, it cannam@108: * must be a time domain plugin). cannam@108: * cannam@108: * The FFT implementation is simple and self-contained, but unlikely cannam@108: * to be the fastest available: a host can usually do better if it cannam@108: * cares enough. cannam@108: * cannam@108: * The window shape for the FFT frame can be set using setWindowType cannam@108: * and the current shape retrieved using getWindowType. (This was cannam@108: * added in v2.3 of the SDK.) cannam@108: * cannam@108: * In every respect other than its input domain handling, the cannam@108: * PluginInputDomainAdapter behaves identically to the plugin that it cannam@108: * wraps. The wrapped plugin will be deleted when the wrapper is cannam@108: * deleted. cannam@108: * cannam@108: * \note This class was introduced in version 1.1 of the Vamp plugin SDK. cannam@108: */ cannam@108: cannam@108: class PluginInputDomainAdapter : public PluginWrapper cannam@108: { cannam@108: public: cannam@108: /** cannam@108: * Construct a PluginInputDomainAdapter wrapping the given plugin. cannam@108: * The adapter takes ownership of the plugin, which will be cannam@108: * deleted when the adapter is deleted. cannam@108: */ cannam@108: PluginInputDomainAdapter(Plugin *plugin); cannam@108: virtual ~PluginInputDomainAdapter(); cannam@108: cannam@108: bool initialise(size_t channels, size_t stepSize, size_t blockSize); cannam@108: void reset(); cannam@108: cannam@108: InputDomain getInputDomain() const; cannam@108: cannam@108: size_t getPreferredStepSize() const; cannam@108: size_t getPreferredBlockSize() const; cannam@108: cannam@108: FeatureSet process(const float *const *inputBuffers, RealTime timestamp); cannam@108: cannam@108: /** cannam@108: * ProcessTimestampMethod determines how the cannam@108: * PluginInputDomainAdapter handles timestamps for the data passed cannam@108: * to the process() function of the plugin it wraps, in the case cannam@108: * where the plugin is expecting frequency-domain data. cannam@108: * cannam@108: * The Vamp specification requires that the timestamp passed to cannam@108: * the plugin for frequency-domain input should be that of the cannam@108: * centre of the processing block, rather than the start as is the cannam@108: * case for time-domain input. cannam@108: * cannam@108: * Since PluginInputDomainAdapter aims to be transparent in use, cannam@108: * it needs to handle this timestamp adjustment itself. However, cannam@108: * some control is available over the method used for adjustment, cannam@108: * by means of the ProcessTimestampMethod setting. cannam@108: * cannam@108: * If ProcessTimestampMethod is set to ShiftTimestamp (the cannam@108: * default), then the data passed to the wrapped plugin will be cannam@108: * calculated from the same input data block as passed to the cannam@108: * wrapper, but the timestamp passed to the plugin will be cannam@108: * advanced by half of the window size. cannam@108: * cannam@108: * If ProcessTimestampMethod is set to ShiftData, then the cannam@108: * timestamp passed to the wrapped plugin will be the same as that cannam@108: * passed to the process call of the wrapper, but the data block cannam@108: * used to calculate the input will be shifted back (earlier) by cannam@108: * half of the window size, with half a block of zero padding at cannam@108: * the start of the first process call. This has the advantage of cannam@108: * preserving the first half block of audio without any cannam@108: * deterioration from window shaping. cannam@108: * cannam@108: * If ProcessTimestampMethod is set to NoShift, then no adjustment cannam@108: * will be made and the timestamps will be incorrect. cannam@108: */ cannam@108: enum ProcessTimestampMethod { cannam@108: ShiftTimestamp, cannam@108: ShiftData, cannam@108: NoShift cannam@108: }; cannam@108: cannam@108: /** cannam@108: * Set the method used for timestamp adjustment in plugins taking cannam@108: * frequency-domain input. See the ProcessTimestampMethod cannam@108: * documentation for details. cannam@108: * cannam@108: * This function must be called before the first call to cannam@108: * process(). cannam@108: */ cannam@108: void setProcessTimestampMethod(ProcessTimestampMethod); cannam@108: cannam@108: /** cannam@108: * Retrieve the method used for timestamp adjustment in plugins cannam@108: * taking frequency-domain input. See the ProcessTimestampMethod cannam@108: * documentation for details. cannam@108: */ cannam@108: ProcessTimestampMethod getProcessTimestampMethod() const; cannam@108: cannam@108: /** cannam@108: * Return the amount by which the timestamps supplied to process() cannam@108: * are being incremented when they are passed to the plugin's own cannam@108: * process() implementation. cannam@108: * cannam@108: * The Vamp API mandates that the timestamp passed to the plugin cannam@108: * for time-domain input should be the time of the first sample in cannam@108: * the block, but the timestamp passed for frequency-domain input cannam@108: * should be the timestamp of the centre of the block. cannam@108: * cannam@108: * The PluginInputDomainAdapter adjusts its timestamps properly so cannam@108: * that the plugin receives correct times, but in some cannam@108: * circumstances (such as for establishing the correct timing of cannam@108: * implicitly-timed features, i.e. features without their own cannam@108: * timestamps) the host may need to be aware that this adjustment cannam@108: * is taking place. cannam@108: * cannam@108: * If the plugin requires time-domain input or the cannam@108: * PluginInputDomainAdapter is configured with its cannam@108: * ProcessTimestampMethod set to ShiftData instead of cannam@108: * ShiftTimestamp, then this function will return zero. cannam@108: * cannam@108: * The result of calling this function before initialise() has cannam@108: * been called is undefined. cannam@108: */ cannam@108: RealTime getTimestampAdjustment() const; cannam@108: cannam@108: /** cannam@108: * The set of supported window shapes. cannam@108: */ cannam@108: enum WindowType { cannam@108: cannam@108: RectangularWindow = 0, cannam@108: cannam@108: BartlettWindow = 1, /// synonym for RectangularWindow cannam@108: TriangularWindow = 1, /// synonym for BartlettWindow cannam@108: cannam@108: HammingWindow = 2, cannam@108: cannam@108: HanningWindow = 3, /// synonym for HannWindow cannam@108: HannWindow = 3, /// synonym for HanningWindow cannam@108: cannam@108: BlackmanWindow = 4, cannam@108: cannam@108: NuttallWindow = 7, cannam@108: cannam@108: BlackmanHarrisWindow = 8 cannam@108: }; cannam@108: cannam@108: /** cannam@108: * Return the current window shape. The default is HanningWindow. cannam@108: */ cannam@108: WindowType getWindowType() const; cannam@108: cannam@108: /** cannam@108: * Set the current window shape. cannam@108: */ cannam@108: void setWindowType(WindowType type); cannam@108: cannam@108: cannam@108: protected: cannam@108: class Impl; cannam@108: Impl *m_impl; cannam@108: }; cannam@108: cannam@108: } cannam@108: cannam@108: } cannam@108: cannam@108: _VAMP_SDK_HOSTSPACE_END(PluginInputDomainAdapter.h) cannam@108: cannam@108: #endif