summaryrefslogtreecommitdiff
path: root/sms
diff options
context:
space:
mode:
authorJohn Glover <glover.john@gmail.com>2011-01-03 21:30:00 +0000
committerJohn Glover <glover.john@gmail.com>2011-01-03 21:30:00 +0000
commitf7831a5824e5fe7bd503217b8042d176603d02cc (patch)
tree5c1ed9af10f0db2ae61a1de3391e422e3219a91b /sms
parent351526f26a4d2602c43e64767f98e86d5af83e64 (diff)
downloadsimpl-f7831a5824e5fe7bd503217b8042d176603d02cc.tar.gz
simpl-f7831a5824e5fe7bd503217b8042d176603d02cc.tar.bz2
simpl-f7831a5824e5fe7bd503217b8042d176603d02cc.zip
Whitespace fixes
Diffstat (limited to 'sms')
-rw-r--r--sms/windows.c310
1 files changed, 136 insertions, 174 deletions
diff --git a/sms/windows.c b/sms/windows.c
index 8d715af..46ca5be 100644
--- a/sms/windows.c
+++ b/sms/windows.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2008 MUSIC TECHNOLOGY GROUP (MTG)
- * UNIVERSITAT POMPEU FABRA
+ * UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+
/*! \file windows.c
* \brief functions for creating various windows
*
@@ -25,7 +26,6 @@
*/
#include "sms.h"
-
/* \brief scale a window by its integral (numeric quadrature)
*
* In order to get a normalized magnitude spectrum (ex. Fourier analysis
@@ -36,24 +36,19 @@
* \param sizeWindow the size of the window
* \param pWindow pointer to an array that will hold the window
*/
-void sms_scaleWindow ( int sizeWindow, sfloat *pWindow)
+void sms_scaleWindow(int sizeWindow, sfloat *pWindow)
{
+ int i;
+ sfloat fSum = 0;
+ sfloat fScale;
- int i;
- sfloat fSum = 0;
- sfloat fScale;
-
- for(i = 0; i < sizeWindow; i++)
- fSum += pWindow[i];
+ for(i = 0; i < sizeWindow; i++)
+ fSum += pWindow[i];
-/* fSum = fSum / 2; */
-/* for(i = 0; i < sizeWindow; i++) */
-/* pWindow[i] /= fSum; */
+ fScale = 2. / fSum;
- fScale = 2. / fSum;
-
- for(i = 0; i < sizeWindow; i++)
- pWindow[i] *= fScale;
+ for(i = 0; i < sizeWindow; i++)
+ pWindow[i] *= fScale;
}
/*! \brief window to be used in the IFFT synthesis
@@ -65,31 +60,30 @@ void sms_scaleWindow ( int sizeWindow, sfloat *pWindow)
* \param sizeWindow the size of the window
* \param pFWindow pointer to an array that will hold the window
*/
-void IFFTwindow (int sizeWindow, sfloat *pFWindow)
+void IFFTwindow(int sizeWindow, sfloat *pFWindow)
{
+ int i;
+ sfloat a0 = .35875, a1 = .48829, a2 = .14128, a3 = .01168;
+ double fConst = TWO_PI / sizeWindow, fIncr = 2.0 /sizeWindow, fVal = 0;
- int i;
- sfloat a0 = .35875, a1 = .48829, a2 = .14128, a3 = .01168;
- double fConst = TWO_PI / sizeWindow, fIncr = 2.0 /sizeWindow, fVal = 0;
+ /* compute inverse of Blackman-Harris 92dB window */
+ for(i = 0; i < sizeWindow; i++)
+ {
+ pFWindow[i] = 1 / (a0 - a1 * cos(fConst * i) +
+ a2 * cos(fConst * 2 * i) - a3 * cos(fConst * 3 * i));
+ }
- /* compute inverse of Blackman-Harris 92dB window */
- for(i = 0; i < sizeWindow; i++)
- {
- pFWindow[i] = 1 / (a0 - a1 * cos(fConst * i) +
- a2 * cos(fConst * 2 * i) - a3 * cos(fConst * 3 * i));
- }
-
- /* scale function by a triangular */
- for (i = 0; i < sizeWindow / 2; i++)
- {
- pFWindow[i] = fVal * pFWindow[i] / 2.787457;
- fVal += fIncr;
- }
- for (i = sizeWindow / 2; i < sizeWindow; i++)
- {
- pFWindow[i] = fVal * pFWindow[i] / 2.787457;
- fVal -= fIncr;
- }
+ /* scale function by a triangular */
+ for(i = 0; i < sizeWindow / 2; i++)
+ {
+ pFWindow[i] = fVal * pFWindow[i] / 2.787457;
+ fVal += fIncr;
+ }
+ for(i = sizeWindow / 2; i < sizeWindow; i++)
+ {
+ pFWindow[i] = fVal * pFWindow[i] / 2.787457;
+ fVal -= fIncr;
+ }
}
/*! \brief BlackmanHarris window with 62dB rolloff
@@ -98,27 +92,20 @@ void IFFTwindow (int sizeWindow, sfloat *pFWindow)
* \param sizeWindow the size of the window
* \param pFWindow pointer to an array that will hold the window
*/
-void BlackmanHarris62 (int sizeWindow, sfloat *pFWindow)
+void BlackmanHarris62(int sizeWindow, sfloat *pFWindow)
{
- int i;
- double fSum = 0;
- /* for 3 term -62.05 */
- sfloat a0 = .44959, a1 = .49364, a2 = .05677;
- double fConst = TWO_PI / sizeWindow;
-
- /* compute window */
- for(i = 0; i < sizeWindow; i++)
- {
- fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
- a2 * cos(fConst * 2 * i);
- }
+ int i;
+ double fSum = 0;
+ /* for 3 term -62.05 */
+ sfloat a0 = .44959, a1 = .49364, a2 = .05677;
+ double fConst = TWO_PI / sizeWindow;
- /* I do not know why I now need this factor of two */
-/* fSum = fSum / 2; */
-
-/* /\* scale function *\/ */
-/* for (i = 0; i < sizeWindow; i++) */
-/* pFWindow[i] = pFWindow[i] / fSum; */
+ /* compute window */
+ for(i = 0; i < sizeWindow; i++)
+ {
+ fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
+ a2 * cos(fConst * 2 * i);
+ }
}
/*! \brief BlackmanHarris window with 70dB rolloff
@@ -126,28 +113,20 @@ void BlackmanHarris62 (int sizeWindow, sfloat *pFWindow)
* \param sizeWindow the size of the window
* \param pFWindow pointer to an array that will hold the window
*/
-void BlackmanHarris70 (int sizeWindow, sfloat *pFWindow)
+void BlackmanHarris70(int sizeWindow, sfloat *pFWindow)
{
- int i;
- double fSum = 0;
- /* for 3 term -70.83 */
- sfloat a0 = .42323, a1 = .49755, a2 = .07922;
- double fConst = TWO_PI / sizeWindow;
-
- /* compute window */
- for(i = 0; i < sizeWindow; i++)
- {
- fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
- a2 * cos(fConst * 2 * i);
- }
+ int i;
+ double fSum = 0;
+ /* for 3 term -70.83 */
+ sfloat a0 = .42323, a1 = .49755, a2 = .07922;
+ double fConst = TWO_PI / sizeWindow;
-/* fSum = fSum / 2; */
-
-/* /\* scale function *\/ */
-/* for (i = 0; i < sizeWindow; i++) */
-/* { */
-/* pFWindow[i] = pFWindow[i] / fSum; */
-/* } */
+ /* compute window */
+ for(i = 0; i < sizeWindow; i++)
+ {
+ fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
+ a2 * cos(fConst * 2 * i);
+ }
}
/*! \brief BlackmanHarris window with 74dB rolloff
@@ -155,27 +134,20 @@ void BlackmanHarris70 (int sizeWindow, sfloat *pFWindow)
* \param sizeWindow the size of the window
* \param pFWindow pointer to an array that will hold the window
*/
-void BlackmanHarris74 (int sizeWindow, sfloat *pFWindow)
+void BlackmanHarris74(int sizeWindow, sfloat *pFWindow)
{
- int i;
- double fSum = 0;
- /* for -74dB from the Nuttall paper */
- sfloat a0 = .40217, a1 = .49703, a2 = .09892, a3 = .00188;
- double fConst = TWO_PI / sizeWindow;
-
- /* compute window */
- for(i = 0; i < sizeWindow; i++)
- {
- fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
- a2 * cos(fConst * 2 * i) + a3 * cos(fConst * 3 * i);
- }
+ int i;
+ double fSum = 0;
+ /* for -74dB from the Nuttall paper */
+ sfloat a0 = .40217, a1 = .49703, a2 = .09892, a3 = .00188;
+ double fConst = TWO_PI / sizeWindow;
- /* I do not know why I now need this factor of two */
-/* fSum = fSum / 2; */
-
-/* /\* scale function *\/ */
-/* for (i = 0; i < sizeWindow; i++) */
-/* pFWindow[i] = pFWindow[i] / fSum; */
+ /* compute window */
+ for(i = 0; i < sizeWindow; i++)
+ {
+ fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
+ a2 * cos(fConst * 2 * i) + a3 * cos(fConst * 3 * i);
+ }
}
/*! \brief BlackmanHarris window with 92dB rolloff
@@ -183,26 +155,20 @@ void BlackmanHarris74 (int sizeWindow, sfloat *pFWindow)
* \param sizeWindow the size of the window
* \param pFWindow pointer to an array that will hold the window
*/
-void BlackmanHarris92 (int sizeWindow, sfloat *pFWindow)
+void BlackmanHarris92(int sizeWindow, sfloat *pFWindow)
{
- int i;
- double fSum = 0;
- /* for -92dB */
- sfloat a0 = .35875, a1 = .48829, a2 = .14128, a3 = .01168;
- double fConst = TWO_PI / sizeWindow;
-
- /* compute window */
- for(i = 0; i < sizeWindow; i++)
- {
- fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
- a2 * cos(fConst * 2 * i) + a3 * cos(fConst * 3 * i);
- }
+ int i;
+ double fSum = 0;
+ /* for -92dB */
+ sfloat a0 = .35875, a1 = .48829, a2 = .14128, a3 = .01168;
+ double fConst = TWO_PI / sizeWindow;
- /* I do not know why I now need this factor of two */
-/* fSum = fSum / 2; */
-/* /\* scale function *\/ */
-/* for (i = 0; i < sizeWindow; i++) */
-/* pFWindow[i] = pFWindow[i] / fSum; */
+ /* compute window */
+ for(i = 0; i < sizeWindow; i++)
+ {
+ fSum += pFWindow[i] = a0 - a1 * cos(fConst * i) +
+ a2 * cos(fConst * 2 * i) + a3 * cos(fConst * 3 * i);
+ }
}
/*! \brief default BlackmanHarris window (70dB rolloff)
@@ -210,44 +176,37 @@ void BlackmanHarris92 (int sizeWindow, sfloat *pFWindow)
* \param sizeWindow the size of the window
* \param pFWindow pointer to an array that will hold the window
*/
-void BlackmanHarris (int sizeWindow, sfloat *pFWindow)
+void BlackmanHarris(int sizeWindow, sfloat *pFWindow)
{
- BlackmanHarris70 (sizeWindow, pFWindow);
+ BlackmanHarris70(sizeWindow, pFWindow);
}
/*! \brief Hamming window
*
- *
- *
- * \param sizeWindow window size
- * \param pWindow window array
+ * \param sizeWindow window size
+ * \param pWindow window array
*/
-void Hamming (int sizeWindow, sfloat *pWindow)
+void Hamming(int sizeWindow, sfloat *pWindow)
{
- int i;
- sfloat fSum = 0;
-
- for(i = 0; i < sizeWindow; i++)
- {
- fSum += pWindow[i] = 0.53836 - 0.46164*cos(TWO_PI*i/(sizeWindow-1));
- }
+ int i;
+ sfloat fSum = 0;
- //ScaleWindow(sizeWindow, pWindow);
-/* fSum = fSum / 2; */
-/* for(i = 0; i < sizeWindow; i++) */
-/* pFWindow[i] /= fSum; */
+ for(i = 0; i < sizeWindow; i++)
+ {
+ fSum += pWindow[i] = 0.53836 - 0.46164*cos(TWO_PI*i/(sizeWindow-1));
+ }
}
/*! \brief Hanning window
*
- * \param sizeWindow window size
- * \param pWindow window array
+ * \param sizeWindow window size
+ * \param pWindow window array
*/
-void Hanning (int sizeWindow, sfloat *pWindow)
+void Hanning(int sizeWindow, sfloat *pWindow)
{
- int i;
- for(i = 0; i < sizeWindow; i++)
- pWindow[i] = (sin(PI*i/(sizeWindow-1)))*(sin(PI*i/(sizeWindow-1)));
+ int i;
+ for(i = 0; i < sizeWindow; i++)
+ pWindow[i] = (sin(PI*i/(sizeWindow-1)))*(sin(PI*i/(sizeWindow-1)));
}
/*! \brief main function for getting various windows
@@ -255,38 +214,38 @@ void Hanning (int sizeWindow, sfloat *pWindow)
* \todo note on window scales
*
* \see SMS_WINDOWS for the different window types available
- * \param sizeWindow window size
- * \param pFWindow window array
+ * \param sizeWindow window size
+ * \param pFWindow window array
* \param iWindowType the desired window type defined by #SMS_WINDOWS
*/
-void sms_getWindow (int sizeWindow, sfloat *pFWindow, int iWindowType)
+void sms_getWindow(int sizeWindow, sfloat *pFWindow, int iWindowType)
{
- switch (iWindowType)
- {
+ switch(iWindowType)
+ {
case SMS_WIN_BH_62:
- BlackmanHarris62 (sizeWindow, pFWindow);
- break;
+ BlackmanHarris62(sizeWindow, pFWindow);
+ break;
case SMS_WIN_BH_70:
- BlackmanHarris70 (sizeWindow, pFWindow);
- break;
+ BlackmanHarris70(sizeWindow, pFWindow);
+ break;
case SMS_WIN_BH_74:
- BlackmanHarris74 (sizeWindow, pFWindow);
- break;
+ BlackmanHarris74(sizeWindow, pFWindow);
+ break;
case SMS_WIN_BH_92:
- BlackmanHarris92 (sizeWindow, pFWindow);
- break;
+ BlackmanHarris92(sizeWindow, pFWindow);
+ break;
case SMS_WIN_HAMMING:
- Hamming (sizeWindow, pFWindow);
- break;
+ Hamming(sizeWindow, pFWindow);
+ break;
case SMS_WIN_HANNING:
- Hanning (sizeWindow, pFWindow);
- break;
+ Hanning(sizeWindow, pFWindow);
+ break;
case SMS_WIN_IFFT:
- IFFTwindow (sizeWindow, pFWindow);
- break;
+ IFFTwindow(sizeWindow, pFWindow);
+ break;
default:
- BlackmanHarris (sizeWindow, pFWindow);
- }
+ BlackmanHarris(sizeWindow, pFWindow);
+ }
}
/*! \brief apply a window and center around sample 0
@@ -298,21 +257,24 @@ void sms_getWindow (int sizeWindow, sfloat *pFWindow, int iWindowType)
*
* \todo do I need to garuntee that sizeWindow is odd-lengthed?
*
- * \param sizeWindow size of waveform/waveform
- * \param pWaveform pointer to waveform
- * \param pWindow pointer to window
- * \param sizeFft size of FFT
- * \param pFftBuffer pointer to FFT buffer
+ * \param sizeWindow size of waveform/waveform
+ * \param pWaveform pointer to waveform
+ * \param pWindow pointer to window
+ * \param sizeFft size of FFT
+ * \param pFftBuffer pointer to FFT buffer
*/
-void sms_windowCentered (int sizeWindow, sfloat *pWaveform, sfloat *pWindow, int sizeFft, sfloat *pFftBuffer)
+void sms_windowCentered(int sizeWindow, sfloat *pWaveform, sfloat *pWindow,
+ int sizeFft, sfloat *pFftBuffer)
{
- int i, iOffset, iMiddleWindow;
-
- iMiddleWindow = (sizeWindow+1) >> 1;
- iOffset = sizeFft - (iMiddleWindow - 1);
- for (i=0; i<iMiddleWindow-1; i++)
- pFftBuffer[iOffset + i] = pWindow[i] * pWaveform[i];
- iOffset = iMiddleWindow - 1;
- for (i=0; i<iMiddleWindow; i++)
- pFftBuffer[i] = pWindow[iOffset + i] * pWaveform[iOffset + i];
+ int iMiddleWindow = (sizeWindow+1) >> 1;
+ int iOffset = sizeFft - (iMiddleWindow - 1);
+ int i;
+
+ for(i=0; i<iMiddleWindow-1; i++)
+ pFftBuffer[iOffset + i] = pWindow[i] * pWaveform[i];
+
+ iOffset = iMiddleWindow - 1;
+
+ for(i=0; i<iMiddleWindow; i++)
+ pFftBuffer[i] = pWindow[iOffset + i] * pWaveform[iOffset + i];
}