| 1 |
#ifndef _Spectrogram_extensions_h_ |
| 2 |
#define _Spectrogram_extensions_h_ |
| 3 |
/* Spectrogram_extensions.h |
| 4 |
* |
| 5 |
* Copyright (C) 2014-2023 David Weenink |
| 6 |
* |
| 7 |
* This code is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 10 |
* your option) any later version. |
| 11 |
* |
| 12 |
* This code is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 22 |
djmw 20140913 |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "Intensity.h" |
| 26 |
#include "MFCC.h" |
| 27 |
#include "PCA.h" |
| 28 |
#include "Spectrogram.h" |
| 29 |
#include "Spectrum.h" |
| 30 |
#include "TableOfReal.h" |
| 31 |
#include "NUM2.h" |
| 32 |
|
| 33 |
#define HZTOMEL(x) NUMhertzToMel2(x) |
| 34 |
#define MELTOHZ(x) NUMmelToHertz2(x) |
| 35 |
|
| 36 |
#define BandFilterSpectrogram_DBREF 4e-10 |
| 37 |
#define BandFilterSpectrogram_DBFAC 10 |
| 38 |
#define BandFilterSpectrogram_DBFLOOR -100 |
| 39 |
|
| 40 |
#define BandFilterSpectrogram_HERTZ 1 |
| 41 |
#define BandFilterSpectrogram_BARK 2 |
| 42 |
#define BandFilterSpectrogram_MEL 3 |
| 43 |
|
| 44 |
Thing_define (BandFilterSpectrogram, Matrix) { |
| 45 |
void v1_info () |
| 46 |
override; |
| 47 |
double v_getValueAtSample (integer icol, integer irow, int units) const |
| 48 |
override; |
| 49 |
|
| 50 |
virtual double v_frequencyToHertz (double f) { return f; } |
| 51 |
virtual double v_hertzToFrequency (double hertz) { return hertz; } |
| 52 |
virtual conststring32 v_getFrequencyUnit () { return U"Hz"; } |
| 53 |
}; |
| 54 |
|
| 55 |
Thing_define (BarkSpectrogram, BandFilterSpectrogram) { |
| 56 |
void v1_info () |
| 57 |
override; |
| 58 |
double v_frequencyToHertz (double f) |
| 59 |
override { return NUMbarkToHertz (f); } |
| 60 |
double v_hertzToFrequency (double hertz) |
| 61 |
override { return NUMhertzToBark (hertz); } |
| 62 |
conststring32 v_getFrequencyUnit () |
| 63 |
override { return U"bark"; } |
| 64 |
}; |
| 65 |
|
| 66 |
Thing_define (MelSpectrogram, BandFilterSpectrogram) { |
| 67 |
void v1_info () |
| 68 |
override; |
| 69 |
double v_frequencyToHertz (double f) |
| 70 |
override { return NUMmelToHertz2 (f); } |
| 71 |
double v_hertzToFrequency (double hertz) |
| 72 |
override { return NUMhertzToMel2 (hertz); } |
| 73 |
conststring32 v_getFrequencyUnit () |
| 74 |
override { return U"mel"; } |
| 75 |
}; |
| 76 |
|
| 77 |
/* |
| 78 |
Interpretation: |
| 79 |
xmin, xmax, x1, dx, nx like Sampled. |
| 80 |
ymin, ymax lowest and highest frequencies in Barks / Mel. |
| 81 |
y1 mid of first filter (bark/mel). |
| 82 |
dy distance between filters (bark/mel). |
| 83 |
ny the number of filters. |
| 84 |
*/ |
| 85 |
|
| 86 |
double BandFilterSpectrogram_getFrequencyInHertz (BandFilterSpectrogram me, double f); |
| 87 |
|
| 88 |
void BandFilterSpectrogram_equalizeIntensities (BandFilterSpectrogram me, double intensity_db); |
| 89 |
|
| 90 |
autoMatrix BandFilterSpectrogram_to_Matrix (BandFilterSpectrogram me, int to_dB); |
| 91 |
|
| 92 |
autoIntensity BandFilterSpectrogram_to_Intensity (BandFilterSpectrogram me); |
| 93 |
|
| 94 |
void BandFilterSpectrogram_drawFrequencyScale (BandFilterSpectrogram me, Graphics g, |
| 95 |
double xmin, double xmax, double ymin, double ymax, bool garnish); |
| 96 |
|
| 97 |
void BandFilterSpectrogram_drawTimeSlice (BandFilterSpectrogram me, Graphics g, double t, double fmin, double fmax, |
| 98 |
double min, double max, conststring32 xlabel, bool garnish); |
| 99 |
|
| 100 |
void BarkSpectrogram_drawSekeyHansonFilterFunctions (BarkSpectrogram me, Graphics g, bool xIsHertz, integer fromFilter, integer toFilter, |
| 101 |
double zmin, double zmax, bool yscale_dB, double ymin, double ymax, bool garnish); |
| 102 |
|
| 103 |
void BandFilterSpectrogram_drawSpectrumAtNearestTimeSlice (BandFilterSpectrogram me, Graphics g, |
| 104 |
double time, double fmin, double fmax, double dBmin, double dBmax, bool garnish); |
| 105 |
|
| 106 |
void BandFilterSpectrogram_paintImage (BandFilterSpectrogram me, Graphics g, |
| 107 |
double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, bool garnish); |
| 108 |
|
| 109 |
autoBarkSpectrogram BarkSpectrogram_create (double tmin, double tmax, integer nt, double dt, double t1, |
| 110 |
double fmin, double fmax, integer nf, double df, double f1); |
| 111 |
|
| 112 |
autoBarkSpectrogram Matrix_to_BarkSpectrogram (Matrix me); |
| 113 |
|
| 114 |
/* |
| 115 |
Interpretation: |
| 116 |
xmin, xmax, x1, dx, nx like Sampled. |
| 117 |
ymin, ymax lowest and highest frequencies in mels. |
| 118 |
y1 mid of first filter (mels). |
| 119 |
dy distance between filters (mel). |
| 120 |
ny the number of filters. |
| 121 |
*/ |
| 122 |
autoMelSpectrogram MelSpectrogram_create (double tmin, double tmax, integer nt, double dt, double t1, |
| 123 |
double fmin, double fmax, integer nf, double df, double f1); |
| 124 |
|
| 125 |
autoMelSpectrogram Matrix_to_MelSpectrogram (Matrix me); |
| 126 |
|
| 127 |
void MelSpectrogram_drawTriangularFilterFunctions (MelSpectrogram me, Graphics g, bool xIsHertz, integer fromFilter, integer toFilter, |
| 128 |
double zmin, double zmax, bool yscale_dB, double ymin, double ymax, bool garnish); |
| 129 |
|
| 130 |
autoMFCC MelSpectrogram_to_MFCC (MelSpectrogram me, integer numberOfCoefficients); |
| 131 |
|
| 132 |
autoMelSpectrogram MFCC_to_MelSpectrogram (MFCC me, integer first, integer last, bool c0); |
| 133 |
|
| 134 |
void BandFilterSpectrogram_and_PCA_drawComponent (BandFilterSpectrogram me, PCA thee, Graphics g, integer component, double dblevel, |
| 135 |
double frequencyOffset, double scale, double tmin, double tmax, double fmin, double fmax); |
| 136 |
|
| 137 |
autoMatrix Spectrogram_to_Matrix_dB (Spectrogram me, double reference, double scaleFactor, double floor_dB); |
| 138 |
// dbs = scaleFactor * log10 (value/reference); |
| 139 |
// if (dbs < floor_db) { dbs = floor_dB } |
| 140 |
|
| 141 |
void BandFilterSpectrogram_into_CC (BandFilterSpectrogram me, CC thee, integer numberOfCoefficients); |
| 142 |
|
| 143 |
void CC_into_BandFilterSpectrogram (CC me, BandFilterSpectrogram thee, integer first, integer last, bool use_c0); |
| 144 |
|
| 145 |
/* |
| 146 |
Implementation of Yanna Ma & Akinori Nishihara (2013), Efficient voice activity detection algorithm |
| 147 |
using long-term spectral flatness measure, EURASIP Journal on Audio, Speech, and Music Processing. |
| 148 |
*/ |
| 149 |
autoMatrix Spectrogram_getLongtermSpectralFlatness (Spectrogram me, double longtimeWindow, double shorttimeWindow, double fmin, double fmax); |
| 150 |
|
| 151 |
void Spectrogram_drawLongTermFlatness (Spectrogram me, Graphics g, double tmin, double tmax, double minimumFlatness_db, |
| 152 |
double longtimeWindow, double shorttimeWindow, double fmin, double fmax, bool garnish); |
| 153 |
|
| 154 |
#endif /* _Spectrogram_extensions_h_ */ |