sbc.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. *
  3. * Bluetooth low-complexity, subband codec (SBC) library
  4. *
  5. * Copyright (C) 2008-2010 Nokia Corporation
  6. * Copyright (C) 2012-2014 Intel 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. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. *
  26. */
  27. #ifndef __SBC_H
  28. #define __SBC_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #include <stdint.h>
  33. #include <sys/types.h>
  34. /* sampling frequency */
  35. #define SBC_FREQ_16000 0x00
  36. #define SBC_FREQ_32000 0x01
  37. #define SBC_FREQ_44100 0x02
  38. #define SBC_FREQ_48000 0x03
  39. /* blocks */
  40. #define SBC_BLK_4 0x00
  41. #define SBC_BLK_8 0x01
  42. #define SBC_BLK_12 0x02
  43. #define SBC_BLK_16 0x03
  44. /* channel mode */
  45. #define SBC_MODE_MONO 0x00
  46. #define SBC_MODE_DUAL_CHANNEL 0x01
  47. #define SBC_MODE_STEREO 0x02
  48. #define SBC_MODE_JOINT_STEREO 0x03
  49. /* allocation method */
  50. #define SBC_AM_LOUDNESS 0x00
  51. #define SBC_AM_SNR 0x01
  52. /* subbands */
  53. #define SBC_SB_4 0x00
  54. #define SBC_SB_8 0x01
  55. /* data endianess */
  56. #define SBC_LE 0x00
  57. #define SBC_BE 0x01
  58. #define SBC_SYNCWORD 0x9C
  59. #define MSBC_SYNCWORD 0xAD
  60. #define MSBC_BLOCKS 15
  61. #define A2DP_SAMPLING_FREQ_16000 (1 << 3)
  62. #define A2DP_SAMPLING_FREQ_32000 (1 << 2)
  63. #define A2DP_SAMPLING_FREQ_44100 (1 << 1)
  64. #define A2DP_SAMPLING_FREQ_48000 (1 << 0)
  65. #define A2DP_CHANNEL_MODE_MONO (1 << 3)
  66. #define A2DP_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
  67. #define A2DP_CHANNEL_MODE_STEREO (1 << 1)
  68. #define A2DP_CHANNEL_MODE_JOINT_STEREO (1 << 0)
  69. #define A2DP_BLOCK_LENGTH_4 (1 << 3)
  70. #define A2DP_BLOCK_LENGTH_8 (1 << 2)
  71. #define A2DP_BLOCK_LENGTH_12 (1 << 1)
  72. #define A2DP_BLOCK_LENGTH_16 (1 << 0)
  73. #define A2DP_SUBBANDS_4 (1 << 1)
  74. #define A2DP_SUBBANDS_8 (1 << 0)
  75. #define A2DP_ALLOCATION_SNR (1 << 1)
  76. #define A2DP_ALLOCATION_LOUDNESS (1 << 0)
  77. struct sbc_struct {
  78. unsigned long flags;
  79. uint8_t frequency;
  80. uint8_t blocks;
  81. uint8_t subbands;
  82. uint8_t mode;
  83. uint8_t allocation;
  84. uint8_t bitpool;
  85. uint8_t endian;
  86. void *priv;
  87. void *priv_alloc_base;
  88. };
  89. #if __BYTE_ORDER == __LITTLE_ENDIAN
  90. struct a2dp_sbc {
  91. uint8_t channel_mode:4;
  92. uint8_t frequency:4;
  93. uint8_t allocation_method:2;
  94. uint8_t subbands:2;
  95. uint8_t block_length:4;
  96. uint8_t min_bitpool;
  97. uint8_t max_bitpool;
  98. } __attribute__ ((packed));
  99. #elif __BYTE_ORDER == __BIG_ENDIAN
  100. struct a2dp_sbc {
  101. uint8_t frequency:4;
  102. uint8_t channel_mode:4;
  103. uint8_t block_length:4;
  104. uint8_t subbands:2;
  105. uint8_t allocation_method:2;
  106. uint8_t min_bitpool;
  107. uint8_t max_bitpool;
  108. } __attribute__ ((packed));
  109. #else
  110. #error "Unknown byte order"
  111. #endif
  112. typedef struct sbc_struct sbc_t;
  113. typedef struct a2dp_sbc a2dp_sbc_t;
  114. int sbc_init(sbc_t *sbc, unsigned long flags);
  115. int sbc_reinit(sbc_t *sbc, unsigned long flags);
  116. int sbc_init_msbc(sbc_t *sbc, unsigned long flags);
  117. int sbc_init_a2dp(sbc_t *sbc, unsigned long flags,
  118. const void *conf, size_t conf_len);
  119. int sbc_reinit_a2dp(sbc_t *sbc, unsigned long flags,
  120. const void *conf, size_t conf_len);
  121. ssize_t sbc_parse(sbc_t *sbc, const void *input, size_t input_len);
  122. /* Decodes ONE input block into ONE output block */
  123. ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len,
  124. void *output, size_t output_len, size_t *written);
  125. /* Encodes ONE input block into ONE output block */
  126. ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len,
  127. void *output, size_t output_len, ssize_t *written);
  128. /* Returns the compressed block size in bytes */
  129. size_t sbc_get_frame_length(sbc_t *sbc);
  130. /* Returns the time one input/output block takes to play in msec*/
  131. unsigned sbc_get_frame_duration(sbc_t *sbc);
  132. /* Returns the uncompressed block size in bytes */
  133. size_t sbc_get_codesize(sbc_t *sbc);
  134. const char *sbc_get_implementation_info(sbc_t *sbc);
  135. void sbc_finish(sbc_t *sbc);
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* __SBC_H */