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

FEAPIExamplePluginLoudness/zplFFT_If.cpp

Go to the documentation of this file.
00001 
00002 //     /*! \file zplFFT_If.cpp: \brief interface of the CzplFFT_If class. */
00003 //
00004 //        Copyright (c) 2004-2006  
00005 //        zplane.development
00006 //        Flohrer Lerch Schwerdtfeger GbR
00007 //        All rights reserved.
00008 //
00009 //    This program is free software; you can redistribute it and/or modify
00010 //    it under the terms of the GNU General Public License as published by
00011 //    the Free Software Foundation; either version 2 of the License, or
00012 //    (at your option) any later version.
00013 //
00014 //    This program is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //    GNU General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU General Public License
00020 //    along with this program; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00024 
00025 #include <string.h>
00026 #include <math.h>
00027 
00028 #include "zplVecLib.h"
00029 
00030 #if !defined(_2PI)
00031 #define _2PI                    (float)(6.283185307179586476925286766559)    
00032 #endif
00033 
00034 void CzplfFFT_If::CalculateWindow (_Fft_Windows_ eWindowType)
00035 {
00036     int i = 0;
00037 
00038     ZASSERT (!m_pfWindow);
00039     ZASSERT (m_iBlockLength < 4);
00040 
00041     switch (eWindowType)   
00042     {
00043     default:
00044     case _RECT:
00045         {
00046             for (i = 0; i < m_iBlockLength; i++)
00047                 m_pfWindow[i]   = 1.0F;
00048             break;
00049         }
00050     case _HANNING:
00051         {
00052             // note that this is symmetric, not periodic!
00053             for (i = 0; i < m_iBlockLength; i++)
00054                 m_pfWindow[i]   = .5F * (1.0F - cosf (_2PI * (i+1) / (m_iBlockLength+1)));
00055             break;
00056         }
00057     case _HAMMING:
00058         {
00059             // note that this is symmetric, not periodic!
00060             for (i = 0; i < m_iBlockLength; i++)
00061                 m_pfWindow[i]   = .54F - .46F * cosf (_2PI * i / (m_iBlockLength-1));
00062             break;
00063         }
00064     case _BLACKMAN:
00065         {
00066             // note that this is symmetric, not periodic!
00067             for (i = 0; i < m_iBlockLength; i++)
00068                 m_pfWindow[i]   = .42F - .5F * cosf (_2PI * i / (m_iBlockLength-1)) + .08F * cosf (2*_2PI * i / (m_iBlockLength-1));
00069             break;
00070         }
00071     case _BARTLETT:
00072         {
00073             // note that this is symmetric, not periodic!
00074             for (i = 0; i < (m_iBlockLength>>1); i++)
00075             {
00076                 m_pfWindow[i]                       =  1 - (-i + (m_iBlockLength-1)*.5F) / (.5F*(m_iBlockLength-1));
00077                 m_pfWindow[m_iBlockLength - 1 - i]  = m_pfWindow[i];
00078             }
00079             break;
00080         }
00081     case _WELCH:
00082         {
00083             // note that this is symmetric, not periodic!
00084             for (i = 0; i < (m_iBlockLength>>1); i++)
00085             {
00086                 m_pfWindow[i]                       =  1 - (-i + (m_iBlockLength-1)*.5F) / (.5F*(m_iBlockLength-1));
00087                 m_pfWindow[i]                      *= m_pfWindow[i];
00088                 m_pfWindow[m_iBlockLength - 1 - i]  = m_pfWindow[i];
00089             }
00090             break;
00091         }
00092     }
00093 }
00094 
00095 unsigned int CzplfFFT_If::Log2 (int iValueAsPowOf2)
00096 {
00097     unsigned int    iOrder = 0;
00098 
00099     while (iValueAsPowOf2>>iOrder)
00100         iOrder++;
00101 
00102     if (!(iValueAsPowOf2%(1<<(iOrder-1))))
00103         iOrder--;
00104     
00105     return iOrder;
00106 }
00107 
00108 int CzplfFFT_If::zplfGetWindow (float *pfWindow)
00109 {
00110     if (!pfWindow)
00111         return m_iBlockLength;
00112     else
00113     {
00114         memcpy (pfWindow, m_pfWindow, sizeof(float) * m_iBlockLength);
00115         return m_iBlockLength;
00116     }
00117 }

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