analysis.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright (c) 2011 Xiph.Org Foundation
  2. Written by Jean-Marc Valin */
  3. /*
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  16. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef ANALYSIS_H
  25. #define ANALYSIS_H
  26. #include "celt.h"
  27. #include "opus_private.h"
  28. #include "mlp.h"
  29. #define NB_FRAMES 8
  30. #define NB_TBANDS 18
  31. #define ANALYSIS_BUF_SIZE 720 /* 30 ms at 24 kHz */
  32. /* At that point we can stop counting frames because it no longer matters. */
  33. #define ANALYSIS_COUNT_MAX 10000
  34. #define DETECT_SIZE 100
  35. /* Uncomment this to print the MLP features on stdout. */
  36. /*#define MLP_TRAINING*/
  37. typedef struct {
  38. int arch;
  39. int application;
  40. opus_int32 Fs;
  41. #define TONALITY_ANALYSIS_RESET_START angle
  42. float angle[240];
  43. float d_angle[240];
  44. float d2_angle[240];
  45. opus_val32 inmem[ANALYSIS_BUF_SIZE];
  46. int mem_fill; /* number of usable samples in the buffer */
  47. float prev_band_tonality[NB_TBANDS];
  48. float prev_tonality;
  49. int prev_bandwidth;
  50. float E[NB_FRAMES][NB_TBANDS];
  51. float logE[NB_FRAMES][NB_TBANDS];
  52. float lowE[NB_TBANDS];
  53. float highE[NB_TBANDS];
  54. float meanE[NB_TBANDS+1];
  55. float mem[32];
  56. float cmean[8];
  57. float std[9];
  58. float Etracker;
  59. float lowECount;
  60. int E_count;
  61. int count;
  62. int analysis_offset;
  63. int write_pos;
  64. int read_pos;
  65. int read_subframe;
  66. float hp_ener_accum;
  67. int initialized;
  68. float rnn_state[MAX_NEURONS];
  69. opus_val32 downmix_state[3];
  70. AnalysisInfo info[DETECT_SIZE];
  71. } TonalityAnalysisState;
  72. /** Initialize a TonalityAnalysisState struct.
  73. *
  74. * This performs some possibly slow initialization steps which should
  75. * not be repeated every analysis step. No allocated memory is retained
  76. * by the state struct, so no cleanup call is required.
  77. */
  78. void tonality_analysis_init(TonalityAnalysisState *analysis, opus_int32 Fs);
  79. /** Reset a TonalityAnalysisState stuct.
  80. *
  81. * Call this when there's a discontinuity in the data.
  82. */
  83. void tonality_analysis_reset(TonalityAnalysisState *analysis);
  84. void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len);
  85. void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm,
  86. int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs,
  87. int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info);
  88. #endif