Spectrogram_extensions.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef _Spectrogram_extensions_h_
  2. #define _Spectrogram_extensions_h_
  3. /* Spectrogram_extensions.h
  4. *
  5. * Copyright (C) 2014, 2015 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. djmw 20140913
  22. */
  23. #include "Intensity.h"
  24. #include "MFCC.h"
  25. #include "PCA.h"
  26. #include "Spectrogram.h"
  27. #include "Spectrum.h"
  28. #include "TableOfReal.h"
  29. #include "NUM2.h"
  30. #define HZTOBARK(x) NUMhertzToBark2(x)
  31. #define HZTOMEL(x) NUMhertzToMel2(x)
  32. #define BARKTOHZ(x) NUMbarkToHertz2(x)
  33. #define MELTOHZ(x) NUMmelToHertz2(x)
  34. #define BARKTOMEL(x) HZTOMEL(BARKTOHZ(x))
  35. #define MELTOBARK(x) HZTOBARK(MELTOHZ(x))
  36. #define BandFilterSpectrogram_DBREF 4e-10
  37. #define BandFilterSpectrogram_DBFAC 10
  38. #define BandFilterSpectrogram_DBFLOOR -100
  39. #define BandFilterSpectrogram_HERTZ 1
  40. #define BandFilterSpectrogram_BARK 2
  41. #define BandFilterSpectrogram_MEL 3
  42. Thing_define (BandFilterSpectrogram, Matrix) {
  43. void v_info ()
  44. override;
  45. double v_getValueAtSample (integer icol, integer irow, int units)
  46. override;
  47. virtual double v_frequencyToHertz (double f) { return f; }
  48. virtual double v_hertzToFrequency (double hertz) { return hertz; }
  49. virtual conststring32 v_getFrequencyUnit () { return U"Hz"; }
  50. };
  51. Thing_define (BarkSpectrogram, BandFilterSpectrogram) {
  52. void v_info ()
  53. override;
  54. double v_frequencyToHertz (double f)
  55. override { return NUMbarkToHertz2 (f); }
  56. double v_hertzToFrequency (double hertz)
  57. override { return NUMhertzToBark2 (hertz); }
  58. conststring32 v_getFrequencyUnit ()
  59. override { return U"bark"; }
  60. };
  61. Thing_define (MelSpectrogram, BandFilterSpectrogram) {
  62. void v_info ()
  63. override;
  64. double v_frequencyToHertz (double f)
  65. override { return NUMmelToHertz2 (f); }
  66. double v_hertzToFrequency (double hertz)
  67. override { return NUMhertzToMel2 (hertz); }
  68. conststring32 v_getFrequencyUnit ()
  69. override { return U"mel"; }
  70. };
  71. /*
  72. Interpretation:
  73. xmin, xmax, x1, dx, nx like Sampled.
  74. ymin, ymax lowest and highest frequencies in Barks / Mel.
  75. y1 mid of first filter (bark/mel).
  76. dy distance between filters (bark/mel).
  77. ny the number of filters.
  78. */
  79. double BandFilterSpectrogram_getFrequencyInHertz (BandFilterSpectrogram me, double f);
  80. void BandFilterSpectrogram_equalizeIntensities (BandFilterSpectrogram me, double intensity_db);
  81. autoMatrix BandFilterSpectrogram_to_Matrix (BandFilterSpectrogram me, int to_dB);
  82. autoIntensity BandFilterSpectrogram_to_Intensity (BandFilterSpectrogram me);
  83. void BandFilterSpectrogram_drawFrequencyScale (BandFilterSpectrogram me, Graphics g,
  84. double xmin, double xmax, double ymin, double ymax, bool garnish);
  85. void BandFilterSpectrogram_drawTimeSlice (BandFilterSpectrogram me, Graphics g, double t, double fmin, double fmax,
  86. double min, double max, conststring32 xlabel, bool garnish);
  87. void BarkSpectrogram_drawSekeyHansonFilterFunctions (BarkSpectrogram me, Graphics g, bool xIsHertz, int fromFilter, int toFilter,
  88. double zmin, double zmax, bool yscale_dB, double ymin, double ymax, bool garnish);
  89. void BandFilterSpectrogram_drawSpectrumAtNearestTimeSlice (BandFilterSpectrogram me, Graphics g,
  90. double time, double fmin, double fmax, double dBmin, double dBmax, bool garnish);
  91. void BandFilterSpectrogram_paintImage (BandFilterSpectrogram me, Graphics g,
  92. double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, bool garnish);
  93. autoBarkSpectrogram BarkSpectrogram_create (double tmin, double tmax, integer nt, double dt, double t1,
  94. double fmin, double fmax, integer nf, double df, double f1);
  95. autoBarkSpectrogram Matrix_to_BarkSpectrogram (Matrix me);
  96. /*
  97. Interpretation:
  98. xmin, xmax, x1, dx, nx like Sampled.
  99. ymin, ymax lowest and highest frequencies in mels.
  100. y1 mid of first filter (mels).
  101. dy distance between filters (mel).
  102. ny the number of filters.
  103. */
  104. autoMelSpectrogram MelSpectrogram_create (double tmin, double tmax, integer nt, double dt, double t1,
  105. double fmin, double fmax, integer nf, double df, double f1);
  106. autoMelSpectrogram Matrix_to_MelSpectrogram (Matrix me);
  107. void MelSpectrogram_drawTriangularFilterFunctions (MelSpectrogram me, Graphics g, bool xIsHertz, int fromFilter, int toFilter,
  108. double zmin, double zmax, bool yscale_dB, double ymin, double ymax, bool garnish);
  109. autoMFCC MelSpectrogram_to_MFCC (MelSpectrogram me, integer numberOfCoefficients);
  110. autoMelSpectrogram MFCC_to_MelSpectrogram (MFCC me, integer first, integer last, bool c0);
  111. void BandFilterSpectrogram_and_PCA_drawComponent (BandFilterSpectrogram me, PCA thee, Graphics g, integer component, double dblevel,
  112. double frequencyOffset, double scale, double tmin, double tmax, double fmin, double fmax);
  113. autoMatrix Spectrogram_to_Matrix_dB (Spectrogram me, double reference, double scaleFactor, double floor_dB);
  114. // dbs = scaleFactor * log10 (value/reference);
  115. // if (dbs < floor_db) { dbs = floor_dB }
  116. void BandFilterSpectrogram_into_CC (BandFilterSpectrogram me, CC thee, integer numberOfCoefficients);
  117. void CC_into_BandFilterSpectrogram (CC me, BandFilterSpectrogram thee, integer first, integer last, bool use_c0);
  118. #endif /* _Spectrogram_extensions_h_ */