![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
00001 /* 00002 ------------------------------------------------------------------------------- 00003 This file is part of the Plink, Plonk, Plank libraries 00004 by Martin Robinson 00005 00006 http://code.google.com/p/pl-nk/ 00007 00008 Copyright University of the West of England, Bristol 2011-14 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in the 00018 documentation and/or other materials provided with the distribution. 00019 * Neither the name of University of the West of England, Bristol nor 00020 the names of its contributors may be used to endorse or promote products 00021 derived from this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 This software makes use of third party libraries. For more information see: 00035 doc/license.txt included in the distribution. 00036 ------------------------------------------------------------------------------- 00037 */ 00038 00039 #ifndef PLONK_CHANNELINTERNALCORE_H 00040 #define PLONK_CHANNELINTERNALCORE_H 00041 00042 #include "../plonk_GraphForwardDeclarations.h" 00043 #include "../utility/plonk_ProcessInfo.h" 00044 #include "../utility/plonk_BlockSize.h" 00045 00046 00047 template<> 00048 struct ChannelData<ChannelInternalCore> 00049 { 00050 double sampleRate; 00051 double sampleDuration; 00052 00053 static ChannelData create (double initSampleRate) 00054 { 00055 ChannelData data = { initSampleRate, 1.0 / initSampleRate }; 00056 return data; 00057 } 00058 }; 00059 00060 00064 class ChannelInternalCore 00065 { 00066 public: 00072 typedef struct ChannelData<ChannelInternalCore> Data; 00073 typedef InputDictionary Inputs; 00074 00075 ChannelInternalCore (Inputs const& inputs, 00076 BlockSize const& blockSize, 00077 SampleRate const& sampleRate) throw(); 00078 virtual ~ChannelInternalCore() { } 00079 00080 const TimeStamp& getNextTimeStamp() const throw() { return nextTimeStamp; } 00081 void setNextTimeStamp (TimeStamp const& newTimeStamp) throw(); 00082 void setLastTimeStamp (TimeStamp const& newTimeStamp) throw(); 00083 void setExpiryTimeStamp (TimeStamp const& newTimeStamp) throw(); 00084 bool shouldBeDeletedNow (TimeStamp const& time) const throw(); 00085 // void resetIfExpired() throw(); 00086 00087 inline const Inputs& getInputs() const throw() { return this->inputs; } 00088 inline Inputs& getInputs() throw() { return this->inputs; } 00089 00090 template<class Type> inline const Type& getInputAs (const int key) const throw() { return this->inputs[key].asUnchecked<Type>(); } 00091 template<class Type> inline Type& getInputAs (const int key) throw() { return this->inputs[key].asUnchecked<Type>(); } 00092 00093 const BlockSize& getBlockSize() const throw() { return blockSize; } 00094 const SampleRate& getSampleRate() const throw() { return sampleRate; } 00095 const DoubleVariable& getOverlap() const throw() { return overlap; } 00096 BlockSize& getBlockSize() throw() { return blockSize; } 00097 SampleRate& getSampleRate() throw() { return sampleRate; } 00098 DoubleVariable& getOverlap() throw() { return overlap; } 00099 00100 double getSampleDurationInTicks() const throw() { return cachedSampleDurationTicks; } 00101 double getBlockDurationInTicks() const throw(); 00102 void updateTimeStamp() throw(); 00103 00104 virtual bool isNull() const throw() { return false; } 00105 virtual bool isConstant() const throw() { return false; } 00106 virtual bool isProxyOwner() const throw() { return false; } 00107 virtual bool isProxy() const throw() { return false; } 00108 virtual bool isTypeConverter() const throw() { return false; } 00109 virtual bool canUseExternalBuffer() const throw() { return true; } 00110 virtual double getLatency() const throw() { return 0.0; } 00111 virtual int getNumChannels() const throw() { return 1; } 00112 00113 virtual Text getLabel() const throw() { return identifier; } // virtual due to proxies 00114 virtual void setLabel (Text const& newId) throw(); // virtual due to proxies 00115 00119 virtual void initChannel (const int channel) = 0; 00120 00121 virtual Text getName() const = 0; 00122 virtual IntArray getInputKeys() const = 0; 00123 TextArray getInputNames() const throw(); 00124 IntArray getInputTypes() const throw(); 00125 TextArray getInputTypeNames() const throw(); 00126 00129 virtual void process (ProcessInfo& info, const int channel) = 0; 00130 00131 protected: 00132 void setBlockSizeInternal (BlockSize const& newBlockSize) throw(); 00133 void setSampleRateInternal (SampleRate const& newSampleRate) throw(); 00134 void setOverlapInternal (DoubleVariable const& newOverlap) throw(); 00135 00136 private: 00137 Text identifier; 00138 TimeStamp lastTimeStamp; 00139 TimeStamp nextTimeStamp; 00140 TimeStamp expiryTimeStamp; 00141 Inputs inputs; 00142 BlockSize blockSize; 00143 SampleRate sampleRate; 00144 DoubleVariable overlap; 00145 mutable double cachedSampleDurationTicks; 00146 00147 void cacheSampleDurationTicks() const throw(); 00148 00149 ChannelInternalCore(); 00150 ChannelInternalCore (const ChannelInternalCore&); 00151 const ChannelInternalCore& operator= (const ChannelInternalCore&); 00152 }; 00153 00154 //------------------------------------------------------------------------------ 00155 00156 inline void ChannelInternalCore::setNextTimeStamp (TimeStamp const& time) throw() 00157 { 00158 plonk_assert ((nextTimeStamp.isInfinite() && time.isInfinite()) || (time > nextTimeStamp)); // gone backwards or wraparound 00159 nextTimeStamp = time; 00160 } 00161 00162 inline void ChannelInternalCore::setLastTimeStamp (TimeStamp const& time) throw() 00163 { 00164 plonk_assert (time.isFinite()); 00165 lastTimeStamp = time; 00166 } 00167 00168 inline void ChannelInternalCore::setExpiryTimeStamp (TimeStamp const& time) throw() 00169 { 00170 expiryTimeStamp = time; 00171 } 00172 00173 inline bool ChannelInternalCore::shouldBeDeletedNow (TimeStamp const& time) const throw() 00174 { 00175 return time >= expiryTimeStamp; 00176 } 00177 00178 //inline void ChannelInternalCore::resetIfExpired() throw() 00179 //{ 00180 // expiryTimeStamp = TimeStamp::getMaximum(); 00181 //} 00182 00183 inline double ChannelInternalCore::getBlockDurationInTicks() const throw() 00184 { 00185 return this->getSampleDurationInTicks() * double (this->getBlockSize().getValue()) * overlap.getValue(); 00186 } 00187 00188 00189 #endif // PLONK_CHANNELINTERNALCORE_H