analysis.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #define NB_FRAMES 8
  29. #define NB_TBANDS 18
  30. #define NB_TOT_BANDS 21
  31. #define ANALYSIS_BUF_SIZE 720 /* 15 ms at 48 kHz */
  32. #define DETECT_SIZE 200
  33. typedef struct {
  34. int arch;
  35. #define TONALITY_ANALYSIS_RESET_START angle
  36. float angle[240];
  37. float d_angle[240];
  38. float d2_angle[240];
  39. opus_val32 inmem[ANALYSIS_BUF_SIZE];
  40. int mem_fill; /* number of usable samples in the buffer */
  41. float prev_band_tonality[NB_TBANDS];
  42. float prev_tonality;
  43. float E[NB_FRAMES][NB_TBANDS];
  44. float lowE[NB_TBANDS];
  45. float highE[NB_TBANDS];
  46. float meanE[NB_TOT_BANDS];
  47. float mem[32];
  48. float cmean[8];
  49. float std[9];
  50. float music_prob;
  51. float Etracker;
  52. float lowECount;
  53. int E_count;
  54. int last_music;
  55. int last_transition;
  56. int count;
  57. float subframe_mem[3];
  58. int analysis_offset;
  59. /** Probability of having speech for time i to DETECT_SIZE-1 (and music before).
  60. pspeech[0] is the probability that all frames in the window are speech. */
  61. float pspeech[DETECT_SIZE];
  62. /** Probability of having music for time i to DETECT_SIZE-1 (and speech before).
  63. pmusic[0] is the probability that all frames in the window are music. */
  64. float pmusic[DETECT_SIZE];
  65. float speech_confidence;
  66. float music_confidence;
  67. int speech_confidence_count;
  68. int music_confidence_count;
  69. int write_pos;
  70. int read_pos;
  71. int read_subframe;
  72. AnalysisInfo info[DETECT_SIZE];
  73. } TonalityAnalysisState;
  74. /** Initialize a TonalityAnalysisState struct.
  75. *
  76. * This performs some possibly slow initialization steps which should
  77. * not be repeated every analysis step. No allocated memory is retained
  78. * by the state struct, so no cleanup call is required.
  79. */
  80. void tonality_analysis_init(TonalityAnalysisState *analysis);
  81. /** Reset a TonalityAnalysisState stuct.
  82. *
  83. * Call this when there's a discontinuity in the data.
  84. */
  85. void tonality_analysis_reset(TonalityAnalysisState *analysis);
  86. void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len);
  87. void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm,
  88. int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs,
  89. int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info);
  90. #endif