Mercurial > hg > x
comparison quickspec.cpp @ 11:977f541d6683
GPL and cosmetic changes
author | Wen X <xue.wen@elec.qmul.ac.uk> |
---|---|
date | Wed, 10 Aug 2011 12:33:35 +0100 |
parents | 9b1c0825cc77 |
children |
comparison
equal
deleted
inserted
replaced
10:c6528c38b23c | 11:977f541d6683 |
---|---|
1 /* | |
2 Harmonic sinusoidal modelling and tools | |
3 | |
4 C++ code package for harmonic sinusoidal modelling and relevant signal processing. | |
5 Centre for Digital Music, Queen Mary, University of London. | |
6 This file copyright 2011 Wen Xue. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. | |
12 */ | |
1 //--------------------------------------------------------------------------- | 13 //--------------------------------------------------------------------------- |
2 #include <math.h> | 14 #include <math.h> |
3 #include <memory.h> | 15 #include <memory.h> |
4 #include "quickspec.h" | 16 #include "quickspec.h" |
5 | 17 |
121 | 133 |
122 No return value. | 134 No return value. |
123 */ | 135 */ |
124 void CalculateSpectrum(void* Data, int BytesPerSample, double* win, QSPEC_FORMAT* Amp, QSPEC_FORMAT* Arg, int Wid, cdouble* w, cdouble* x, int* hbi) | 136 void CalculateSpectrum(void* Data, int BytesPerSample, double* win, QSPEC_FORMAT* Amp, QSPEC_FORMAT* Arg, int Wid, cdouble* w, cdouble* x, int* hbi) |
125 { | 137 { |
126 if (BytesPerSample==2) RFFTCW((__int16*)Data, win, 0, 0, log2(Wid), w, x, hbi); | 138 if (BytesPerSample==2) RFFTCW((__int16*)Data, win, 0, 0, Log2(Wid), w, x, hbi); |
127 else {IntToDouble((double*)x, Data, BytesPerSample, Wid); RFFTCW((double*)x, win, 0, 0, log2(Wid), w, x, hbi);} | 139 else {IntToDouble((double*)x, Data, BytesPerSample, Wid); RFFTCW((double*)x, win, 0, 0, Log2(Wid), w, x, hbi);} |
128 for (int j=0; j<=Wid/2; j++) | 140 for (int j=0; j<=Wid/2; j++) |
129 { | 141 { |
130 Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y); | 142 Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y); |
131 if (Arg) Arg[j]=(x[j].y==0 && x[j].x==0)?0:atan2(x[j].y, x[j].x); | 143 if (Arg) Arg[j]=(x[j].y==0 && x[j].x==0)?0:atan2(x[j].y, x[j].x); |
132 } | 144 } |
155 } | 167 } |
156 else if (eff<Wid) | 168 else if (eff<Wid) |
157 { | 169 { |
158 double* doublex=(double*)x; | 170 double* doublex=(double*)x; |
159 IntToDouble(doublex, Data, BytesPerSample, eff); memset(&doublex[eff], 0, sizeof(double)*(Wid-eff)); | 171 IntToDouble(doublex, Data, BytesPerSample, eff); memset(&doublex[eff], 0, sizeof(double)*(Wid-eff)); |
160 RFFTCW(doublex, win, 0, 0, log2(Wid), w, x, hbi); | 172 RFFTCW(doublex, win, 0, 0, Log2(Wid), w, x, hbi); |
161 for (int j=0; j<=Wid/2; j++) | 173 for (int j=0; j<=Wid/2; j++) |
162 { | 174 { |
163 Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y); | 175 Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y); |
164 if (Arg) Arg[j]=(x[j].y==0 && x[j].x==0)?0:atan2(x[j].y, x[j].x); | 176 if (Arg) Arg[j]=(x[j].y==0 && x[j].x==0)?0:atan2(x[j].y, x[j].x); |
165 } | 177 } |
188 if (Wid!=fWid) | 200 if (Wid!=fWid) |
189 { //then update internal buffers to the new window size | 201 { //then update internal buffers to the new window size |
190 free8(fw); free(fhbi); | 202 free8(fw); free(fhbi); |
191 fw=(cdouble*)malloc8(sizeof(cdouble)*Wid*1.5); SetTwiddleFactors(Wid, fw); | 203 fw=(cdouble*)malloc8(sizeof(cdouble)*Wid*1.5); SetTwiddleFactors(Wid, fw); |
192 fx=&fw[Wid/2]; | 204 fx=&fw[Wid/2]; |
193 fhbi=CreateBitInvTable(log2(Wid)-1); | 205 fhbi=CreateBitInvTable(Log2(Wid)-1); |
194 } | 206 } |
195 if (Wid!=fWid || WinType!=fwt || WinParam!=fwdp) | 207 if (Wid!=fWid || WinType!=fwt || WinParam!=fwdp) |
196 { //then update internal window function to the new window type | 208 { //then update internal window function to the new window type |
197 fwin=NewWindow8(WinType, Wid, 0, &WinParam); | 209 fwin=NewWindow8(WinType, Wid, 0, &WinParam); |
198 fwt=WinType; fwdp=WinParam; | 210 fwt=WinType; fwdp=WinParam; |