]> git.sesse.net Git - ffmpeg/blob - libavcodec/pcm.c
Merge commit 'ad01ba6ceaea7d71c4b9887795523438689b5a96'
[ffmpeg] / libavcodec / pcm.c
1 /*
2  * PCM codecs
3  * Copyright (c) 2001 Fabrice Bellard
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 /**
23  * @file
24  * PCM codecs
25  */
26
27 #include "libavutil/attributes.h"
28 #include "avcodec.h"
29 #include "bytestream.h"
30 #include "internal.h"
31 #include "mathops.h"
32 #include "pcm_tablegen.h"
33
34 static av_cold int pcm_encode_init(AVCodecContext *avctx)
35 {
36     avctx->frame_size = 0;
37     switch (avctx->codec->id) {
38     case AV_CODEC_ID_PCM_ALAW:
39         pcm_alaw_tableinit();
40         break;
41     case AV_CODEC_ID_PCM_MULAW:
42         pcm_ulaw_tableinit();
43         break;
44     default:
45         break;
46     }
47
48     avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
49     avctx->block_align           = avctx->channels * avctx->bits_per_coded_sample / 8;
50     avctx->bit_rate              = avctx->block_align * avctx->sample_rate * 8;
51     avctx->coded_frame           = avcodec_alloc_frame();
52     if (!avctx->coded_frame)
53         return AVERROR(ENOMEM);
54
55     return 0;
56 }
57
58 static av_cold int pcm_encode_close(AVCodecContext *avctx)
59 {
60     av_freep(&avctx->coded_frame);
61
62     return 0;
63 }
64
65 /**
66  * Write PCM samples macro
67  * @param type   Datatype of native machine format
68  * @param endian bytestream_put_xxx() suffix
69  * @param src    Source pointer (variable name)
70  * @param dst    Destination pointer (variable name)
71  * @param n      Total number of samples (variable name)
72  * @param shift  Bitshift (bits)
73  * @param offset Sample value offset
74  */
75 #define ENCODE(type, endian, src, dst, n, shift, offset)                \
76     samples_ ## type = (const type *) src;                              \
77     for (; n > 0; n--) {                                                \
78         register type v = (*samples_ ## type++ >> shift) + offset;      \
79         bytestream_put_ ## endian(&dst, v);                             \
80     }
81
82 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset)              \
83     n /= avctx->channels;                                               \
84     for (c = 0; c < avctx->channels; c++) {                             \
85         int i;                                                          \
86         samples_ ## type = (const type *) frame->extended_data[c];      \
87         for (i = n; i > 0; i--) {                                       \
88             register type v = (*samples_ ## type++ >> shift) + offset;  \
89             bytestream_put_ ## endian(&dst, v);                         \
90         }                                                               \
91     }
92
93 static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
94                             const AVFrame *frame, int *got_packet_ptr)
95 {
96     int n, c, sample_size, v, ret;
97     const short *samples;
98     unsigned char *dst;
99     const uint8_t *samples_uint8_t;
100     const int16_t *samples_int16_t;
101     const int32_t *samples_int32_t;
102     const int64_t *samples_int64_t;
103     const uint16_t *samples_uint16_t;
104     const uint32_t *samples_uint32_t;
105
106     sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
107     n           = frame->nb_samples * avctx->channels;
108     samples     = (const short *)frame->data[0];
109
110     if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)))
111         return ret;
112     dst = avpkt->data;
113
114     switch (avctx->codec->id) {
115     case AV_CODEC_ID_PCM_U32LE:
116         ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
117         break;
118     case AV_CODEC_ID_PCM_U32BE:
119         ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
120         break;
121     case AV_CODEC_ID_PCM_S24LE:
122         ENCODE(int32_t, le24, samples, dst, n, 8, 0)
123         break;
124     case AV_CODEC_ID_PCM_S24LE_PLANAR:
125         ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
126         break;
127     case AV_CODEC_ID_PCM_S24BE:
128         ENCODE(int32_t, be24, samples, dst, n, 8, 0)
129         break;
130     case AV_CODEC_ID_PCM_U24LE:
131         ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
132         break;
133     case AV_CODEC_ID_PCM_U24BE:
134         ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
135         break;
136     case AV_CODEC_ID_PCM_S24DAUD:
137         for (; n > 0; n--) {
138             uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
139                            (ff_reverse[*samples & 0xff] << 8);
140             tmp <<= 4; // sync flags would go here
141             bytestream_put_be24(&dst, tmp);
142             samples++;
143         }
144         break;
145     case AV_CODEC_ID_PCM_U16LE:
146         ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
147         break;
148     case AV_CODEC_ID_PCM_U16BE:
149         ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
150         break;
151     case AV_CODEC_ID_PCM_S8:
152         ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
153         break;
154     case AV_CODEC_ID_PCM_S8_PLANAR:
155         ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
156         break;
157 #if HAVE_BIGENDIAN
158     case AV_CODEC_ID_PCM_F64LE:
159         ENCODE(int64_t, le64, samples, dst, n, 0, 0)
160         break;
161     case AV_CODEC_ID_PCM_S32LE:
162     case AV_CODEC_ID_PCM_F32LE:
163         ENCODE(int32_t, le32, samples, dst, n, 0, 0)
164         break;
165     case AV_CODEC_ID_PCM_S32LE_PLANAR:
166         ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
167         break;
168     case AV_CODEC_ID_PCM_S16LE:
169         ENCODE(int16_t, le16, samples, dst, n, 0, 0)
170         break;
171     case AV_CODEC_ID_PCM_S16LE_PLANAR:
172         ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
173         break;
174     case AV_CODEC_ID_PCM_F64BE:
175     case AV_CODEC_ID_PCM_F32BE:
176     case AV_CODEC_ID_PCM_S32BE:
177     case AV_CODEC_ID_PCM_S16BE:
178 #else
179     case AV_CODEC_ID_PCM_F64BE:
180         ENCODE(int64_t, be64, samples, dst, n, 0, 0)
181         break;
182     case AV_CODEC_ID_PCM_F32BE:
183     case AV_CODEC_ID_PCM_S32BE:
184         ENCODE(int32_t, be32, samples, dst, n, 0, 0)
185         break;
186     case AV_CODEC_ID_PCM_S16BE:
187         ENCODE(int16_t, be16, samples, dst, n, 0, 0)
188         break;
189     case AV_CODEC_ID_PCM_S16BE_PLANAR:
190         ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
191         break;
192     case AV_CODEC_ID_PCM_F64LE:
193     case AV_CODEC_ID_PCM_F32LE:
194     case AV_CODEC_ID_PCM_S32LE:
195     case AV_CODEC_ID_PCM_S16LE:
196 #endif /* HAVE_BIGENDIAN */
197     case AV_CODEC_ID_PCM_U8:
198         memcpy(dst, samples, n * sample_size);
199         break;
200 #if HAVE_BIGENDIAN
201     case AV_CODEC_ID_PCM_S16BE_PLANAR:
202 #else
203     case AV_CODEC_ID_PCM_S16LE_PLANAR:
204     case AV_CODEC_ID_PCM_S32LE_PLANAR:
205 #endif /* HAVE_BIGENDIAN */
206         n /= avctx->channels;
207         for (c = 0; c < avctx->channels; c++) {
208             const uint8_t *src = frame->extended_data[c];
209             bytestream_put_buffer(&dst, src, n * sample_size);
210         }
211         break;
212     case AV_CODEC_ID_PCM_ALAW:
213         for (; n > 0; n--) {
214             v      = *samples++;
215             *dst++ = linear_to_alaw[(v + 32768) >> 2];
216         }
217         break;
218     case AV_CODEC_ID_PCM_MULAW:
219         for (; n > 0; n--) {
220             v      = *samples++;
221             *dst++ = linear_to_ulaw[(v + 32768) >> 2];
222         }
223         break;
224     default:
225         return -1;
226     }
227
228     *got_packet_ptr = 1;
229     return 0;
230 }
231
232 typedef struct PCMDecode {
233     AVFrame frame;
234     short   table[256];
235 } PCMDecode;
236
237 static av_cold int pcm_decode_init(AVCodecContext *avctx)
238 {
239     PCMDecode *s = avctx->priv_data;
240     int i;
241
242     if (avctx->channels <= 0) {
243         av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
244         return AVERROR(EINVAL);
245     }
246
247     switch (avctx->codec_id) {
248     case AV_CODEC_ID_PCM_ALAW:
249         for (i = 0; i < 256; i++)
250             s->table[i] = alaw2linear(i);
251         break;
252     case AV_CODEC_ID_PCM_MULAW:
253         for (i = 0; i < 256; i++)
254             s->table[i] = ulaw2linear(i);
255         break;
256     default:
257         break;
258     }
259
260     avctx->sample_fmt = avctx->codec->sample_fmts[0];
261
262     if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
263         avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id);
264
265     avcodec_get_frame_defaults(&s->frame);
266     avctx->coded_frame = &s->frame;
267
268     return 0;
269 }
270
271 /**
272  * Read PCM samples macro
273  * @param size   Data size of native machine format
274  * @param endian bytestream_get_xxx() endian suffix
275  * @param src    Source pointer (variable name)
276  * @param dst    Destination pointer (variable name)
277  * @param n      Total number of samples (variable name)
278  * @param shift  Bitshift (bits)
279  * @param offset Sample value offset
280  */
281 #define DECODE(size, endian, src, dst, n, shift, offset)                \
282     for (; n > 0; n--) {                                                \
283         uint ## size ## _t v = bytestream_get_ ## endian(&src);         \
284         AV_WN ## size ## A(dst, (v - offset) << shift);                 \
285         dst += size / 8;                                                \
286     }
287
288 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)         \
289     n /= avctx->channels;                                               \
290     for (c = 0; c < avctx->channels; c++) {                             \
291         int i;                                                          \
292         dst = s->frame.extended_data[c];                                \
293         for (i = n; i > 0; i--) {                                       \
294             uint ## size ## _t v = bytestream_get_ ## endian(&src);     \
295             AV_WN ## size ## A(dst, (v - offset) << shift);             \
296             dst += size / 8;                                            \
297         }                                                               \
298     }
299
300 static int pcm_decode_frame(AVCodecContext *avctx, void *data,
301                             int *got_frame_ptr, AVPacket *avpkt)
302 {
303     const uint8_t *src = avpkt->data;
304     int buf_size       = avpkt->size;
305     PCMDecode *s       = avctx->priv_data;
306     int sample_size, c, n, ret, samples_per_block;
307     uint8_t *samples;
308     int32_t *dst_int32_t;
309
310     sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
311
312     /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
313     samples_per_block = 1;
314     if (AV_CODEC_ID_PCM_DVD == avctx->codec_id) {
315         if (avctx->bits_per_coded_sample != 20 &&
316             avctx->bits_per_coded_sample != 24) {
317             av_log(avctx, AV_LOG_ERROR,
318                    "PCM DVD unsupported sample depth %i\n",
319                    avctx->bits_per_coded_sample);
320             return AVERROR(EINVAL);
321         }
322         /* 2 samples are interleaved per block in PCM_DVD */
323         samples_per_block = 2;
324         sample_size       = avctx->bits_per_coded_sample * 2 / 8;
325     } else if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
326         /* we process 40-bit blocks per channel for LXF */
327         samples_per_block = 2;
328         sample_size       = 5;
329     }
330
331     if (sample_size == 0) {
332         av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
333         return AVERROR(EINVAL);
334     }
335
336     if (avctx->channels == 0) {
337         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
338         return AVERROR(EINVAL);
339     }
340
341     n = avctx->channels * sample_size;
342
343     if (n && buf_size % n) {
344         if (buf_size < n) {
345             av_log(avctx, AV_LOG_ERROR,
346                    "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
347                    buf_size, n);
348             return AVERROR_INVALIDDATA;
349         } else
350             buf_size -= buf_size % n;
351     }
352
353     n = buf_size / sample_size;
354
355     /* get output buffer */
356     s->frame.nb_samples = n * samples_per_block / avctx->channels;
357     if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
358         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
359         return ret;
360     }
361     samples = s->frame.data[0];
362
363     switch (avctx->codec_id) {
364     case AV_CODEC_ID_PCM_U32LE:
365         DECODE(32, le32, src, samples, n, 0, 0x80000000)
366         break;
367     case AV_CODEC_ID_PCM_U32BE:
368         DECODE(32, be32, src, samples, n, 0, 0x80000000)
369         break;
370     case AV_CODEC_ID_PCM_S24LE:
371         DECODE(32, le24, src, samples, n, 8, 0)
372         break;
373     case AV_CODEC_ID_PCM_S24LE_PLANAR:
374         DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
375         break;
376     case AV_CODEC_ID_PCM_S24BE:
377         DECODE(32, be24, src, samples, n, 8, 0)
378         break;
379     case AV_CODEC_ID_PCM_U24LE:
380         DECODE(32, le24, src, samples, n, 8, 0x800000)
381         break;
382     case AV_CODEC_ID_PCM_U24BE:
383         DECODE(32, be24, src, samples, n, 8, 0x800000)
384         break;
385     case AV_CODEC_ID_PCM_S24DAUD:
386         for (; n > 0; n--) {
387             uint32_t v = bytestream_get_be24(&src);
388             v >>= 4; // sync flags are here
389             AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
390                              (ff_reverse[v        & 0xff] << 8));
391             samples += 2;
392         }
393         break;
394     case AV_CODEC_ID_PCM_U16LE:
395         DECODE(16, le16, src, samples, n, 0, 0x8000)
396         break;
397     case AV_CODEC_ID_PCM_U16BE:
398         DECODE(16, be16, src, samples, n, 0, 0x8000)
399         break;
400     case AV_CODEC_ID_PCM_S8:
401         for (; n > 0; n--)
402             *samples++ = *src++ + 128;
403         break;
404     case AV_CODEC_ID_PCM_S8_PLANAR:
405         n /= avctx->channels;
406         for (c = 0; c < avctx->channels; c++) {
407             int i;
408             samples = s->frame.extended_data[c];
409             for (i = n; i > 0; i--)
410                 *samples++ = *src++ + 128;
411         }
412         break;
413 #if HAVE_BIGENDIAN
414     case AV_CODEC_ID_PCM_F64LE:
415         DECODE(64, le64, src, samples, n, 0, 0)
416         break;
417     case AV_CODEC_ID_PCM_S32LE:
418     case AV_CODEC_ID_PCM_F32LE:
419         DECODE(32, le32, src, samples, n, 0, 0)
420         break;
421     case AV_CODEC_ID_PCM_S32LE_PLANAR:
422         DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
423         break;
424     case AV_CODEC_ID_PCM_S16LE:
425         DECODE(16, le16, src, samples, n, 0, 0)
426         break;
427     case AV_CODEC_ID_PCM_S16LE_PLANAR:
428         DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
429         break;
430     case AV_CODEC_ID_PCM_F64BE:
431     case AV_CODEC_ID_PCM_F32BE:
432     case AV_CODEC_ID_PCM_S32BE:
433     case AV_CODEC_ID_PCM_S16BE:
434 #else
435     case AV_CODEC_ID_PCM_F64BE:
436         DECODE(64, be64, src, samples, n, 0, 0)
437         break;
438     case AV_CODEC_ID_PCM_F32BE:
439     case AV_CODEC_ID_PCM_S32BE:
440         DECODE(32, be32, src, samples, n, 0, 0)
441         break;
442     case AV_CODEC_ID_PCM_S16BE:
443         DECODE(16, be16, src, samples, n, 0, 0)
444         break;
445     case AV_CODEC_ID_PCM_S16BE_PLANAR:
446         DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
447         break;
448     case AV_CODEC_ID_PCM_F64LE:
449     case AV_CODEC_ID_PCM_F32LE:
450     case AV_CODEC_ID_PCM_S32LE:
451     case AV_CODEC_ID_PCM_S16LE:
452 #endif /* HAVE_BIGENDIAN */
453     case AV_CODEC_ID_PCM_U8:
454         memcpy(samples, src, n * sample_size);
455         break;
456 #if HAVE_BIGENDIAN
457     case AV_CODEC_ID_PCM_S16BE_PLANAR:
458 #else
459     case AV_CODEC_ID_PCM_S16LE_PLANAR:
460     case AV_CODEC_ID_PCM_S32LE_PLANAR:
461 #endif /* HAVE_BIGENDIAN */
462         n /= avctx->channels;
463         for (c = 0; c < avctx->channels; c++) {
464             samples = s->frame.extended_data[c];
465             bytestream_get_buffer(&src, samples, n * sample_size);
466         }
467         break;
468     case AV_CODEC_ID_PCM_ZORK:
469         for (; n > 0; n--) {
470             int v = *src++;
471             if (v < 128)
472                 v = 128 - v;
473             *samples++ = v;
474         }
475         break;
476     case AV_CODEC_ID_PCM_ALAW:
477     case AV_CODEC_ID_PCM_MULAW:
478         for (; n > 0; n--) {
479             AV_WN16A(samples, s->table[*src++]);
480             samples += 2;
481         }
482         break;
483     case AV_CODEC_ID_PCM_DVD:
484     {
485         const uint8_t *src8;
486         dst_int32_t = (int32_t *)s->frame.data[0];
487         n /= avctx->channels;
488         switch (avctx->bits_per_coded_sample) {
489         case 20:
490             while (n--) {
491                 c    = avctx->channels;
492                 src8 = src + 4 * c;
493                 while (c--) {
494                     *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8   & 0xf0) <<  8);
495                     *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ & 0x0f) << 12);
496                 }
497                 src = src8;
498             }
499             break;
500         case 24:
501             while (n--) {
502                 c    = avctx->channels;
503                 src8 = src + 4 * c;
504                 while (c--) {
505                     *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
506                     *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
507                 }
508                 src = src8;
509             }
510             break;
511         }
512         break;
513     }
514     case AV_CODEC_ID_PCM_LXF:
515     {
516         int i;
517         n /= avctx->channels;
518         for (c = 0; c < avctx->channels; c++) {
519             dst_int32_t = (int32_t *)s->frame.extended_data[c];
520             for (i = 0; i < n; i++) {
521                 // extract low 20 bits and expand to 32 bits
522                 *dst_int32_t++ =  (src[2]         << 28) |
523                                   (src[1]         << 20) |
524                                   (src[0]         << 12) |
525                                  ((src[2] & 0x0F) <<  8) |
526                                    src[1];
527                 // extract high 20 bits and expand to 32 bits
528                 *dst_int32_t++ =  (src[4]         << 24) |
529                                   (src[3]         << 16) |
530                                  ((src[2] & 0xF0) <<  8) |
531                                   (src[4]         <<  4) |
532                                   (src[3]         >>  4);
533                 src += 5;
534             }
535         }
536         break;
537     }
538     default:
539         return -1;
540     }
541
542     *got_frame_ptr   = 1;
543     *(AVFrame *)data = s->frame;
544
545     return buf_size;
546 }
547
548 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
549 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_)                  \
550 AVCodec ff_ ## name_ ## _encoder = {                                        \
551     .name         = #name_,                                                 \
552     .type         = AVMEDIA_TYPE_AUDIO,                                     \
553     .id           = AV_CODEC_ID_ ## id_,                                    \
554     .init         = pcm_encode_init,                                        \
555     .encode2      = pcm_encode_frame,                                       \
556     .close        = pcm_encode_close,                                       \
557     .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE,                          \
558     .sample_fmts  = (const enum AVSampleFormat[]){ sample_fmt_,             \
559                                                    AV_SAMPLE_FMT_NONE },    \
560     .long_name    = NULL_IF_CONFIG_SMALL(long_name_),                       \
561 }
562
563 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)                  \
564     PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
565 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name)                  \
566     PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
567 #define PCM_ENCODER(id, sample_fmt, name, long_name)                        \
568     PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
569
570 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
571 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_)                  \
572 AVCodec ff_ ## name_ ## _decoder = {                                        \
573     .name           = #name_,                                               \
574     .type           = AVMEDIA_TYPE_AUDIO,                                   \
575     .id             = AV_CODEC_ID_ ## id_,                                  \
576     .priv_data_size = sizeof(PCMDecode),                                    \
577     .init           = pcm_decode_init,                                      \
578     .decode         = pcm_decode_frame,                                     \
579     .capabilities   = CODEC_CAP_DR1,                                        \
580     .sample_fmts    = (const enum AVSampleFormat[]){ sample_fmt_,           \
581                                                      AV_SAMPLE_FMT_NONE },  \
582     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),                     \
583 }
584
585 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name)                  \
586     PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
587 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name)                  \
588     PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
589 #define PCM_DECODER(id, sample_fmt, name, long_name)                        \
590     PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
591
592 #define PCM_CODEC(id, sample_fmt_, name, long_name_)                    \
593     PCM_ENCODER(id, sample_fmt_, name, long_name_);                     \
594     PCM_DECODER(id, sample_fmt_, name, long_name_)
595
596 /* Note: Do not forget to add new entries to the Makefile as well. */
597 PCM_CODEC  (PCM_ALAW,         AV_SAMPLE_FMT_S16, pcm_alaw,         "PCM A-law / G.711 A-law");
598 PCM_DECODER(PCM_DVD,          AV_SAMPLE_FMT_S32, pcm_dvd,          "PCM signed 20|24-bit big-endian");
599 PCM_CODEC  (PCM_F32BE,        AV_SAMPLE_FMT_FLT, pcm_f32be,        "PCM 32-bit floating point big-endian");
600 PCM_CODEC  (PCM_F32LE,        AV_SAMPLE_FMT_FLT, pcm_f32le,        "PCM 32-bit floating point little-endian");
601 PCM_CODEC  (PCM_F64BE,        AV_SAMPLE_FMT_DBL, pcm_f64be,        "PCM 64-bit floating point big-endian");
602 PCM_CODEC  (PCM_F64LE,        AV_SAMPLE_FMT_DBL, pcm_f64le,        "PCM 64-bit floating point little-endian");
603 PCM_DECODER(PCM_LXF,          AV_SAMPLE_FMT_S32P,pcm_lxf,          "PCM signed 20-bit little-endian planar");
604 PCM_CODEC  (PCM_MULAW,        AV_SAMPLE_FMT_S16, pcm_mulaw,        "PCM mu-law / G.711 mu-law");
605 PCM_CODEC  (PCM_S8,           AV_SAMPLE_FMT_U8,  pcm_s8,           "PCM signed 8-bit");
606 PCM_CODEC  (PCM_S8_PLANAR,    AV_SAMPLE_FMT_U8P, pcm_s8_planar,    "PCM signed 8-bit planar");
607 PCM_CODEC  (PCM_S16BE,        AV_SAMPLE_FMT_S16, pcm_s16be,        "PCM signed 16-bit big-endian");
608 PCM_CODEC  (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
609 PCM_CODEC  (PCM_S16LE,        AV_SAMPLE_FMT_S16, pcm_s16le,        "PCM signed 16-bit little-endian");
610 PCM_CODEC  (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
611 PCM_CODEC  (PCM_S24BE,        AV_SAMPLE_FMT_S32, pcm_s24be,        "PCM signed 24-bit big-endian");
612 PCM_CODEC  (PCM_S24DAUD,      AV_SAMPLE_FMT_S16, pcm_s24daud,      "PCM D-Cinema audio signed 24-bit");
613 PCM_CODEC  (PCM_S24LE,        AV_SAMPLE_FMT_S32, pcm_s24le,        "PCM signed 24-bit little-endian");
614 PCM_CODEC  (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
615 PCM_CODEC  (PCM_S32BE,        AV_SAMPLE_FMT_S32, pcm_s32be,        "PCM signed 32-bit big-endian");
616 PCM_CODEC  (PCM_S32LE,        AV_SAMPLE_FMT_S32, pcm_s32le,        "PCM signed 32-bit little-endian");
617 PCM_CODEC  (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
618 PCM_CODEC  (PCM_U8,           AV_SAMPLE_FMT_U8,  pcm_u8,           "PCM unsigned 8-bit");
619 PCM_CODEC  (PCM_U16BE,        AV_SAMPLE_FMT_S16, pcm_u16be,        "PCM unsigned 16-bit big-endian");
620 PCM_CODEC  (PCM_U16LE,        AV_SAMPLE_FMT_S16, pcm_u16le,        "PCM unsigned 16-bit little-endian");
621 PCM_CODEC  (PCM_U24BE,        AV_SAMPLE_FMT_S32, pcm_u24be,        "PCM unsigned 24-bit big-endian");
622 PCM_CODEC  (PCM_U24LE,        AV_SAMPLE_FMT_S32, pcm_u24le,        "PCM unsigned 24-bit little-endian");
623 PCM_CODEC  (PCM_U32BE,        AV_SAMPLE_FMT_S32, pcm_u32be,        "PCM unsigned 32-bit big-endian");
624 PCM_CODEC  (PCM_U32LE,        AV_SAMPLE_FMT_S32, pcm_u32le,        "PCM unsigned 32-bit little-endian");
625 PCM_DECODER(PCM_ZORK,         AV_SAMPLE_FMT_U8,  pcm_zork,         "PCM Zork");
626