mpc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Musepack decoder core
  3. * Copyright (c) 2006 Konstantin Shishkov
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/mpc.c Musepack decoder core
  23. * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
  24. * divided into 32 subbands.
  25. */
  26. #include "libavutil/random.h"
  27. #include "avcodec.h"
  28. #include "bitstream.h"
  29. #include "dsputil.h"
  30. #include "mpegaudio.h"
  31. #include "mpc.h"
  32. #include "mpcdata.h"
  33. static DECLARE_ALIGNED_16(MPA_INT, mpa_window[512]);
  34. void ff_mpc_init(void)
  35. {
  36. ff_mpa_synth_init(mpa_window);
  37. }
  38. /**
  39. * Process decoded Musepack data and produce PCM
  40. */
  41. static void mpc_synth(MPCContext *c, int16_t *out)
  42. {
  43. int dither_state = 0;
  44. int i, ch;
  45. OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;
  46. for(ch = 0; ch < 2; ch++){
  47. samples_ptr = samples + ch;
  48. for(i = 0; i < SAMPLES_PER_BAND; i++) {
  49. ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),
  50. mpa_window, &dither_state,
  51. samples_ptr, 2,
  52. c->sb_samples[ch][i]);
  53. samples_ptr += 64;
  54. }
  55. }
  56. for(i = 0; i < MPC_FRAME_SIZE*2; i++)
  57. *out++=samples[i];
  58. }
  59. void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data)
  60. {
  61. int i, j, ch;
  62. Band *bands = c->bands;
  63. int off;
  64. float mul;
  65. /* dequantize */
  66. memset(c->sb_samples, 0, sizeof(c->sb_samples));
  67. off = 0;
  68. for(i = 0; i <= maxband; i++, off += SAMPLES_PER_BAND){
  69. for(ch = 0; ch < 2; ch++){
  70. if(bands[i].res[ch]){
  71. j = 0;
  72. mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][0]];
  73. for(; j < 12; j++)
  74. c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
  75. mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][1]];
  76. for(; j < 24; j++)
  77. c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
  78. mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][2]];
  79. for(; j < 36; j++)
  80. c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
  81. }
  82. }
  83. if(bands[i].msf){
  84. int t1, t2;
  85. for(j = 0; j < SAMPLES_PER_BAND; j++){
  86. t1 = c->sb_samples[0][j][i];
  87. t2 = c->sb_samples[1][j][i];
  88. c->sb_samples[0][j][i] = t1 + t2;
  89. c->sb_samples[1][j][i] = t1 - t2;
  90. }
  91. }
  92. }
  93. mpc_synth(c, data);
  94. }