![]() |
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_CHANNELINTERNAL_H 00040 #define PLONK_CHANNELINTERNAL_H 00041 00042 #include "../plonk_GraphForwardDeclarations.h" 00043 #include "plonk_ChannelInternalCore.h" 00044 00045 00057 template<class SampleType, class DataType> 00058 class ChannelInternal : public ChannelInternalBase<SampleType>, 00059 public DoubleVariable::Receiver 00060 { 00061 public: 00062 typedef ChannelBase<SampleType> ChannelType; 00063 typedef ChannelInternalBase<SampleType> Internal; 00064 typedef UnitBase<SampleType> UnitType; 00065 typedef NumericalArray<SampleType> Buffer; 00066 typedef InputDictionary Inputs; 00067 typedef ChannelBase<SampleType> Container; 00068 typedef ChannelInternalCore::Data BaseData; 00069 00070 ChannelInternal (Inputs const& inputDictionary, 00071 DataType const& initState, 00072 BlockSize const& blockSize, 00073 SampleRate const& sampleRate) throw() 00074 : Internal (inputDictionary, blockSize, sampleRate), 00075 state (initState) 00076 { 00077 this->getSampleRate().addReceiver (this); 00078 this->updateSampleRateInData(); 00079 } 00080 00081 ~ChannelInternal() 00082 { 00083 this->getSampleRate().removeReceiver (this); 00084 } 00085 00086 const DataType& getState() const throw() { return state; } 00087 DataType& getState() throw() { return state; } 00088 00089 void setSampleRate (SampleRate const& newSampleRate) throw() 00090 { 00091 if (newSampleRate != this->getSampleRate()) 00092 { 00093 plonk_assert (newSampleRate.getValue() >= 0.0); 00094 00095 this->getSampleRate().removeReceiver (this); 00096 this->setSampleRateInternal (newSampleRate); 00097 this->getSampleRate().addReceiver (this); 00098 00099 this->updateSampleRateInData(); 00100 } 00101 } 00102 00103 void setOverlap (DoubleVariable const& newOverlap) throw() 00104 { 00105 if (newOverlap != this->getOverlap()) 00106 { 00107 plonk_assert (newOverlap.getValue() > 0.0); 00108 plonk_assert (newOverlap.getValue() <= 1.0); 00109 00110 this->getOverlap().removeReceiver (this); 00111 this->setOverlapInternal (newOverlap); 00112 this->getOverlap().addReceiver (this); 00113 00114 this->updateTimeStamp(); // changes the next time due to changed overlap.. 00115 } 00116 } 00117 00118 void changed (DoubleVariable::Sender const& source, Text const& message, Dynamic const& payload) throw() 00119 { 00120 (void)message; 00121 (void)payload; 00122 00123 SampleRate sampleRateSource = static_cast<SampleRate> (source); 00124 00125 if (sampleRateSource == this->getSampleRate()) 00126 { 00127 this->updateSampleRateInData(); 00128 return; 00129 } 00130 00131 DoubleVariable overlapSource = static_cast<DoubleVariable> (source); 00132 00133 if (overlapSource == this->getOverlap()) 00134 { 00135 this->updateTimeStamp(); 00136 return; 00137 } 00138 } 00139 00140 void updateSampleRateInData() throw() 00141 { 00142 BaseData& baseData (reinterpret_cast<BaseData&> (state)); 00143 00144 const double newSampleRate = this->getSampleRate().getValue(); 00145 00146 if (baseData.sampleRate != newSampleRate) 00147 { 00148 baseData.sampleRate = newSampleRate; 00149 baseData.sampleDuration = 1.0 / newSampleRate; 00150 } 00151 } 00152 00153 private: 00154 DataType state; 00155 00156 ChannelInternal(); 00157 ChannelInternal (const ChannelInternal&); 00158 const ChannelInternal& operator= (const ChannelInternal&); 00159 }; 00160 00161 00162 00163 00164 00165 #endif // PLONK_CHANNELINTERNAL_H