annotate audioconvert.c @ 8185:2608f4c27249 libavcodec

Move FFT-specific MMX optimizations out of the 'ifdef HAVE_MMX' block. The MMX dependency is already handled by configure.
author diego
date Thu, 20 Nov 2008 22:50:13 +0000
parents ea2c20535551
children ffb82d54ecdc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
1 /*
3596
2dc9933dc75f cosmetics
michael
parents: 3594
diff changeset
2 * audio conversion
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
3 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
10c577c37617 audio format conversion
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3596
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3596
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3596
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
10c577c37617 audio format conversion
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3596
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3596
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10c577c37617 audio format conversion
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10c577c37617 audio format conversion
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
10c577c37617 audio format conversion
michael
parents:
diff changeset
16 *
10c577c37617 audio format conversion
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3596
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
10c577c37617 audio format conversion
michael
parents:
diff changeset
20 */
10c577c37617 audio format conversion
michael
parents:
diff changeset
21
10c577c37617 audio format conversion
michael
parents:
diff changeset
22 /**
10c577c37617 audio format conversion
michael
parents:
diff changeset
23 * @file audioconvert.c
3596
2dc9933dc75f cosmetics
michael
parents: 3594
diff changeset
24 * audio conversion
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
25 * @author Michael Niedermayer <michaelni@gmx.at>
10c577c37617 audio format conversion
michael
parents:
diff changeset
26 */
10c577c37617 audio format conversion
michael
parents:
diff changeset
27
7458
eb63aa50bf85 Revert r14484 hunk that deleted the 'include avcodec.h' statement.
pross
parents: 7453
diff changeset
28 #include "avcodec.h"
7453
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
29 #include "audioconvert.h"
8098
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
30 #include <libavutil/avstring.h>
7453
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
31
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
32 typedef struct SampleFmtInfo {
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
33 const char *name;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
34 int bits;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
35 } SampleFmtInfo;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
36
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
37 /** this table gives more information about formats */
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
38 static const SampleFmtInfo sample_fmt_info[SAMPLE_FMT_NB] = {
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
39 [SAMPLE_FMT_U8] = { .name = "u8", .bits = 8 },
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
40 [SAMPLE_FMT_S16] = { .name = "s16", .bits = 16 },
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
41 [SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 },
7612
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
42 [SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 },
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
43 [SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64 },
7453
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
44 };
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
45
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
46 const char *avcodec_get_sample_fmt_name(int sample_fmt)
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
47 {
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
48 if (sample_fmt < 0 || sample_fmt >= SAMPLE_FMT_NB)
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
49 return NULL;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
50 return sample_fmt_info[sample_fmt].name;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
51 }
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
52
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
53 enum SampleFormat avcodec_get_sample_fmt(const char* name)
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
54 {
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
55 int i;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
56
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
57 for (i=0; i < SAMPLE_FMT_NB; i++)
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
58 if (!strcmp(sample_fmt_info[i].name, name))
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
59 return i;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
60 return SAMPLE_FMT_NONE;
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
61 }
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
62
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
63 void avcodec_sample_fmt_string (char *buf, int buf_size, int sample_fmt)
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
64 {
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
65 /* print header */
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
66 if (sample_fmt < 0)
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
67 snprintf (buf, buf_size, "name " " depth");
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
68 else if (sample_fmt < SAMPLE_FMT_NB) {
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
69 SampleFmtInfo info= sample_fmt_info[sample_fmt];
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
70 snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits);
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
71 }
d1d15f2dca4c Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents: 5215
diff changeset
72 }
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
73
8098
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
74 static const char* const channel_names[]={
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
75 "FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC",
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
76 "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL",
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
77 "TBC", "TBR",
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
78 [29] = "DL",
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
79 [30] = "DR",
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
80 };
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
81
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
82 const char *get_channel_name(int channel_id)
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
83 {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
84 if (channel_id<0 || channel_id>=FF_ARRAY_ELEMS(channel_names))
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
85 return NULL;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
86 return channel_names[channel_id];
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
87 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
88
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
89 int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name)
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
90 {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
91 switch(nb_channels) {
8102
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
92 case 1: return CH_LAYOUT_MONO;
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
93 case 2: return CH_LAYOUT_STEREO;
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
94 case 3: return CH_LAYOUT_SURROUND;
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
95 case 4: return CH_LAYOUT_QUAD;
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
96 case 5: return CH_LAYOUT_5POINT0;
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
97 case 6: return CH_LAYOUT_5POINT1;
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
98 case 8: return CH_LAYOUT_7POINT1;
8098
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
99 default: return 0;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
100 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
101 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
102
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
103 static const struct {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
104 const char *name;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
105 int nb_channels;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
106 int64_t layout;
8155
ea2c20535551 One const is enough.
cehoyos
parents: 8102
diff changeset
107 } channel_layout_map[] = {
8102
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
108 { "mono", 1, CH_LAYOUT_MONO },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
109 { "stereo", 2, CH_LAYOUT_STEREO },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
110 { "surround", 3, CH_LAYOUT_SURROUND },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
111 { "quad", 4, CH_LAYOUT_QUAD },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
112 { "5.0", 5, CH_LAYOUT_5POINT0 },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
113 { "5.1", 6, CH_LAYOUT_5POINT1 },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
114 { "5.1+downmix", 8, CH_LAYOUT_5POINT1|CH_LAYOUT_STEREO_DOWNMIX, },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
115 { "7.1", 8, CH_LAYOUT_7POINT1 },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
116 { "7.1(wide)", 8, CH_LAYOUT_7POINT1_WIDE },
04295cbc0e9b Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents: 8098
diff changeset
117 { "7.1+downmix", 10, CH_LAYOUT_7POINT1|CH_LAYOUT_STEREO_DOWNMIX, },
8098
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
118 { 0 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
119 };
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
120
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
121 void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout)
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
122 {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
123 int i;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
124
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
125 if (channel_layout==0)
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
126 channel_layout = avcodec_guess_channel_layout(nb_channels, CODEC_ID_NONE, NULL);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
127
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
128 for (i=0; channel_layout_map[i].name; i++)
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
129 if (nb_channels == channel_layout_map[i].nb_channels &&
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
130 channel_layout == channel_layout_map[i].layout) {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
131 snprintf(buf, buf_size, channel_layout_map[i].name);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
132 return;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
133 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
134
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
135 snprintf(buf, buf_size, "%d channels", nb_channels);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
136 if (channel_layout) {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
137 int i,ch;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
138 av_strlcat(buf, " (", buf_size);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
139 for(i=0,ch=0; i<64; i++) {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
140 if ((channel_layout & (1L<<i))) {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
141 const char *name = get_channel_name(i);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
142 if (name) {
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
143 if (ch>0) av_strlcat(buf, "|", buf_size);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
144 av_strlcat(buf, name, buf_size);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
145 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
146 ch++;
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
147 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
148 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
149 av_strlcat(buf, ")", buf_size);
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
150 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
151 }
c2ab7a8958ed Add audio channel layout API to libavcodec.
pross
parents: 7984
diff changeset
152
7459
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
153 struct AVAudioConvert {
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
154 int in_channels, out_channels;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
155 int fmt_pair;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
156 };
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
157
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
158 AVAudioConvert *av_audio_convert_alloc(enum SampleFormat out_fmt, int out_channels,
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
159 enum SampleFormat in_fmt, int in_channels,
7984
24f2b8cc7918 Remove duplicate "const" qualifier for *matrix.
gpoirier
parents: 7825
diff changeset
160 const float *matrix, int flags)
7459
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
161 {
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
162 AVAudioConvert *ctx;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
163 if (in_channels!=out_channels)
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
164 return NULL; /* FIXME: not supported */
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
165 ctx = av_malloc(sizeof(AVAudioConvert));
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
166 if (!ctx)
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
167 return NULL;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
168 ctx->in_channels = in_channels;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
169 ctx->out_channels = out_channels;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
170 ctx->fmt_pair = out_fmt + SAMPLE_FMT_NB*in_fmt;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
171 return ctx;
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
172 }
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
173
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
174 void av_audio_convert_free(AVAudioConvert *ctx)
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
175 {
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
176 av_free(ctx);
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
177 }
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
178
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
179 int av_audio_convert(AVAudioConvert *ctx,
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
180 void * const out[6], const int out_stride[6],
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
181 const void * const in[6], const int in_stride[6], int len)
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
182 {
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
183 int ch;
10c577c37617 audio format conversion
michael
parents:
diff changeset
184
10c577c37617 audio format conversion
michael
parents:
diff changeset
185 //FIXME optimize common cases
10c577c37617 audio format conversion
michael
parents:
diff changeset
186
7459
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
187 for(ch=0; ch<ctx->out_channels; ch++){
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
188 const int is= in_stride[ch];
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
189 const int os= out_stride[ch];
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
190 uint8_t *pi= in[ch];
10c577c37617 audio format conversion
michael
parents:
diff changeset
191 uint8_t *po= out[ch];
7459
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
192 uint8_t *end= po + os*len;
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
193 if(!out[ch])
10c577c37617 audio format conversion
michael
parents:
diff changeset
194 continue;
10c577c37617 audio format conversion
michael
parents:
diff changeset
195
10c577c37617 audio format conversion
michael
parents:
diff changeset
196 #define CONV(ofmt, otype, ifmt, expr)\
7459
283eeda62184 Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
pross
parents: 7458
diff changeset
197 if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
198 do{\
10c577c37617 audio format conversion
michael
parents:
diff changeset
199 *(otype*)po = expr; pi += is; po += os;\
10c577c37617 audio format conversion
michael
parents:
diff changeset
200 }while(po < end);\
10c577c37617 audio format conversion
michael
parents:
diff changeset
201 }
10c577c37617 audio format conversion
michael
parents:
diff changeset
202
5127
4dbe6578f811 misc spelling fixes
diego
parents: 3947
diff changeset
203 //FIXME put things below under ifdefs so we do not waste space for cases no codec will need
4dbe6578f811 misc spelling fixes
diego
parents: 3947
diff changeset
204 //FIXME rounding and clipping ?
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
205
10c577c37617 audio format conversion
michael
parents:
diff changeset
206 CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(uint8_t*)pi)
10c577c37617 audio format conversion
michael
parents:
diff changeset
207 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<8)
10c577c37617 audio format conversion
michael
parents:
diff changeset
208 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<24)
10c577c37617 audio format conversion
michael
parents:
diff changeset
209 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
7612
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
210 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
211 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S16, (*(int16_t*)pi>>8) + 0x80)
10c577c37617 audio format conversion
michael
parents:
diff changeset
212 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S16, *(int16_t*)pi)
10c577c37617 audio format conversion
michael
parents:
diff changeset
213 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S16, *(int16_t*)pi<<16)
10c577c37617 audio format conversion
michael
parents:
diff changeset
214 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S16, *(int16_t*)pi*(1.0 / (1<<15)))
7612
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
215 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S16, *(int16_t*)pi*(1.0 / (1<<15)))
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
216 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S32, (*(int32_t*)pi>>24) + 0x80)
10c577c37617 audio format conversion
michael
parents:
diff changeset
217 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S32, *(int32_t*)pi>>16)
10c577c37617 audio format conversion
michael
parents:
diff changeset
218 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32, *(int32_t*)pi)
10c577c37617 audio format conversion
michael
parents:
diff changeset
219 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S32, *(int32_t*)pi*(1.0 / (1<<31)))
7612
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
220 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S32, *(int32_t*)pi*(1.0 / (1<<31)))
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
221 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<7)) + 0x80)
10c577c37617 audio format conversion
michael
parents:
diff changeset
222 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<15)))
10c577c37617 audio format conversion
michael
parents:
diff changeset
223 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<31)))
10c577c37617 audio format conversion
michael
parents:
diff changeset
224 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_FLT, *(float*)pi)
7612
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
225 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_FLT, *(float*)pi)
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
226 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, lrint(*(double*)pi * (1<<7)) + 0x80)
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
227 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, lrint(*(double*)pi * (1<<15)))
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
228 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, lrint(*(double*)pi * (1<<31)))
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
229 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_DBL, *(double*)pi)
1302ec81afc0 Add SAMPLE_FMT_DBL.
pross
parents: 7459
diff changeset
230 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_DBL, *(double*)pi)
3594
10c577c37617 audio format conversion
michael
parents:
diff changeset
231 else return -1;
10c577c37617 audio format conversion
michael
parents:
diff changeset
232 }
10c577c37617 audio format conversion
michael
parents:
diff changeset
233 return 0;
10c577c37617 audio format conversion
michael
parents:
diff changeset
234 }