Go to the documentation of this file.00001 #ifndef SPECTROGRAM_HPP
00002 #define SPECTROGRAM_HPP
00003
00008 #include <vector>
00009 #include <QImage>
00010 #include <QPixmap>
00011 #include <QSize>
00012 #include <QThread>
00013 #include <complex>
00014 #include <memory>
00015 #include "soundfile.hpp"
00016 #include "fft.hpp"
00017
00018 #include <QVector>
00019 #include <QRgb>
00020
00022
00040 class Palette
00041 {
00042 public:
00044 Palette();
00046
00051 Palette(const QImage& img);
00052
00054
00058 int get_color(float val) const;
00060
00061 float get_intensity(QRgb color) const;
00063 bool has_color(QRgb color) const;
00065
00069 QImage make_canvas(int width, int height) const;
00071
00072 bool indexable() const;
00074 QPixmap preview(int width, int height) const;
00076 int numColors() const;
00077 private:
00078 QVector<QRgb> colors_;
00079 };
00080
00081
00082
00084 enum Window
00085 {
00086 WINDOW_HANN,
00087 WINDOW_BLACKMAN,
00088 WINDOW_RECTANGULAR,
00089 WINDOW_TRIANGULAR
00090 };
00092 enum AxisScale {SCALE_LINEAR, SCALE_LOGARITHMIC};
00094 enum SynthesisType {SYNTHESIS_SINE, SYNTHESIS_NOISE};
00096 enum BrightCorrection {BRIGHT_NONE, BRIGHT_SQRT};
00097
00099 class Spectrogram : public QObject
00100 {
00101 Q_OBJECT
00102 public:
00103 Spectrogram(QObject* parent = 0);
00105 QImage to_image(real_vec& signal, int samplerate) const;
00107 real_vec synthetize(const QImage& image, int samplerate,
00108 SynthesisType type) const;
00110
00111 QString serialized() const;
00113 void deserialize(const QString& serialized);
00114
00116
00117 double bandwidth;
00119 double basefreq;
00121 double maxfreq;
00123 double overlap;
00125 double pixpersec;
00127 Window window;
00129 AxisScale intensity_axis;
00131 AxisScale frequency_axis;
00133 BrightCorrection correction;
00135 Palette palette;
00136 private:
00138 real_vec sine_synthesis(const QImage& image, int samplerate) const;
00140 real_vec noise_synthesis(const QImage& image, int samplerate) const;
00142 QImage make_image(const std::vector<real_vec>& data) const;
00144 real_vec envelope_from_spectrogram(const QImage& image, int row) const;
00146 void apply_window(complex_vec& chunk, int lowidx,
00147 double filterscale) const;
00149 static const char delimiter = ';';
00150 void band_progress(int x, int of, int from=0, int to=100) const;
00152 bool cancelled() const;
00153 mutable bool cancelled_;
00154 signals:
00156 void progress(int value) const;
00158 void status(const QString& text) const;
00159 public slots:
00161 void cancel();
00162 };
00163
00164
00165
00166 typedef std::pair<int,int> intpair;
00167
00169
00170 class Filterbank
00171 {
00172 public:
00173 static std::auto_ptr<Filterbank> get_filterbank(AxisScale type,
00174 double scale, double base, double hzbandwidth, double overlap);
00175
00176 Filterbank(double scale);
00178 virtual intpair get_band(int i) const = 0;
00180 virtual int get_center(int i) const = 0;
00182 virtual int num_bands_est(double maxfreq) const = 0;
00183 virtual ~Filterbank();
00184 protected:
00186 const double scale_;
00187 };
00188
00190 class LinearFilterbank : public Filterbank
00191 {
00192 public:
00193 LinearFilterbank(double scale, double base, double hzbandwidth,
00194 double overlap);
00195 intpair get_band(int i) const;
00196 int get_center(int i) const;
00197 int num_bands_est(double maxfreq) const;
00198 private:
00199 const double bandwidth_;
00200 const int startidx_;
00201 const double step_;
00202 };
00203
00205 class LogFilterbank : public Filterbank
00206 {
00207 public:
00208 LogFilterbank(double scale, double base, double centsperband,
00209 double overlap);
00210 intpair get_band(int i) const;
00211 int get_center(int i) const;
00212 int num_bands_est(double maxfreq) const;
00213 private:
00214 const double centsperband_;
00215 const double logstart_;
00216 const double logstep_;
00217 };
00218
00219 #endif