Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

FEAPIPluginBase.cpp

Go to the documentation of this file.
00001 
00002 //     /*! \file FEAPIPluginBase.cpp: \brief implementation of the CFeatureExtractBase class. */
00003 //
00004 //        Copyright (c) 2004-2007, Alexander Lerch, zplane.development GbR
00005 //        All rights reserved.
00006 //
00007 //        Redistribution and use in source and binary forms, with or without 
00008 //        modification, are permitted provided that the following conditions 
00009 //        are met:
00010 //
00011 //        *   Redistributions of source code must retain the above copyright 
00012 //            notice, this list of conditions and the following disclaimer. 
00013 //        *   Redistributions in binary form must reproduce the above 
00014 //            copyright notice, this list of conditions and the following 
00015 //            disclaimer in the documentation and/or other materials 
00016 //            provided with the distribution. 
00017 //        *   Neither the name of the FEAPI development team nor the names 
00018 //            of its contributors may be used to endorse or promote products 
00019 //            derived from this software without specific prior written 
00020 //            permission. 
00021 //
00022 //        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00023 //        "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00024 //        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
00025 //        FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
00026 //        COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00027 //        INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00028 //        BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00029 //        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00030 //        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00031 //        LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00032 //        ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00033 //        POSSIBILITY OF SUCH DAMAGE.
00034 //
00037 //                      !!!Do never ever edit this file!!!
00040 
00041 
00042 #include <string>
00043 
00044 #include "FEAPI.h"
00045 #include "FEAPIPluginBase.h"
00046 
00048 #define _API_MAJOR_VERSION          0x00000001
00049 #define _API_MINOR_VERSION          0x00000000
00050 #define _API_SUB_VERSION            0x00000000
00051 
00052 
00054 #define _DEFAULT_PLUG_MAJOR_VERSION 0x00000000
00055 #define _DEFAULT_PLUG_MINOR_VERSION 0x00000000
00056 #define _DEFAULT_PLUG_SUB_VERSION   0x00000000
00057 
00058 
00059 #define _DEFAULT_PLUGIN_NAME        "Default Plugin Name"
00060 #define _DEFAULT_PLUGIN_VENDOR      "Default Plugin Vendor"
00061 #define _DEFAULT_PLUGIN_DESCRIPTION "This is the default plugin description"
00062 #define _DEFAULT_PLUGIN_COPYRIGHT   "(c) default copyright information"
00063 #define _DEFAULT_PLUGIN_ID          "Default Plugin Id"
00064 
00065 #define _DEFAULT_NUM_PARAMETERS     0
00066 #define _DEFAULT_NUM_RESULTS        0
00067 
00068 
00069 static const float MinFloat = - float((1<<30)-1);
00070 static const float MaxFloat = float((1<<30)-1);
00071 
00073 // CPin implementation: construction, destruction, and copy
00075 
00076 CPin::CPin()
00077 :   m_iIndex(0),
00078     m_Name(),
00079     m_Unit(),
00080     m_Description(),
00081     m_fRangeMin(MinFloat),                  
00082     m_fRangeMax(MaxFloat),          
00083     m_fQuantizedTo(-1),
00084     m_fSampleRate(-1),
00085     m_fDefaultValue(0),     
00086     m_bIsChangeableInRealTime(1)
00087 {
00088 }
00089     
00090 CPin::CPin(int iIndex)
00091 :   m_iIndex(iIndex),
00092     m_Name(),
00093     m_Unit(),
00094     m_Description(),
00095     m_fRangeMin(MinFloat),                  
00096     m_fRangeMax(MaxFloat),          
00097     m_fQuantizedTo(-1),
00098     m_fSampleRate(-1),
00099     m_fDefaultValue(0),     
00100     m_bIsChangeableInRealTime(1)
00101 {
00102 }
00103 
00104 CPin::CPin(const CPin& OtherPin)
00105 {
00106     if (&OtherPin != this)
00107         Copy(OtherPin);
00108 }
00109 
00110 CPin::~CPin()
00111 {
00112 }
00113 
00114 void CPin::Copy(const CPin& OtherPin)
00115 {
00116     m_iIndex = OtherPin.m_iIndex;
00117     m_Name = OtherPin.m_Name;
00118     m_Unit = OtherPin.m_Unit;
00119     m_Description = OtherPin.m_Description;
00120     m_fRangeMin = OtherPin.m_fRangeMin;                 
00121     m_fRangeMax = OtherPin.m_fRangeMax; 
00122     m_fQuantizedTo = OtherPin.m_fQuantizedTo;
00123     m_fSampleRate = OtherPin.m_fSampleRate;
00124     m_fDefaultValue = OtherPin.m_fDefaultValue;
00125     m_bIsChangeableInRealTime = OtherPin.m_bIsChangeableInRealTime;
00126 }
00127 
00128 
00130 // CPin implementation: properties common to all kinds of pins
00132 
00133 CPin CPin::SetIndex(int iIndex)
00134 {
00135     return CPin(iIndex);
00136 }
00137 
00138 int CPin::GetIndex() const
00139 {
00140     return m_iIndex;
00141 }
00142 
00143 CPin& CPin::SetName(const std::string& Name)
00144 {
00145     m_Name = Name;
00146     return *this;
00147 }
00148 
00149 const std::string& CPin::GetName() const
00150 {
00151     return m_Name;
00152 }
00153 
00154 CPin& CPin::SetUnit(const std::string& Unit)
00155 {
00156     m_Unit = Unit;
00157     return *this;
00158 }
00159 
00160 const std::string& CPin::GetUnit() const
00161 {
00162     return m_Unit;
00163 }
00164 
00165 CPin& CPin::SetDescription(const std::string& Description)
00166 {
00167     m_Description = Description;
00168     return *this;
00169 }
00170 
00171 const std::string& CPin::GetDescription() const
00172 {
00173     return m_Description;
00174 }
00175 
00176 CPin& CPin::SetRangeMin(float fRangeMin)
00177 {
00178     m_fRangeMin = fRangeMin;
00179     return *this;
00180 }
00181 
00182 float CPin::GetRangeMin() const
00183 {
00184     return m_fRangeMin;
00185 }
00186 
00187 CPin& CPin::SetRangeMax(float fRangeMax)
00188 {
00189     m_fRangeMax = fRangeMax;
00190     return *this;
00191 }
00192 
00193 float CPin::GetRangeMax() const
00194 {
00195     return m_fRangeMax;
00196 }
00197 
00198 
00200 // CPin implementation: input and result pins
00202 
00203 CPin& CPin::SetQuantizedTo(float fQuantizedTo)
00204 {
00205     m_fQuantizedTo = fQuantizedTo;
00206     return *this;
00207 }
00208 
00209 float CPin::GetQuantizedTo() const
00210 {
00211     return m_fQuantizedTo;
00212 }
00213 
00214 CPin& CPin::SetSampleRate(float fSampleRate)
00215 {
00216     m_fSampleRate = fSampleRate;
00217     return *this;
00218 }
00219 
00220 float CPin::GetSampleRate() const
00221 {
00222     return m_fSampleRate;
00223 }
00224 
00225 
00227 // CPin implementation: parameter pins
00229 
00230 CPin& CPin::SetDefaultValue(float fDefaultValue)
00231 {
00232     m_fDefaultValue = fDefaultValue;
00233     return *this;
00234 }
00235     
00236 float CPin::GetDefaultValue() const
00237 {
00238     return m_fDefaultValue;
00239 }
00240 
00241 CPin& CPin::SetIsChangeableInRealTime(int bIsChangeableInRealTime)
00242 {
00243     m_bIsChangeableInRealTime = bIsChangeableInRealTime;
00244     return *this;
00245 }
00246     
00247 int CPin::GetIsChangeableInRealTime() const
00248 {
00249     return m_bIsChangeableInRealTime;
00250 }
00251 
00252 
00254 // CFeatureExtractBase
00256 
00257 CFeatureExtractBase::CFeatureExtractBase ()
00258 {
00259     // initialize
00260     m_fSampleRate           = 0;
00261 
00262     m_bIsInitialized        = false;
00263 
00264     m_cPluginName           = _DEFAULT_PLUGIN_NAME;
00265     m_cPluginVendor         = _DEFAULT_PLUGIN_VENDOR;
00266     m_cPluginDescription    = _DEFAULT_PLUGIN_DESCRIPTION;
00267     m_cPluginId             = _DEFAULT_PLUGIN_ID;
00268     m_cPluginCopyRight      = _DEFAULT_PLUGIN_COPYRIGHT;
00269 
00270     m_iMajorVersion         = _DEFAULT_PLUG_MAJOR_VERSION;
00271     m_iMinorVersion         = _DEFAULT_PLUG_MINOR_VERSION;
00272     m_iSubVersion           = _DEFAULT_PLUG_SUB_VERSION;
00273 }
00274 
00275 
00276 CFeatureExtractBase::~CFeatureExtractBase ()
00277 {
00278     m_bIsInitialized    = false;
00279     
00280     // Cleaning internal data structures
00281     m_Inputs.clear();
00282     m_Results.clear();
00283     m_Parameters.clear();
00284 }
00285 
00286 
00287 int  CFeatureExtractBase::GetPluginAPIVersion (FEAPI_VersionInfo_t iApiMajorMinorOrSubVersion)
00288 {
00289     switch (iApiMajorMinorOrSubVersion)
00290     {
00291     case FEAPI_kMajorVersion:
00292         {
00293             return _API_MAJOR_VERSION;
00294         }
00295     case FEAPI_kMinorVersion:
00296         {
00297             return _API_MINOR_VERSION;
00298         }
00299     case FEAPI_kSubVersion:
00300         {
00301             return _API_SUB_VERSION;
00302         }
00303     default:
00304         {
00305             // this shall never happen ...
00306             return 0;
00307         }
00308     }
00309 }
00310 
00311 
00312 FEAPI_Error_t      CFeatureExtractBase::InitializePlugin (  float               fInputSampleRate, 
00313                                                             int                 iNumberOfAudioChannels,
00314                                                             int                 iHostApiMajorVersion,
00315                                                             FEAPI_UserData_t     *pstUserData)
00316 {
00317     if ((fInputSampleRate <= 0) || (iNumberOfAudioChannels <= 0))
00318         return FEAPI_kUnspecifiedError;
00319 
00320     m_fSampleRate       = fInputSampleRate;
00321 
00322     m_bIsInitialized    = true;
00323 
00324     return FEAPI_kNoError;
00325 }
00326 
00327 
00328 FEAPI_Error_t      CFeatureExtractBase::GetPluginName (char *pcPluginName)
00329 {
00330     if (!pcPluginName)
00331         return FEAPI_kUnspecifiedError;
00332     pcPluginName[m_cPluginName.copy (pcPluginName, FEAPI_kMaxNameLength-1)] = '\0';
00333 
00334     return FEAPI_kNoError;
00335 }
00336 
00337 
00338 FEAPI_Error_t      CFeatureExtractBase::GetPluginVendor (char *pcPluginVendor)
00339 {
00340     if (!pcPluginVendor)
00341         return FEAPI_kUnspecifiedError;
00342     pcPluginVendor[m_cPluginVendor.copy (pcPluginVendor, FEAPI_kMaxNameLength-1)] = '\0';
00343 
00344     return FEAPI_kNoError;
00345 }
00346 
00347 FEAPI_Error_t      CFeatureExtractBase::GetPluginId (char *pcPluginId)
00348 {
00349     if (!pcPluginId)
00350         return FEAPI_kUnspecifiedError;
00351     pcPluginId[m_cPluginId.copy (pcPluginId, FEAPI_kMaxNameLength-1)] = '\0';
00352 
00353     return FEAPI_kNoError;
00354 }
00355 
00356 int  CFeatureExtractBase::GetPluginVendorVersion (FEAPI_VersionInfo_t ePluginMajorMinorOrSubVersion)
00357 {
00358     switch (ePluginMajorMinorOrSubVersion)
00359     {
00360     case FEAPI_kMajorVersion:
00361         {
00362             return m_iMajorVersion;
00363         }
00364     case FEAPI_kMinorVersion:
00365         {
00366             return m_iMinorVersion;
00367         }
00368     case FEAPI_kSubVersion:
00369         {
00370             return m_iSubVersion;
00371         }
00372     default:
00373         {
00374             // this shall never happen ...
00375             return -1;
00376         }
00377     }
00378 }
00379 
00380 
00381 FEAPI_Error_t      CFeatureExtractBase::GetPluginDescription (char *pcPluginDescription)
00382 {
00383     if (!pcPluginDescription)
00384         return FEAPI_kUnspecifiedError;
00385     pcPluginDescription[m_cPluginDescription.copy (pcPluginDescription, FEAPI_kMaxDescriptionLength-1)] = '\0';
00386 
00387     return FEAPI_kNoError;
00388 }
00389 
00390 
00391 FEAPI_Error_t      CFeatureExtractBase::GetPluginCopyright (char *pcPluginCopyright)
00392 {
00393     if (!pcPluginCopyright)
00394         return FEAPI_kUnspecifiedError;
00395     pcPluginCopyright[m_cPluginCopyRight.copy (pcPluginCopyright, FEAPI_kMaxDescriptionLength-1)] = '\0';
00396 
00397     return FEAPI_kNoError;
00398 }
00399 
00400 
00401 int         CFeatureExtractBase::GetPluginNumOfInputs ()
00402 {   
00403     return int(m_Inputs.size());
00404 }
00405 
00406 
00407 FEAPI_Error_t      CFeatureExtractBase::GetPluginInputDescription (int iInputIndex, FEAPI_SignalDescription_t *pstInputDescription)
00408 {
00409     if (pstInputDescription == 0) return FEAPI_kInvalidPointerError;
00410     if ((iInputIndex < 0) || (iInputIndex >= GetPluginNumOfInputs())) return FEAPI_kIndexOutOfRangeError;
00411     
00412     // The plugin has no inputs or SetInput was not used. In the latter case this function should be overridden in the plugin class.
00413     if (m_Inputs.empty()) return FEAPI_kUnspecifiedError;  
00414 
00415     pstInputDescription->acName[m_Inputs[iInputIndex].GetName().copy(pstInputDescription->acName, FEAPI_kMaxNameLength - 1)] = '\0';
00416     pstInputDescription->acUnit[m_Inputs[iInputIndex].GetUnit().copy(pstInputDescription->acUnit, FEAPI_kMaxUnitLength - 1)] = '\0';
00417     pstInputDescription->acDescription[m_Inputs[iInputIndex].GetDescription().copy(pstInputDescription->acDescription, FEAPI_kMaxDescriptionLength - 1)] = '\0';
00418     pstInputDescription->fRangeMin = m_Inputs[iInputIndex].GetRangeMin();
00419     pstInputDescription->fRangeMax = m_Inputs[iInputIndex].GetRangeMax();
00420     pstInputDescription->fQuantizedTo = m_Inputs[iInputIndex].GetQuantizedTo();
00421     pstInputDescription->fSampleRate = m_fSampleRate;
00422     
00423     return FEAPI_kNoError;
00424 }
00425 
00426 
00427 int         CFeatureExtractBase::GetPluginNumOfResults ()
00428 {
00429     return int(m_Results.size());
00430 }
00431 
00432 
00433 FEAPI_Error_t      CFeatureExtractBase::GetPluginResultDescription (int iResultIndex, FEAPI_SignalDescription_t *pstResultDescription)
00434 {
00435     if (pstResultDescription == 0) return FEAPI_kInvalidPointerError;
00436     if ((iResultIndex < 0) || (iResultIndex >= GetPluginNumOfResults())) return FEAPI_kIndexOutOfRangeError;
00437     
00438     // The plugin has no results or SetResult was not used. In the latter case this function should be overridden in the plugin class.
00439     if (m_Results.empty()) return FEAPI_kUnspecifiedError;
00440 
00441     pstResultDescription->acName[m_Results[iResultIndex].GetName().copy(pstResultDescription->acName, FEAPI_kMaxNameLength - 1)] = '\0';
00442     pstResultDescription->acUnit[m_Results[iResultIndex].GetUnit().copy(pstResultDescription->acUnit, FEAPI_kMaxUnitLength - 1)] = '\0';
00443     pstResultDescription->acDescription[m_Results[iResultIndex].GetDescription().copy(pstResultDescription->acDescription, FEAPI_kMaxDescriptionLength - 1)] = '\0';
00444     pstResultDescription->fRangeMin = m_Results[iResultIndex].GetRangeMin();
00445     pstResultDescription->fRangeMax = m_Results[iResultIndex].GetRangeMax();
00446     pstResultDescription->fQuantizedTo = m_Results[iResultIndex].GetQuantizedTo();
00447     pstResultDescription->fSampleRate = m_Results[iResultIndex].GetSampleRate();
00448     
00449     return FEAPI_kNoError;
00450 }
00451 
00452 
00453 int         CFeatureExtractBase::GetPluginNumOfParameters ()
00454 {
00455     return int(m_Parameters.size());
00456 }
00457 
00458 
00459 FEAPI_Error_t      CFeatureExtractBase::GetPluginParameterDescription (int iParameterIndex, FEAPI_ParameterDescription_t *pstParameterDescription)
00460 {
00461     if (pstParameterDescription == 0) return FEAPI_kInvalidPointerError;
00462     if ((iParameterIndex < 0) || (iParameterIndex >= GetPluginNumOfParameters())) return FEAPI_kIndexOutOfRangeError;
00463     
00464     // The plugin has no parameters or SetParameter was not used. In the latter case this function should be overridden in the plugin class.    
00465     if (m_Parameters.empty()) return FEAPI_kUnspecifiedError;
00466 
00467     pstParameterDescription->acName[m_Parameters[iParameterIndex].GetName().copy(pstParameterDescription->acName, FEAPI_kMaxNameLength - 1)] = '\0';
00468     pstParameterDescription->acUnit[m_Parameters[iParameterIndex].GetUnit().copy(pstParameterDescription->acUnit, FEAPI_kMaxUnitLength - 1)] = '\0';
00469     pstParameterDescription->acDescription[m_Parameters[iParameterIndex].GetDescription().copy(pstParameterDescription->acDescription, FEAPI_kMaxDescriptionLength - 1)] = '\0';
00470     pstParameterDescription->fRangeMin = m_Parameters[iParameterIndex].GetRangeMin();
00471     pstParameterDescription->fRangeMax = m_Parameters[iParameterIndex].GetRangeMax();
00472     pstParameterDescription->fDefaultValue = m_Parameters[iParameterIndex].GetDefaultValue();
00473     pstParameterDescription->fQuantizedTo = m_Parameters[iParameterIndex].GetQuantizedTo();
00474     pstParameterDescription->bIsChangeableInRealTime = m_Parameters[iParameterIndex].GetIsChangeableInRealTime();
00475     
00476     return FEAPI_kNoError;
00477 }
00478 
00479 
00480 FEAPI_Error_t      CFeatureExtractBase::SetPluginParameter (int iParameterIndex, float fValue)
00481 {
00482     // inherit me!
00483     return FEAPI_kUnknownError;
00484 }
00485 
00486 
00487 float       CFeatureExtractBase::GetPluginParameter (int iParameterIndex)
00488 {
00489     // inherit me!
00490     return -1;
00491 }
00492 
00493 
00494 FEAPI_Error_t      CFeatureExtractBase::ProcessPluginDone ()
00495 {
00496     // inherit me!
00497     return FEAPI_kNoError;
00498 }
00499 
00500 
00501 int         CFeatureExtractBase::GetPluginResultLatency (int iResultIndex)
00502 {
00503     // inherit me!
00504     return 0; 
00505 }
00506 
00507 
00508 FEAPI_Error_t      CFeatureExtractBase::ResetPlugin ()
00509 {
00510     // inherit me!
00511     return FEAPI_kNoError;
00512 }
00513 
00514 
00516 // CFeatureExtractBase implementation: helper methods
00518     
00519 void CFeatureExtractBase::SetPluginInputPinInfo(const CPin& PinInfo)
00520 {
00521     m_Inputs[PinInfo.GetIndex()] = PinInfo;
00522 }
00523 
00524 void CFeatureExtractBase::SetPluginResultPinInfo(const CPin& PinInfo)
00525 {
00526     m_Results[PinInfo.GetIndex()] = PinInfo;
00527 }
00528     
00529 void CFeatureExtractBase::SetPluginParameterPinInfo(const CPin& PinInfo)
00530 {
00531     m_Parameters[PinInfo.GetIndex()] = PinInfo;
00532 }
00533 

Generated on Fri Mar 23 10:28:54 2007 for FEAPI Plugin Documentation by  doxygen 1.3.9.1