Mercurial > hg > qm-dsp
comparison dsp/phasevocoder/PhaseVocoder.cpp @ 289:befe5aa6b450
* Refactor FFT a little bit so as to separate construction and processing
rather than have a single static method -- will make it easier to use a
different implementation
* pull in KissFFT implementation (not hooked up yet)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 13 May 2009 09:19:12 +0000 |
parents | 9c403afdd9e9 |
children | e5907ae6de17 |
comparison
equal
deleted
inserted
replaced
288:86c70067c723 | 289:befe5aa6b450 |
---|---|
14 | 14 |
15 ////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////// |
16 // Construction/Destruction | 16 // Construction/Destruction |
17 ////////////////////////////////////////////////////////////////////// | 17 ////////////////////////////////////////////////////////////////////// |
18 | 18 |
19 PhaseVocoder::PhaseVocoder() | 19 PhaseVocoder::PhaseVocoder(unsigned int n) : |
20 m_n(n) | |
20 { | 21 { |
21 | 22 m_fft = new FFTReal(m_n); |
23 m_realOut = new double[m_n]; | |
24 m_imagOut = new double[m_n]; | |
22 } | 25 } |
23 | 26 |
24 PhaseVocoder::~PhaseVocoder() | 27 PhaseVocoder::~PhaseVocoder() |
25 { | 28 { |
26 | 29 delete [] m_realOut; |
30 delete [] m_imagOut; | |
31 delete m_fft; | |
27 } | 32 } |
28 | 33 |
29 void PhaseVocoder::FFTShift(unsigned int size, double *src) | 34 void PhaseVocoder::FFTShift(unsigned int size, double *src) |
30 { | 35 { |
31 const int hs = size/2; | 36 const int hs = size/2; |
34 src[i] = src[i + hs]; | 39 src[i] = src[i + hs]; |
35 src[i + hs] = tmp; | 40 src[i + hs] = tmp; |
36 } | 41 } |
37 } | 42 } |
38 | 43 |
39 void PhaseVocoder::process(unsigned int size, double *src, double *mag, double *theta) | 44 void PhaseVocoder::process(double *src, double *mag, double *theta) |
40 { | 45 { |
46 FFTShift( m_n, src); | |
47 | |
48 m_fft->process(0, src, m_realOut, m_imagOut); | |
41 | 49 |
42 // Primary Interface to Phase Vocoder | 50 getMagnitude( m_n/2, mag, m_realOut, m_imagOut); |
43 realOut = new double[ size ]; | 51 getPhase( m_n/2, theta, m_realOut, m_imagOut); |
44 imagOut = new double[ size ]; | |
45 | |
46 FFTShift( size, src); | |
47 | |
48 coreFFT( size, src, 0, realOut, imagOut); | |
49 | |
50 getMagnitude( size/2, mag, realOut, imagOut); | |
51 getPhase( size/2, theta, realOut, imagOut); | |
52 | |
53 delete [] realOut; | |
54 delete [] imagOut; | |
55 } | |
56 | |
57 | |
58 void PhaseVocoder::coreFFT( unsigned int NumSamples, double *RealIn, double* ImagIn, double *RealOut, double *ImagOut) | |
59 { | |
60 // This function is taken from a standard freeware implementation defined in FFT.h | |
61 // TODO: Use FFTW | |
62 FFT::process( NumSamples,0, RealIn, ImagIn, RealOut, ImagOut ); | |
63 } | 52 } |
64 | 53 |
65 void PhaseVocoder::getMagnitude(unsigned int size, double *mag, double *real, double *imag) | 54 void PhaseVocoder::getMagnitude(unsigned int size, double *mag, double *real, double *imag) |
66 { | 55 { |
67 unsigned int j; | 56 unsigned int j; |