You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

587 lines
18KB

  1. /*
  2. * DCA encoder
  3. * Copyright (C) 2008 Alexander E. Patrakov
  4. * 2010 Benjamin Larsson
  5. * 2011 Xiang Wang
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "libavutil/common.h"
  24. #include "libavutil/avassert.h"
  25. #include "libavutil/audioconvert.h"
  26. #include "avcodec.h"
  27. #include "get_bits.h"
  28. #include "put_bits.h"
  29. #include "dcaenc.h"
  30. #include "dcadata.h"
  31. #undef NDEBUG
  32. #define MAX_CHANNELS 6
  33. #define DCA_SUBBANDS_32 32
  34. #define DCA_MAX_FRAME_SIZE 16383
  35. #define DCA_HEADER_SIZE 13
  36. #define DCA_SUBBANDS 32 ///< Subband activity count
  37. #define QUANTIZER_BITS 16
  38. #define SUBFRAMES 1
  39. #define SUBSUBFRAMES 4
  40. #define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8)
  41. #define LFE_BITS 8
  42. #define LFE_INTERPOLATION 64
  43. #define LFE_PRESENT 2
  44. #define LFE_MISSING 0
  45. static const int8_t dca_lfe_index[] = {
  46. 1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3
  47. };
  48. static const int8_t dca_channel_reorder_lfe[][9] = {
  49. { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
  50. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  51. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  52. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  53. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  54. { 1, 2, 0, -1, -1, -1, -1, -1, -1 },
  55. { 0, 1, -1, 2, -1, -1, -1, -1, -1 },
  56. { 1, 2, 0, -1, 3, -1, -1, -1, -1 },
  57. { 0, 1, -1, 2, 3, -1, -1, -1, -1 },
  58. { 1, 2, 0, -1, 3, 4, -1, -1, -1 },
  59. { 2, 3, -1, 0, 1, 4, 5, -1, -1 },
  60. { 1, 2, 0, -1, 3, 4, 5, -1, -1 },
  61. { 0, -1, 4, 5, 2, 3, 1, -1, -1 },
  62. { 3, 4, 1, -1, 0, 2, 5, 6, -1 },
  63. { 2, 3, -1, 5, 7, 0, 1, 4, 6 },
  64. { 3, 4, 1, -1, 0, 2, 5, 7, 6 },
  65. };
  66. static const int8_t dca_channel_reorder_nolfe[][9] = {
  67. { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
  68. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  69. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  70. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  71. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  72. { 1, 2, 0, -1, -1, -1, -1, -1, -1 },
  73. { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
  74. { 1, 2, 0, 3, -1, -1, -1, -1, -1 },
  75. { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
  76. { 1, 2, 0, 3, 4, -1, -1, -1, -1 },
  77. { 2, 3, 0, 1, 4, 5, -1, -1, -1 },
  78. { 1, 2, 0, 3, 4, 5, -1, -1, -1 },
  79. { 0, 4, 5, 2, 3, 1, -1, -1, -1 },
  80. { 3, 4, 1, 0, 2, 5, 6, -1, -1 },
  81. { 2, 3, 5, 7, 0, 1, 4, 6, -1 },
  82. { 3, 4, 1, 0, 2, 5, 7, 6, -1 },
  83. };
  84. typedef struct {
  85. PutBitContext pb;
  86. int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */
  87. int start[MAX_CHANNELS];
  88. int frame_size;
  89. int prim_channels;
  90. int lfe_channel;
  91. int sample_rate_code;
  92. int scale_factor[MAX_CHANNELS][DCA_SUBBANDS_32];
  93. int lfe_scale_factor;
  94. int lfe_data[SUBFRAMES*SUBSUBFRAMES*4];
  95. int a_mode; ///< audio channels arrangement
  96. int num_channel;
  97. int lfe_state;
  98. int lfe_offset;
  99. const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
  100. int32_t pcm[FFMAX(LFE_INTERPOLATION, DCA_SUBBANDS_32)];
  101. int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]; /* [sample][channel][subband] */
  102. } DCAContext;
  103. static int32_t cos_table[128];
  104. static inline int32_t mul32(int32_t a, int32_t b)
  105. {
  106. int64_t r = (int64_t) a * b;
  107. /* round the result before truncating - improves accuracy */
  108. return (r + 0x80000000) >> 32;
  109. }
  110. /* Integer version of the cosine modulated Pseudo QMF */
  111. static void qmf_init(void)
  112. {
  113. int i;
  114. int32_t c[17], s[17];
  115. s[0] = 0; /* sin(index * PI / 64) * 0x7fffffff */
  116. c[0] = 0x7fffffff; /* cos(index * PI / 64) * 0x7fffffff */
  117. for (i = 1; i <= 16; i++) {
  118. s[i] = 2 * (mul32(c[i - 1], 105372028) + mul32(s[i - 1], 2144896908));
  119. c[i] = 2 * (mul32(c[i - 1], 2144896908) - mul32(s[i - 1], 105372028));
  120. }
  121. for (i = 0; i < 16; i++) {
  122. cos_table[i ] = c[i] >> 3; /* avoid output overflow */
  123. cos_table[i + 16] = s[16 - i] >> 3;
  124. cos_table[i + 32] = -s[i] >> 3;
  125. cos_table[i + 48] = -c[16 - i] >> 3;
  126. cos_table[i + 64] = -c[i] >> 3;
  127. cos_table[i + 80] = -s[16 - i] >> 3;
  128. cos_table[i + 96] = s[i] >> 3;
  129. cos_table[i + 112] = c[16 - i] >> 3;
  130. }
  131. }
  132. static int32_t band_delta_factor(int band, int sample_num)
  133. {
  134. int index = band * (2 * sample_num + 1);
  135. if (band == 0)
  136. return 0x07ffffff;
  137. else
  138. return cos_table[index & 127];
  139. }
  140. static void add_new_samples(DCAContext *c, const int32_t *in,
  141. int count, int channel)
  142. {
  143. int i;
  144. /* Place new samples into the history buffer */
  145. for (i = 0; i < count; i++) {
  146. c->history[channel][c->start[channel] + i] = in[i];
  147. av_assert0(c->start[channel] + i < 512);
  148. }
  149. c->start[channel] += count;
  150. if (c->start[channel] == 512)
  151. c->start[channel] = 0;
  152. av_assert0(c->start[channel] < 512);
  153. }
  154. static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32],
  155. int channel)
  156. {
  157. int band, i, j, k;
  158. int32_t resp;
  159. int32_t accum[DCA_SUBBANDS_32] = {0};
  160. add_new_samples(c, in, DCA_SUBBANDS_32, channel);
  161. /* Calculate the dot product of the signal with the (possibly inverted)
  162. reference decoder's response to this vector:
  163. (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0)
  164. so that -1.0 cancels 1.0 from the previous step */
  165. for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++)
  166. accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
  167. for (i = 0; i < c->start[channel]; k++, j++, i++)
  168. accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
  169. resp = 0;
  170. /* TODO: implement FFT instead of this naive calculation */
  171. for (band = 0; band < DCA_SUBBANDS_32; band++) {
  172. for (j = 0; j < 32; j++)
  173. resp += mul32(accum[j], band_delta_factor(band, j));
  174. out[band] = (band & 2) ? (-resp) : resp;
  175. }
  176. }
  177. static int32_t lfe_fir_64i[512];
  178. static int lfe_downsample(DCAContext *c, int32_t in[LFE_INTERPOLATION])
  179. {
  180. int i, j;
  181. int channel = c->prim_channels;
  182. int32_t accum = 0;
  183. add_new_samples(c, in, LFE_INTERPOLATION, channel);
  184. for (i = c->start[channel], j = 0; i < 512; i++, j++)
  185. accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
  186. for (i = 0; i < c->start[channel]; i++, j++)
  187. accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
  188. return accum;
  189. }
  190. static void init_lfe_fir(void)
  191. {
  192. static int initialized = 0;
  193. int i;
  194. if (initialized)
  195. return;
  196. for (i = 0; i < 512; i++)
  197. lfe_fir_64i[i] = lfe_fir_64[i] * (1 << 25); //float -> int32_t
  198. initialized = 1;
  199. }
  200. static void put_frame_header(DCAContext *c)
  201. {
  202. /* SYNC */
  203. put_bits(&c->pb, 16, 0x7ffe);
  204. put_bits(&c->pb, 16, 0x8001);
  205. /* Frame type: normal */
  206. put_bits(&c->pb, 1, 1);
  207. /* Deficit sample count: none */
  208. put_bits(&c->pb, 5, 31);
  209. /* CRC is not present */
  210. put_bits(&c->pb, 1, 0);
  211. /* Number of PCM sample blocks */
  212. put_bits(&c->pb, 7, PCM_SAMPLES-1);
  213. /* Primary frame byte size */
  214. put_bits(&c->pb, 14, c->frame_size-1);
  215. /* Audio channel arrangement: L + R (stereo) */
  216. put_bits(&c->pb, 6, c->num_channel);
  217. /* Core audio sampling frequency */
  218. put_bits(&c->pb, 4, c->sample_rate_code);
  219. /* Transmission bit rate: 1411.2 kbps */
  220. put_bits(&c->pb, 5, 0x16); /* FIXME: magic number */
  221. /* Embedded down mix: disabled */
  222. put_bits(&c->pb, 1, 0);
  223. /* Embedded dynamic range flag: not present */
  224. put_bits(&c->pb, 1, 0);
  225. /* Embedded time stamp flag: not present */
  226. put_bits(&c->pb, 1, 0);
  227. /* Auxiliary data flag: not present */
  228. put_bits(&c->pb, 1, 0);
  229. /* HDCD source: no */
  230. put_bits(&c->pb, 1, 0);
  231. /* Extension audio ID: N/A */
  232. put_bits(&c->pb, 3, 0);
  233. /* Extended audio data: not present */
  234. put_bits(&c->pb, 1, 0);
  235. /* Audio sync word insertion flag: after each sub-frame */
  236. put_bits(&c->pb, 1, 0);
  237. /* Low frequency effects flag: not present or interpolation factor=64 */
  238. put_bits(&c->pb, 2, c->lfe_state);
  239. /* Predictor history switch flag: on */
  240. put_bits(&c->pb, 1, 1);
  241. /* No CRC */
  242. /* Multirate interpolator switch: non-perfect reconstruction */
  243. put_bits(&c->pb, 1, 0);
  244. /* Encoder software revision: 7 */
  245. put_bits(&c->pb, 4, 7);
  246. /* Copy history: 0 */
  247. put_bits(&c->pb, 2, 0);
  248. /* Source PCM resolution: 16 bits, not DTS ES */
  249. put_bits(&c->pb, 3, 0);
  250. /* Front sum/difference coding: no */
  251. put_bits(&c->pb, 1, 0);
  252. /* Surrounds sum/difference coding: no */
  253. put_bits(&c->pb, 1, 0);
  254. /* Dialog normalization: 0 dB */
  255. put_bits(&c->pb, 4, 0);
  256. }
  257. static void put_primary_audio_header(DCAContext *c)
  258. {
  259. static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
  260. static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
  261. int ch, i;
  262. /* Number of subframes */
  263. put_bits(&c->pb, 4, SUBFRAMES - 1);
  264. /* Number of primary audio channels */
  265. put_bits(&c->pb, 3, c->prim_channels - 1);
  266. /* Subband activity count */
  267. for (ch = 0; ch < c->prim_channels; ch++)
  268. put_bits(&c->pb, 5, DCA_SUBBANDS - 2);
  269. /* High frequency VQ start subband */
  270. for (ch = 0; ch < c->prim_channels; ch++)
  271. put_bits(&c->pb, 5, DCA_SUBBANDS - 1);
  272. /* Joint intensity coding index: 0, 0 */
  273. for (ch = 0; ch < c->prim_channels; ch++)
  274. put_bits(&c->pb, 3, 0);
  275. /* Transient mode codebook: A4, A4 (arbitrary) */
  276. for (ch = 0; ch < c->prim_channels; ch++)
  277. put_bits(&c->pb, 2, 0);
  278. /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */
  279. for (ch = 0; ch < c->prim_channels; ch++)
  280. put_bits(&c->pb, 3, 6);
  281. /* Bit allocation quantizer select: linear 5-bit */
  282. for (ch = 0; ch < c->prim_channels; ch++)
  283. put_bits(&c->pb, 3, 6);
  284. /* Quantization index codebook select: dummy data
  285. to avoid transmission of scale factor adjustment */
  286. for (i = 1; i < 11; i++)
  287. for (ch = 0; ch < c->prim_channels; ch++)
  288. put_bits(&c->pb, bitlen[i], thr[i]);
  289. /* Scale factor adjustment index: not transmitted */
  290. }
  291. /**
  292. * 8-23 bits quantization
  293. * @param sample
  294. * @param bits
  295. */
  296. static inline uint32_t quantize(int32_t sample, int bits)
  297. {
  298. av_assert0(sample < 1 << (bits - 1));
  299. av_assert0(sample >= -(1 << (bits - 1)));
  300. return sample & ((1 << bits) - 1);
  301. }
  302. static inline int find_scale_factor7(int64_t max_value, int bits)
  303. {
  304. int i = 0, j = 128, q;
  305. max_value = ((max_value << 15) / lossy_quant[bits + 3]) >> (bits - 1);
  306. while (i < j) {
  307. q = (i + j) >> 1;
  308. if (max_value < scale_factor_quant7[q])
  309. j = q;
  310. else
  311. i = q + 1;
  312. }
  313. av_assert1(i < 128);
  314. return i;
  315. }
  316. static inline void put_sample7(DCAContext *c, int64_t sample, int bits,
  317. int scale_factor)
  318. {
  319. sample = (sample << 15) / ((int64_t) lossy_quant[bits + 3] * scale_factor_quant7[scale_factor]);
  320. put_bits(&c->pb, bits, quantize((int) sample, bits));
  321. }
  322. static void put_subframe(DCAContext *c,
  323. int32_t subband_data[8 * SUBSUBFRAMES][MAX_CHANNELS][32],
  324. int subframe)
  325. {
  326. int i, sub, ss, ch, max_value;
  327. int32_t *lfe_data = c->lfe_data + 4 * SUBSUBFRAMES * subframe;
  328. /* Subsubframes count */
  329. put_bits(&c->pb, 2, SUBSUBFRAMES -1);
  330. /* Partial subsubframe sample count: dummy */
  331. put_bits(&c->pb, 3, 0);
  332. /* Prediction mode: no ADPCM, in each channel and subband */
  333. for (ch = 0; ch < c->prim_channels; ch++)
  334. for (sub = 0; sub < DCA_SUBBANDS; sub++)
  335. put_bits(&c->pb, 1, 0);
  336. /* Prediction VQ addres: not transmitted */
  337. /* Bit allocation index */
  338. for (ch = 0; ch < c->prim_channels; ch++)
  339. for (sub = 0; sub < DCA_SUBBANDS; sub++)
  340. put_bits(&c->pb, 5, QUANTIZER_BITS+3);
  341. if (SUBSUBFRAMES > 1) {
  342. /* Transition mode: none for each channel and subband */
  343. for (ch = 0; ch < c->prim_channels; ch++)
  344. for (sub = 0; sub < DCA_SUBBANDS; sub++)
  345. put_bits(&c->pb, 1, 0); /* codebook A4 */
  346. }
  347. /* Determine scale_factor */
  348. for (ch = 0; ch < c->prim_channels; ch++)
  349. for (sub = 0; sub < DCA_SUBBANDS; sub++) {
  350. max_value = 0;
  351. for (i = 0; i < 8 * SUBSUBFRAMES; i++)
  352. max_value = FFMAX(max_value, FFABS(subband_data[i][ch][sub]));
  353. c->scale_factor[ch][sub] = find_scale_factor7(max_value, QUANTIZER_BITS);
  354. }
  355. if (c->lfe_channel) {
  356. max_value = 0;
  357. for (i = 0; i < 4 * SUBSUBFRAMES; i++)
  358. max_value = FFMAX(max_value, FFABS(lfe_data[i]));
  359. c->lfe_scale_factor = find_scale_factor7(max_value, LFE_BITS);
  360. }
  361. /* Scale factors: the same for each channel and subband,
  362. encoded according to Table D.1.2 */
  363. for (ch = 0; ch < c->prim_channels; ch++)
  364. for (sub = 0; sub < DCA_SUBBANDS; sub++)
  365. put_bits(&c->pb, 7, c->scale_factor[ch][sub]);
  366. /* Joint subband scale factor codebook select: not transmitted */
  367. /* Scale factors for joint subband coding: not transmitted */
  368. /* Stereo down-mix coefficients: not transmitted */
  369. /* Dynamic range coefficient: not transmitted */
  370. /* Stde information CRC check word: not transmitted */
  371. /* VQ encoded high frequency subbands: not transmitted */
  372. /* LFE data */
  373. if (c->lfe_channel) {
  374. for (i = 0; i < 4 * SUBSUBFRAMES; i++)
  375. put_sample7(c, lfe_data[i], LFE_BITS, c->lfe_scale_factor);
  376. put_bits(&c->pb, 8, c->lfe_scale_factor);
  377. }
  378. /* Audio data (subsubframes) */
  379. for (ss = 0; ss < SUBSUBFRAMES ; ss++)
  380. for (ch = 0; ch < c->prim_channels; ch++)
  381. for (sub = 0; sub < DCA_SUBBANDS; sub++)
  382. for (i = 0; i < 8; i++)
  383. put_sample7(c, subband_data[ss * 8 + i][ch][sub], QUANTIZER_BITS, c->scale_factor[ch][sub]);
  384. /* DSYNC */
  385. put_bits(&c->pb, 16, 0xffff);
  386. }
  387. static void put_frame(DCAContext *c,
  388. int32_t subband_data[PCM_SAMPLES][MAX_CHANNELS][32],
  389. uint8_t *frame)
  390. {
  391. int i;
  392. init_put_bits(&c->pb, frame + DCA_HEADER_SIZE, DCA_MAX_FRAME_SIZE-DCA_HEADER_SIZE);
  393. put_primary_audio_header(c);
  394. for (i = 0; i < SUBFRAMES; i++)
  395. put_subframe(c, &subband_data[SUBSUBFRAMES * 8 * i], i);
  396. flush_put_bits(&c->pb);
  397. c->frame_size = (put_bits_count(&c->pb) >> 3) + DCA_HEADER_SIZE;
  398. init_put_bits(&c->pb, frame, DCA_HEADER_SIZE);
  399. put_frame_header(c);
  400. flush_put_bits(&c->pb);
  401. }
  402. static int encode_frame(AVCodecContext *avctx, uint8_t *frame,
  403. int buf_size, void *data)
  404. {
  405. int i, k, channel;
  406. DCAContext *c = avctx->priv_data;
  407. int16_t *samples = data;
  408. int real_channel = 0;
  409. for (i = 0; i < PCM_SAMPLES; i ++) { /* i is the decimated sample number */
  410. for (channel = 0; channel < c->prim_channels + 1; channel++) {
  411. /* Get 32 PCM samples */
  412. for (k = 0; k < 32; k++) { /* k is the sample number in a 32-sample block */
  413. c->pcm[k] = samples[avctx->channels * (32 * i + k) + channel] << 16;
  414. }
  415. /* Put subband samples into the proper place */
  416. real_channel = c->channel_order_tab[channel];
  417. if (real_channel >= 0) {
  418. qmf_decompose(c, c->pcm, &c->subband[i][real_channel][0], real_channel);
  419. }
  420. }
  421. }
  422. if (c->lfe_channel) {
  423. for (i = 0; i < PCM_SAMPLES / 2; i++) {
  424. for (k = 0; k < LFE_INTERPOLATION; k++) /* k is the sample number in a 32-sample block */
  425. c->pcm[k] = samples[avctx->channels * (LFE_INTERPOLATION*i+k) + c->lfe_offset] << 16;
  426. c->lfe_data[i] = lfe_downsample(c, c->pcm);
  427. }
  428. }
  429. put_frame(c, c->subband, frame);
  430. return c->frame_size;
  431. }
  432. static int encode_init(AVCodecContext *avctx)
  433. {
  434. DCAContext *c = avctx->priv_data;
  435. int i;
  436. c->prim_channels = avctx->channels;
  437. c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
  438. switch (avctx->channel_layout) {
  439. case AV_CH_LAYOUT_STEREO: c->a_mode = 2; c->num_channel = 2; break;
  440. case AV_CH_LAYOUT_5POINT0: c->a_mode = 9; c->num_channel = 9; break;
  441. case AV_CH_LAYOUT_5POINT1: c->a_mode = 9; c->num_channel = 9; break;
  442. case AV_CH_LAYOUT_5POINT0_BACK: c->a_mode = 9; c->num_channel = 9; break;
  443. case AV_CH_LAYOUT_5POINT1_BACK: c->a_mode = 9; c->num_channel = 9; break;
  444. default:
  445. av_log(avctx, AV_LOG_ERROR,
  446. "Only stereo, 5.0, 5.1 channel layouts supported at the moment!\n");
  447. return AVERROR_PATCHWELCOME;
  448. }
  449. if (c->lfe_channel) {
  450. init_lfe_fir();
  451. c->prim_channels--;
  452. c->channel_order_tab = dca_channel_reorder_lfe[c->a_mode];
  453. c->lfe_state = LFE_PRESENT;
  454. c->lfe_offset = dca_lfe_index[c->a_mode];
  455. } else {
  456. c->channel_order_tab = dca_channel_reorder_nolfe[c->a_mode];
  457. c->lfe_state = LFE_MISSING;
  458. }
  459. for (i = 0; i < 16; i++) {
  460. if (dca_sample_rates[i] && (dca_sample_rates[i] == avctx->sample_rate))
  461. break;
  462. }
  463. if (i == 16) {
  464. av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported, only ", avctx->sample_rate);
  465. for (i = 0; i < 16; i++)
  466. av_log(avctx, AV_LOG_ERROR, "%d, ", dca_sample_rates[i]);
  467. av_log(avctx, AV_LOG_ERROR, "supported.\n");
  468. return -1;
  469. }
  470. c->sample_rate_code = i;
  471. avctx->frame_size = 32 * PCM_SAMPLES;
  472. if (!cos_table[127])
  473. qmf_init();
  474. return 0;
  475. }
  476. AVCodec ff_dca_encoder = {
  477. .name = "dca",
  478. .type = AVMEDIA_TYPE_AUDIO,
  479. .id = CODEC_ID_DTS,
  480. .priv_data_size = sizeof(DCAContext),
  481. .init = encode_init,
  482. .encode = encode_frame,
  483. .capabilities = CODEC_CAP_EXPERIMENTAL,
  484. .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
  485. };