sbc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Bluetooth low-complexity, subband codec (SBC)
  3. *
  4. * Copyright (C) 2017 Aurelien Jacobs <aurel@gnuage.org>
  5. * Copyright (C) 2012-2014 Intel Corporation
  6. * Copyright (C) 2008-2010 Nokia Corporation
  7. * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
  8. * Copyright (C) 2004-2005 Henryk Ploetz <henryk@ploetzli.ch>
  9. * Copyright (C) 2005-2006 Brad Midgley <bmidgley@xmission.com>
  10. *
  11. * This file is part of FFmpeg.
  12. *
  13. * FFmpeg is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2.1 of the License, or (at your option) any later version.
  17. *
  18. * FFmpeg is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with FFmpeg; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27. /**
  28. * @file
  29. * SBC common definitions for the encoder and decoder
  30. */
  31. #ifndef AVCODEC_SBC_H
  32. #define AVCODEC_SBC_H
  33. #include "avcodec.h"
  34. #include "libavutil/crc.h"
  35. #define MSBC_BLOCKS 15
  36. /* sampling frequency */
  37. #define SBC_FREQ_16000 0x00
  38. #define SBC_FREQ_32000 0x01
  39. #define SBC_FREQ_44100 0x02
  40. #define SBC_FREQ_48000 0x03
  41. /* blocks */
  42. #define SBC_BLK_4 0x00
  43. #define SBC_BLK_8 0x01
  44. #define SBC_BLK_12 0x02
  45. #define SBC_BLK_16 0x03
  46. /* channel mode */
  47. #define SBC_MODE_MONO 0x00
  48. #define SBC_MODE_DUAL_CHANNEL 0x01
  49. #define SBC_MODE_STEREO 0x02
  50. #define SBC_MODE_JOINT_STEREO 0x03
  51. /* allocation method */
  52. #define SBC_AM_LOUDNESS 0x00
  53. #define SBC_AM_SNR 0x01
  54. /* subbands */
  55. #define SBC_SB_4 0x00
  56. #define SBC_SB_8 0x01
  57. /* synchronisation words */
  58. #define SBC_SYNCWORD 0x9C
  59. #define MSBC_SYNCWORD 0xAD
  60. /* extra bits of precision for the synthesis filter input data */
  61. #define SBCDEC_FIXED_EXTRA_BITS 2
  62. /*
  63. * Enforce 16 byte alignment for the data, which is supposed to be used
  64. * with SIMD optimized code.
  65. */
  66. #define SBC_ALIGN 16
  67. /* This structure contains an unpacked SBC frame.
  68. Yes, there is probably quite some unused space herein */
  69. struct sbc_frame {
  70. uint8_t frequency;
  71. uint8_t blocks;
  72. enum {
  73. MONO = SBC_MODE_MONO,
  74. DUAL_CHANNEL = SBC_MODE_DUAL_CHANNEL,
  75. STEREO = SBC_MODE_STEREO,
  76. JOINT_STEREO = SBC_MODE_JOINT_STEREO
  77. } mode;
  78. uint8_t channels;
  79. enum {
  80. LOUDNESS = SBC_AM_LOUDNESS,
  81. SNR = SBC_AM_SNR
  82. } allocation;
  83. uint8_t subbands;
  84. uint8_t bitpool;
  85. uint16_t codesize;
  86. /* bit number x set means joint stereo has been used in subband x */
  87. uint8_t joint;
  88. /* only the lower 4 bits of every element are to be used */
  89. DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor)[2][8];
  90. /* raw integer subband samples in the frame */
  91. DECLARE_ALIGNED(SBC_ALIGN, int32_t, sb_sample_f)[16][2][8];
  92. /* modified subband samples */
  93. DECLARE_ALIGNED(SBC_ALIGN, int32_t, sb_sample)[16][2][8];
  94. const AVCRC *crc_ctx;
  95. };
  96. uint8_t ff_sbc_crc8(const AVCRC *crc_ctx, const uint8_t *data, size_t len);
  97. void ff_sbc_calculate_bits(const struct sbc_frame *frame, int (*bits)[8]);
  98. #endif /* AVCODEC_SBC_H */