pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
plonk_UnaryOpPlink.h
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_UNARYOPPLINK_H
00040 #define PLONK_UNARYOPPLINK_H
00041 
00042 #include "plonk_UnaryOpChannel.h"
00043 
00044 
00045 #define PLONK_PLINK_UNARYOPCHANNEL_COMMON_START(PLONKOP) \
00046     template<>\
00047     class UnaryOpChannelInternal<float, UnaryOpFunctionsHelper<float>::UnaryOpFunctionsType::PLONKOP> \
00048     : public ChannelInternal<float, ChannelInternalCore::Data>\
00049     {\
00050     public:\
00051         typedef ChannelInternalCore::Data                                   Data;\
00052         typedef UnaryOpFunctionsHelper<float>::UnaryOpFunctionsType         UnaryOpFunctionsType;\
00053         typedef ChannelBase<float>                                          ChannelType;\
00054         typedef UnaryOpChannelInternal<float,UnaryOpFunctionsType::PLONKOP> UnaryOpInternal;\
00055         typedef ChannelInternal<float,Data>                                 Internal;\
00056         typedef ChannelInternalBase<float>                                  InternalBase;\
00057         typedef UnitBase<float>                                             UnitType;\
00058         typedef InputDictionary                                             Inputs;\
00059         typedef NumericalArray<float>                                       Buffer;\
00060         typedef UnaryOpUtility<float>                                       UtilityType;\
00061         \
00062         enum InputIndices { Operand, NumInputs };\
00063         enum Outputs { Output, NumOutputs };\
00064         enum Buffers { OutputBuffer, OperandBuffer, NumBuffers };\
00065         typedef PlinkProcess<NumBuffers> Process;\
00066         \
00067         UnaryOpChannelInternal (Inputs const& inputs, Data const& data,\
00068                                 BlockSize const& blockSize, SampleRate const& sampleRate) throw()\
00069         :   Internal (inputs, data, blockSize, sampleRate)\
00070         {\
00071             plonk_staticassert (NumBuffers == (NumInputs + NumOutputs));\
00072             Process::init (&p, this, NumOutputs, NumInputs);\
00073         }
00074         
00075 
00076 #define PLONK_PLINK_UNARYOPCHANNEL_COMMON_END\
00077     private:\
00078         Process p;\
00079     };
00080 
00081 #define PLONK_PLINK_UNARYOPCHANNEL_FUNCTION(PLANKOP,TYPECODE) plink_UnaryOpProcess##PLANKOP##TYPECODE
00082 
00083 #define PLONK_PLINK_UNARYOPCHANNEL_PROCESS(PLONKOP, PLANKOP) \
00084     Text getName() const throw() {\
00085         Text variant = UtilityType::global().getName (UnaryOpFunctionsType::PLONKOP);\
00086         if (variant.length() < 1) variant = "unknown type";\
00087         return "Unary Operator (" + variant + ")";\
00088     }\
00089     \
00090     IntArray getInputKeys() const throw() {\
00091         const IntArray keys (IOKey::Generic);\
00092         return keys;\
00093     }\
00094     \
00095     InternalBase* getChannel (const int index) throw() {\
00096         const Inputs channelInputs = this->getInputs().getChannel (index);\
00097         return new UnaryOpInternal (channelInputs, this->getState(), this->getBlockSize(), this->getSampleRate());\
00098     }\
00099     \
00100     void initChannel (const int channel) throw() {\
00101         const UnitType& input = this->getInputAsUnit (IOKey::Generic);\
00102         const float sourceValue = input.getValue (channel);\
00103         this->setBlockSize (BlockSize::decide (input.getBlockSize (channel), this->getBlockSize()));\
00104         this->setSampleRate (SampleRate::decide (input.getSampleRate (channel), this->getSampleRate()));\
00105         this->setOverlap (input.getOverlap (channel));\
00106         this->initValue (pl_##PLANKOP##F (sourceValue));\
00107     }\
00108     \
00109     void process (ProcessInfo& info, const int channel) throw() {\
00110         UnitType& operandUnit (this->getInputAsUnit (IOKey::Generic));\
00111         const Buffer& operandBuffer (operandUnit.process (info, channel));\
00112         \
00113         p.buffers[0].bufferSize = this->getOutputBuffer().length();\
00114         p.buffers[0].buffer = this->getOutputSamples();\
00115         p.buffers[1].bufferSize = operandBuffer.length();\
00116         p.buffers[1].buffer = operandBuffer.getArray();\
00117         \
00118         PLONK_PLINK_UNARYOPCHANNEL_FUNCTION(PLANKOP,F) (&p,0);\
00119     }
00120 
00121 #define PLONK_PLINK_UNARYOPCHANNEL(PLONKOP, PLANKOP)\
00122     PLONK_PLINK_UNARYOPCHANNEL_COMMON_START(PLONKOP)\
00123     PLONK_PLINK_UNARYOPCHANNEL_PROCESS(PLONKOP, PLANKOP)\
00124     PLONK_PLINK_UNARYOPCHANNEL_COMMON_END
00125 
00126 PLONK_PLINK_UNARYOPCHANNEL(move, Move)
00127 PLONK_PLINK_UNARYOPCHANNEL(inc, Inc)
00128 PLONK_PLINK_UNARYOPCHANNEL(neg, Neg)
00129 PLONK_PLINK_UNARYOPCHANNEL(abs, Abs)
00130 PLONK_PLINK_UNARYOPCHANNEL(log2, Log2)
00131 PLONK_PLINK_UNARYOPCHANNEL(reciprocal, Reciprocal)
00132 PLONK_PLINK_UNARYOPCHANNEL(sin, Sin)
00133 PLONK_PLINK_UNARYOPCHANNEL(cos, Cos)
00134 PLONK_PLINK_UNARYOPCHANNEL(tan, Tan)
00135 PLONK_PLINK_UNARYOPCHANNEL(asin, Asin)
00136 PLONK_PLINK_UNARYOPCHANNEL(acos, Acos)
00137 PLONK_PLINK_UNARYOPCHANNEL(atan, Atan)
00138 PLONK_PLINK_UNARYOPCHANNEL(sinh, Sinh)
00139 PLONK_PLINK_UNARYOPCHANNEL(cosh, Cosh)
00140 PLONK_PLINK_UNARYOPCHANNEL(tanh, Tanh)
00141 PLONK_PLINK_UNARYOPCHANNEL(sqrt, Sqrt)
00142 PLONK_PLINK_UNARYOPCHANNEL(log, Log)
00143 PLONK_PLINK_UNARYOPCHANNEL(log10, Log10)
00144 PLONK_PLINK_UNARYOPCHANNEL(exp, Exp)
00145 PLONK_PLINK_UNARYOPCHANNEL(squared, Squared)
00146 PLONK_PLINK_UNARYOPCHANNEL(cubed, Cubed)
00147 PLONK_PLINK_UNARYOPCHANNEL(ceil, Ceil)
00148 PLONK_PLINK_UNARYOPCHANNEL(floor, Floor)
00149 PLONK_PLINK_UNARYOPCHANNEL(frac, Frac)
00150 PLONK_PLINK_UNARYOPCHANNEL(sign , Sign)
00151 PLONK_PLINK_UNARYOPCHANNEL(m2f, M2F)
00152 PLONK_PLINK_UNARYOPCHANNEL(f2m, F2M)
00153 PLONK_PLINK_UNARYOPCHANNEL(a2dB, A2dB)
00154 PLONK_PLINK_UNARYOPCHANNEL(dB2a, dB2A)
00155 PLONK_PLINK_UNARYOPCHANNEL(d2r, D2R)
00156 PLONK_PLINK_UNARYOPCHANNEL(r2d, R2D)
00157 PLONK_PLINK_UNARYOPCHANNEL(distort, Distort)
00158 PLONK_PLINK_UNARYOPCHANNEL(zap, Zap)
00159 
00160 #endif // PLONK_UNARYOPPLINK_H
 All Classes Functions Typedefs Enumerations Enumerator Properties