readsamplesjoint.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2014 The Android Open Source Project
  4. * Copyright 2003 - 2004 Open Interface North America, Inc. All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. ******************************************************************************/
  19. /*******************************************************************************
  20. * @file readsamplesjoint.inc
  21. *
  22. * This is the body of the generic version of OI_SBC_ReadSamplesJoint().
  23. * It is designed to be \#included into a function as follows:
  24. \code
  25. void OI_SBC_ReadSamplesJoint4(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
  26. {
  27. #define NROF_SUBBANDS 4
  28. #include "readsamplesjoint.inc"
  29. #undef NROF_SUBBANDS
  30. }
  31. void OI_SBC_ReadSamplesJoint8(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
  32. {
  33. #define NROF_SUBBANDS 8
  34. #include "readsamplesjoint.inc"
  35. #undef NROF_SUBBANDS
  36. }
  37. \endcode
  38. * Or to make a generic version:
  39. \code
  40. void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
  41. {
  42. OI_UINT nrof_subbands = common->frameInfo.nrof_subbands;
  43. #define NROF_SUBBANDS nrof_subbands
  44. #include "readsamplesjoint.inc"
  45. #undef NROF_SUBBANDS
  46. }
  47. \endcode
  48. * @ingroup codec_internal
  49. *******************************************************************************/
  50. /**********************************************************************************
  51. $Revision: #1 $
  52. ***********************************************************************************/
  53. {
  54. OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
  55. OI_UINT bl = common->frameInfo.nrof_blocks;
  56. OI_INT32 * RESTRICT s = common->subdata;
  57. OI_UINT8 *ptr = global_bs->ptr.w;
  58. OI_UINT32 value = global_bs->value;
  59. OI_UINT bitPtr = global_bs->bitPtr;
  60. OI_UINT8 jmask = common->frameInfo.join << (8 - NROF_SUBBANDS);
  61. do {
  62. OI_INT8 *sf_array = &common->scale_factor[0];
  63. OI_UINT8 *bits_array = &common->bits.uint8[0];
  64. OI_UINT8 joint = jmask;
  65. OI_UINT sb;
  66. /*
  67. * Left channel
  68. */
  69. sb = NROF_SUBBANDS;
  70. do {
  71. OI_UINT32 raw;
  72. OI_INT32 dequant;
  73. OI_UINT8 bits = *bits_array++;
  74. OI_INT sf = *sf_array++;
  75. OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
  76. dequant = OI_SBC_Dequant(raw, sf, bits);
  77. *s++ = dequant;
  78. } while (--sb);
  79. /*
  80. * Right channel
  81. */
  82. sb = NROF_SUBBANDS;
  83. do {
  84. OI_UINT32 raw;
  85. OI_INT32 dequant;
  86. OI_UINT8 bits = *bits_array++;
  87. OI_INT sf = *sf_array++;
  88. OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
  89. dequant = OI_SBC_Dequant(raw, sf, bits);
  90. /*
  91. * Check if we need to do mid/side
  92. */
  93. if (joint & 0x80) {
  94. OI_INT32 mid = *(s - NROF_SUBBANDS);
  95. OI_INT32 side = dequant;
  96. *(s - NROF_SUBBANDS) = mid + side;
  97. dequant = mid - side;
  98. }
  99. joint <<= 1;
  100. *s++ = dequant;
  101. } while (--sb);
  102. } while (--bl);
  103. }