1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
6 Centre for Digital Music, Queen Mary, University of London.
7 This file 2005-2006 Christian Landone.
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.
16 #include "PhaseVocoder.h"
17 #include "dsp/transforms/FFT.h"
20 //////////////////////////////////////////////////////////////////////
21 // Construction/Destruction
22 //////////////////////////////////////////////////////////////////////
24 PhaseVocoder::PhaseVocoder(unsigned int n
) :
27 m_fft
= new FFTReal(m_n
);
28 m_realOut
= new double[m_n
];
29 m_imagOut
= new double[m_n
];
32 PhaseVocoder::~PhaseVocoder()
39 void PhaseVocoder::FFTShift(unsigned int size
, double *src
)
41 const int hs
= size
/2;
42 for (int i
= 0; i
< hs
; ++i
) {
49 void PhaseVocoder::process(double *src
, double *mag
, double *theta
)
53 m_fft
->process(0, src
, m_realOut
, m_imagOut
);
55 getMagnitude( m_n
/2, mag
, m_realOut
, m_imagOut
);
56 getPhase( m_n
/2, theta
, m_realOut
, m_imagOut
);
59 void PhaseVocoder::getMagnitude(unsigned int size
, double *mag
, double *real
, double *imag
)
63 for( j
= 0; j
< size
; j
++)
65 mag
[ j
] = sqrt( real
[ j
] * real
[ j
] + imag
[ j
] * imag
[ j
]);
69 void PhaseVocoder::getPhase(unsigned int size
, double *theta
, double *real
, double *imag
)
73 // Phase Angle "matlab" style
74 //Watch out for quadrant mapping !!!
75 for( k
= 0; k
< size
; k
++)
77 theta
[ k
] = atan2( -imag
[ k
], real
[ k
]);