conceal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /***************************************************************************\
  2. *
  3. * MPEG Layer3-Audio Decoder
  4. * © 1997-2006 by Fraunhofer IIS
  5. * All Rights Reserved
  6. *
  7. * filename: conceal.h
  8. * project : ISO/MPEG-Decoder
  9. * author : Stefan Gewinner
  10. * date : 1998-05-26
  11. * contents/description: error concealment class - HEADER
  12. *
  13. *
  14. \***************************************************************************/
  15. /*
  16. * $Date: 2010/11/17 20:46:02 $
  17. * $Id: conceal.h,v 1.1 2010/11/17 20:46:02 audiodsp Exp $
  18. */
  19. #ifndef __CONCEAL_H__
  20. #define __CONCEAL_H__
  21. /* ------------------------ includes --------------------------------------*/
  22. #include "mpeg.h"
  23. /*-------------------------------------------------------------------------*/
  24. //
  25. // Error concealment class.
  26. //
  27. // This object is used to apply error concealment to a spectrum in case of
  28. // CRC errors. CRC protection is optional for ISO/MPEG bitstreams.
  29. //
  30. class CErrorConcealment
  31. {
  32. public:
  33. CErrorConcealment();
  34. ~CErrorConcealment() {}
  35. void Init();
  36. void Apply
  37. (
  38. bool fApply, // true: restore, false: store
  39. const MPEG_INFO &Info,
  40. MP3SI &Si,
  41. float *lpSpec,
  42. int gr,
  43. int ch
  44. );
  45. enum { MAX_SPECTRUM_DATA = 4 };
  46. protected :
  47. //
  48. // structure to hold information for one granule
  49. //
  50. typedef struct tagGRAN_DATA
  51. {
  52. MP3SI_GRCH gr; /* side info */
  53. float Rs[SBLIMIT*SSLIMIT]; /* line amplitudes */
  54. float nrg[23]; /* sf-band energies */
  55. int nrgValid; /* valid-flag for sf-band energies */
  56. #ifdef DEBUG_CONCEALMENT
  57. long frameNumber;
  58. #endif
  59. } GRAN_DATA;
  60. //
  61. // structure for concealment data
  62. //
  63. typedef struct tagSPECTRUM_DATA
  64. {
  65. int writeOffset; /* place to store next valid granule */
  66. GRAN_DATA gran[MAX_SPECTRUM_DATA]; /* ring buffer */
  67. GRAN_DATA estGran;
  68. } SPECTRUM_DATA;
  69. SPECTRUM_DATA SpecDataBuffer[2]; /* one buffer for each channel */
  70. void Store
  71. (
  72. const MPEG_INFO &Info,
  73. const MP3SI &Si,
  74. const float *lpSpec,
  75. int gr,
  76. int ch
  77. );
  78. void Restore
  79. (
  80. const MPEG_INFO &Info,
  81. MP3SI &Si,
  82. float *lpSpec,
  83. int gr,
  84. int ch
  85. );
  86. #ifdef USE_ENERGY_PREDICTION
  87. float predict(const float *hist, const float *coff, int n);
  88. void adaptPredictor(const float *hist, float pwr, float *coff, float d, int n);
  89. #endif
  90. void estimateBandEnergies(const MPEG_INFO &Info, GRAN_DATA *g);
  91. void predictEnergies(const MPEG_INFO &Info, SPECTRUM_DATA *s);
  92. //
  93. // random seeds for the float and bit random generators
  94. //
  95. float ranHigh1(float a);
  96. float ranHigh2(float a);
  97. float ranLow(float a);
  98. float ran3(long *idum);
  99. int irbit2(unsigned long *iseed);
  100. int inext;
  101. int inextp;
  102. long ma [56];
  103. int iff ;
  104. long f_seed, w_seed ;
  105. unsigned long b_seed ;
  106. #ifdef DEBUG_CONCEALMENT
  107. long currentFrame ;
  108. #endif
  109. };
  110. /*-------------------------------------------------------------------------*/
  111. #endif