comparison layer/SpectrogramLayer.cpp @ 75:dfdbf336bb37

* Remove dsp directory. This is now the qm-dsp library used by qm-vamp-plugins instead of being used in Sonic Visualiser directly. * Remove plugins that have now become part of qm-vamp-plugins. * Move time stretcher from dsp to audioio (this is the one DSP thing we do need in SV)
author Chris Cannam
date Thu, 06 Apr 2006 12:12:41 +0000
parents 72fa239a4880
children fd348f36c0d3
comparison
equal deleted inserted replaced
74:195ad6178ef8 75:dfdbf336bb37
19 #include "base/Profiler.h" 19 #include "base/Profiler.h"
20 #include "base/AudioLevel.h" 20 #include "base/AudioLevel.h"
21 #include "base/Window.h" 21 #include "base/Window.h"
22 #include "base/Pitch.h" 22 #include "base/Pitch.h"
23 23
24 #include "dsp/maths/MathUtilities.h"
25
26 #include <QPainter> 24 #include <QPainter>
27 #include <QImage> 25 #include <QImage>
28 #include <QPixmap> 26 #include <QPixmap>
29 #include <QRect> 27 #include <QRect>
30 #include <QTimer> 28 #include <QTimer>
33 31
34 #include <cassert> 32 #include <cassert>
35 #include <cmath> 33 #include <cmath>
36 34
37 //#define DEBUG_SPECTROGRAM_REPAINT 1 35 //#define DEBUG_SPECTROGRAM_REPAINT 1
36
37 static double mod(double x, double y)
38 {
39 double a = floor(x / y);
40 double b = x - (y * a);
41 return b;
42 }
43
44 static double princarg(double ang)
45 {
46 return mod(ang + M_PI, -2 * M_PI) + M_PI;
47 }
38 48
39 49
40 SpectrogramLayer::SpectrogramLayer(Configuration config) : 50 SpectrogramLayer::SpectrogramLayer(Configuration config) :
41 Layer(), 51 Layer(),
42 m_model(0), 52 m_model(0),
1026 float frequency = (float(bin) * sampleRate) / windowSize; 1036 float frequency = (float(bin) * sampleRate) / windowSize;
1027 1037
1028 float expectedPhase = 1038 float expectedPhase =
1029 oldPhase + (2.0 * M_PI * bin * windowIncrement) / windowSize; 1039 oldPhase + (2.0 * M_PI * bin * windowIncrement) / windowSize;
1030 1040
1031 float phaseError = MathUtilities::princarg(newPhase - expectedPhase); 1041 float phaseError = princarg(newPhase - expectedPhase);
1032 1042
1033 if (fabs(phaseError) < (1.1 * (windowIncrement * M_PI) / windowSize)) { 1043 if (fabs(phaseError) < (1.1 * (windowIncrement * M_PI) / windowSize)) {
1034 1044
1035 // The new frequency estimate based on the phase error 1045 // The new frequency estimate based on the phase error
1036 // resulting from assuming the "native" frequency of this bin 1046 // resulting from assuming the "native" frequency of this bin
1113 mag /= windowSize / 2; 1123 mag /= windowSize / 2;
1114 1124
1115 if (mag > factor) factor = mag; 1125 if (mag > factor) factor = mag;
1116 1126
1117 double phase = atan2(output[i][1], output[i][0]); 1127 double phase = atan2(output[i][1], output[i][0]);
1118 phase = MathUtilities::princarg(phase); 1128 phase = princarg(phase);
1119 1129
1120 output[i][0] = mag; 1130 output[i][0] = mag;
1121 m_cache->setPhaseAt(column, i, phase); 1131 m_cache->setPhaseAt(column, i, phase);
1122 } 1132 }
1123 1133