| 1 | #cxx . . $ `<file>/dwtools/Spectrogram_extensions.h`/ifndef _Spectrogram_extensions_h_ |
| 2 | #define _Spectrogram_extensions_h_cxx . . $ `dwtools/Spectrogram_extensions.h:2:9`! |
| 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"cxx . . $ `<file>/fon/Intensity.h`/ |
| 26 | #include "MFCC.h"cxx . . $ `<file>/dwtools/MFCC.h`/ |
| 27 | #include "PCA.h"cxx . . $ `<file>/dwtools/PCA.h`/ |
| 28 | #include "Spectrogram.h"cxx . . $ `<file>/fon/Spectrogram.h`/ |
| 29 | #include "Spectrum.h"cxx . . $ `<file>/fon/Spectrum.h`/ |
| 30 | #include "TableOfReal.h"cxx . . $ `<file>/stat/TableOfReal.h`/ |
| 31 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 32 | |
| 33 | #define HZTOMELcxx . . $ `dwtools/Spectrogram_extensions.h:33:9`!(x) NUMhertzToMel2(x) |
| 34 | #define MELTOHZcxx . . $ `dwtools/Spectrogram_extensions.h:34:9`!(x) NUMmelToHertz2(x) |
| 35 | |
| 36 | #define BandFilterSpectrogram_DBREFcxx . . $ `dwtools/Spectrogram_extensions.h:36:9`! 4e-10 |
| 37 | #define BandFilterSpectrogram_DBFACcxx . . $ `dwtools/Spectrogram_extensions.h:37:9`! 10 |
| 38 | #define BandFilterSpectrogram_DBFLOORcxx . . $ `dwtools/Spectrogram_extensions.h:38:9`! -100 |
| 39 | |
| 40 | #define BandFilterSpectrogram_HERTZcxx . . $ `dwtools/Spectrogram_extensions.h:40:9`! 1 |
| 41 | #define BandFilterSpectrogram_BARKcxx . . $ `dwtools/Spectrogram_extensions.h:41:9`! 2 |
| 42 | #define BandFilterSpectrogram_MELcxx . . $ `dwtools/Spectrogram_extensions.h:42:9`! 3 |
| 43 | |
| 44 | Thing_definecxx . . $ autoSomeThing# (BandFilterSpectrogram, Matrix) { |
| 45 | void v1_infocxx . . $ structBandFilterSpectrogram#v1_info(49f6e7a06ebc5aa8). () |
| 46 | override; |
| 47 | double v_getValueAtSamplecxx . . $ structBandFilterSpectrogram#v_getValueAtSample(8bbfc6ce471470c9). (integercxx . . $ integer# icol, integercxx . . $ integer# irow, int units) const |
| 48 | override; |
| 49 | |
| 50 | virtual double v_frequencyToHertzcxx . . $ structBandFilterSpectrogram#v_frequencyToHertz(447c67c6676f75c3). (double f) { return f; } |
| 51 | virtual double v_hertzToFrequencycxx . . $ structBandFilterSpectrogram#v_hertzToFrequency(447c67c6676f75c3). (double hertz) { return hertz; } |
| 52 | virtual conststring32cxx . . $ conststring32# v_getFrequencyUnitcxx . . $ structBandFilterSpectrogram#v_getFrequencyUnit(1912f6684645c851). () { return U"Hz"; } |
| 53 | }; |
| 54 | |
| 55 | Thing_definecxx . . $ structBarkSpectrogram# (BarkSpectrogram, BandFilterSpectrogram) { |
| 56 | void v1_infocxx . . $ structBarkSpectrogram#v1_info(49f6e7a06ebc5aa8). () |
| 57 | override; |
| 58 | double v_frequencyToHertzcxx . . $ structBarkSpectrogram#v_frequencyToHertz(447c67c6676f75c3). (double f) |
| 59 | override { return NUMbarkToHertzcxx . . $ NUMbarkToHertz(447c67c6676f75c3). (f); } |
| 60 | double v_hertzToFrequencycxx . . $ structBarkSpectrogram#v_hertzToFrequency(447c67c6676f75c3). (double hertz) |
| 61 | override { return NUMhertzToBarkcxx . . $ NUMhertzToBark(447c67c6676f75c3). (hertz); } |
| 62 | conststring32cxx . . $ conststring32# v_getFrequencyUnitcxx . . $ structBarkSpectrogram#v_getFrequencyUnit(1912f6684645c851). () |
| 63 | override { return U"bark"; } |
| 64 | }; |
| 65 | |
| 66 | Thing_definecxx . . $ ClassInfo# (MelSpectrogram, BandFilterSpectrogram) { |
| 67 | void v1_infocxx . . $ structMelSpectrogram#v1_info(49f6e7a06ebc5aa8). () |
| 68 | override; |
| 69 | double v_frequencyToHertzcxx . . $ structMelSpectrogram#v_frequencyToHertz(447c67c6676f75c3). (double f) |
| 70 | override { return NUMmelToHertz2cxx . . $ NUMmelToHertz2(447c67c6676f75c3). (f); } |
| 71 | double v_hertzToFrequencycxx . . $ structMelSpectrogram#v_hertzToFrequency(447c67c6676f75c3). (double hertz) |
| 72 | override { return NUMhertzToMel2cxx . . $ NUMhertzToMel2(447c67c6676f75c3). (hertz); } |
| 73 | conststring32cxx . . $ conststring32# v_getFrequencyUnitcxx . . $ structMelSpectrogram#v_getFrequencyUnit(1912f6684645c851). () |
| 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_getFrequencyInHertzcxx . . $ BandFilterSpectrogram_getFrequencyInHertz(bed147db8ba82502). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, double f); |
| 87 | |
| 88 | void BandFilterSpectrogram_equalizeIntensitiescxx . . $ BandFilterSpectrogram_equalizeIntensities(a54df35b90308d66). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, double intensity_db); |
| 89 | |
| 90 | autoMatrixcxx . . $ autoMatrix# BandFilterSpectrogram_to_Matrixcxx . . $ BandFilterSpectrogram_to_Matrix(620d3198b4d77f06). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, int to_dB); |
| 91 | |
| 92 | autoIntensitycxx . . $ autoIntensity# BandFilterSpectrogram_to_Intensitycxx . . $ BandFilterSpectrogram_to_Intensity(651f1dca9b81a323). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me); |
| 93 | |
| 94 | void BandFilterSpectrogram_drawFrequencyScalecxx . . $ BandFilterSpectrogram_drawFrequencyScale(a67df6c9c6365edd). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, Graphicscxx . . $ Graphics# g, |
| 95 | double xmin, double xmax, double ymin, double ymax, bool garnish); |
| 96 | |
| 97 | void BandFilterSpectrogram_drawTimeSlicecxx . . $ BandFilterSpectrogram_drawTimeSlice(f56573e2cc3b6815). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, Graphicscxx . . $ Graphics# g, double t, double fmin, double fmax, |
| 98 | double min, double max, conststring32cxx . . $ conststring32# xlabel, bool garnish); |
| 99 | |
| 100 | void BarkSpectrogram_drawSekeyHansonFilterFunctionscxx . . $ BarkSpectrogram_drawSekeyHansonFilterFunctions(8f1397b53e5efd85). (BarkSpectrogramcxx . . $ BarkSpectrogram# me, Graphicscxx . . $ Graphics# g, bool xIsHertz, integercxx . . $ integer# fromFilter, integercxx . . $ integer# toFilter, |
| 101 | double zmin, double zmax, bool yscale_dB, double ymin, double ymax, bool garnish); |
| 102 | |
| 103 | void BandFilterSpectrogram_drawSpectrumAtNearestTimeSlicecxx . . $ BandFilterSpectrogram_drawSpectrumAtNearestTimeSlice(a7a35655369f09c5). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, Graphicscxx . . $ Graphics# g, |
| 104 | double time, double fmin, double fmax, double dBmin, double dBmax, bool garnish); |
| 105 | |
| 106 | void BandFilterSpectrogram_paintImagecxx . . $ BandFilterSpectrogram_paintImage(93c0f69c4b3234dc). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, Graphicscxx . . $ Graphics# g, |
| 107 | double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, bool garnish); |
| 108 | |
| 109 | autoBarkSpectrogramcxx . . $ autoBarkSpectrogram# BarkSpectrogram_createcxx . . $ BarkSpectrogram_create(b560be76b93ca01d). (double tmin, double tmax, integercxx . . $ integer# nt, double dt, double t1, |
| 110 | double fmin, double fmax, integercxx . . $ integer# nf, double df, double f1); |
| 111 | |
| 112 | autoBarkSpectrogramcxx . . $ autoBarkSpectrogram# Matrix_to_BarkSpectrogramcxx . . $ Matrix_to_BarkSpectrogram(ff8b2c423852bbef). (Matrixcxx . . $ 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 | autoMelSpectrogramcxx . . $ autoMelSpectrogram# MelSpectrogram_createcxx . . $ MelSpectrogram_create(ac799e7c17ea0a99). (double tmin, double tmax, integercxx . . $ integer# nt, double dt, double t1, |
| 123 | double fmin, double fmax, integercxx . . $ integer# nf, double df, double f1); |
| 124 | |
| 125 | autoMelSpectrogramcxx . . $ autoMelSpectrogram# Matrix_to_MelSpectrogramcxx . . $ Matrix_to_MelSpectrogram(38e636cc477c4127). (Matrixcxx . . $ Matrix# me); |
| 126 | |
| 127 | void MelSpectrogram_drawTriangularFilterFunctionscxx . . $ MelSpectrogram_drawTriangularFilterFunctions(6e3c0a4d25e55f81). (MelSpectrogramcxx . . $ MelSpectrogram# me, Graphicscxx . . $ Graphics# g, bool xIsHertz, integercxx . . $ integer# fromFilter, integercxx . . $ integer# toFilter, |
| 128 | double zmin, double zmax, bool yscale_dB, double ymin, double ymax, bool garnish); |
| 129 | |
| 130 | autoMFCCcxx . . $ autoMFCC# MelSpectrogram_to_MFCCcxx . . $ MelSpectrogram_to_MFCC(402316c77bc09e28). (MelSpectrogramcxx . . $ MelSpectrogram# me, integercxx . . $ integer# numberOfCoefficients); |
| 131 | |
| 132 | autoMelSpectrogramcxx . . $ autoMelSpectrogram# MFCC_to_MelSpectrogramcxx . . $ MFCC_to_MelSpectrogram(819a68c6ca5b5468). (MFCCcxx . . $ MFCC# me, integercxx . . $ integer# first, integercxx . . $ integer# last, bool c0); |
| 133 | |
| 134 | void BandFilterSpectrogram_and_PCA_drawComponentcxx . . $ BandFilterSpectrogram_and_PCA_drawComponent(1df264a0745374b1). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, PCAcxx . . $ PCA# thee, Graphicscxx . . $ Graphics# g, integercxx . . $ integer# component, double dblevel, |
| 135 | double frequencyOffset, double scale, double tmin, double tmax, double fmin, double fmax); |
| 136 | |
| 137 | autoMatrixcxx . . $ autoMatrix# Spectrogram_to_Matrix_dBcxx . . $ Spectrogram_to_Matrix_dB(e49b3fec1510f465). (Spectrogramcxx . . $ 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_CCcxx . . $ BandFilterSpectrogram_into_CC(fc613e1bf7ef0afe). (BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# me, CCcxx . . $ CC# thee, integercxx . . $ integer# numberOfCoefficients); |
| 142 | |
| 143 | void CC_into_BandFilterSpectrogramcxx . . $ CC_into_BandFilterSpectrogram(98ad1036a70a01af). (CCcxx . . $ CC# me, BandFilterSpectrogramcxx . . $ BandFilterSpectrogram# thee, integercxx . . $ integer# first, integercxx . . $ 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 | autoMatrixcxx . . $ autoMatrix# Spectrogram_getLongtermSpectralFlatnesscxx . . $ Spectrogram_getLongtermSpectralFlatness(d7b1da01d821f6e6). (Spectrogramcxx . . $ Spectrogram# me, double longtimeWindow, double shorttimeWindow, double fmin, double fmax); |
| 150 | |
| 151 | void Spectrogram_drawLongTermFlatnesscxx . . $ Spectrogram_drawLongTermFlatness(ead065df759ac17b). (Spectrogramcxx . . $ Spectrogram# me, Graphicscxx . . $ 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_ */ |