NOOP, remove trailing tabs/whitespace.
[ardour.git] / libs / qm-dsp / dsp / phasevocoder / PhaseVocoder.cpp
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     QM DSP Library
5
6     Centre for Digital Music, Queen Mary, University of London.
7     This file 2005-2006 Christian Landone.
8
9     This program is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License as
11     published by the Free Software Foundation; either version 2 of the
12     License, or (at your option) any later version.  See the file
13     COPYING included with this distribution for more information.
14 */
15
16 #include "PhaseVocoder.h"
17 #include "dsp/transforms/FFT.h"
18 #include <math.h>
19
20 //////////////////////////////////////////////////////////////////////
21 // Construction/Destruction
22 //////////////////////////////////////////////////////////////////////
23
24 PhaseVocoder::PhaseVocoder(unsigned int n) :
25     m_n(n)
26 {
27     m_fft = new FFTReal(m_n);
28     m_realOut = new double[m_n];
29     m_imagOut = new double[m_n];
30 }
31
32 PhaseVocoder::~PhaseVocoder()
33 {
34     delete [] m_realOut;
35     delete [] m_imagOut;
36     delete m_fft;
37 }
38
39 void PhaseVocoder::FFTShift(unsigned int size, double *src)
40 {
41     const int hs = size/2;
42     for (int i = 0; i < hs; ++i) {
43         double tmp = src[i];
44         src[i] = src[i + hs];
45         src[i + hs] = tmp;
46     }
47 }
48
49 void PhaseVocoder::process(double *src, double *mag, double *theta)
50 {
51     FFTShift( m_n, src);
52
53     m_fft->process(0, src, m_realOut, m_imagOut);
54
55     getMagnitude( m_n/2, mag, m_realOut, m_imagOut);
56     getPhase( m_n/2, theta, m_realOut, m_imagOut);
57 }
58
59 void PhaseVocoder::getMagnitude(unsigned int size, double *mag, double *real, double *imag)
60 {
61     unsigned int j;
62
63     for( j = 0; j < size; j++)
64     {
65         mag[ j ] = sqrt( real[ j ] * real[ j ] + imag[ j ] * imag[ j ]);
66     }
67 }
68
69 void PhaseVocoder::getPhase(unsigned int size, double *theta, double *real, double *imag)
70 {
71     unsigned int k;
72
73     // Phase Angle "matlab" style
74     //Watch out for quadrant mapping  !!!
75     for( k = 0; k < size; k++)
76     {
77         theta[ k ] = atan2( -imag[ k ], real[ k ]);
78     }
79 }