Mercurial > libavcodec.hg
annotate audioconvert.c @ 12426:7defcfe74c72 libavcodec
Flush the PutBitsContext at the end of each block when encoding ADPCM IMA QT
author | mstorsjo |
---|---|
date | Thu, 26 Aug 2010 07:39:34 +0000 |
parents | d23e48091c51 |
children |
rev | line source |
---|---|
3594 | 1 /* |
3596 | 2 * audio conversion |
3594 | 3 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> |
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 | 8 * modify it under the terms of the GNU Lesser General Public |
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 | 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 | 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 | |
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 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | |
21 | |
22 /** | |
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11320
diff
changeset
|
23 * @file |
3596 | 24 * audio conversion |
3594 | 25 * @author Michael Niedermayer <michaelni@gmx.at> |
26 */ | |
27 | |
8630
ffb82d54ecdc
Use "" instead of <> when #including non-system headers.
diego
parents:
8155
diff
changeset
|
28 #include "libavutil/avstring.h" |
11657 | 29 #include "libavutil/libm.h" |
7458
eb63aa50bf85
Revert r14484 hunk that deleted the 'include avcodec.h' statement.
pross
parents:
7453
diff
changeset
|
30 #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
|
31 #include "audioconvert.h" |
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 |
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 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
|
34 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
|
35 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
|
36 } 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
|
37 |
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 /** 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
|
39 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
|
40 [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
|
41 [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
|
42 [SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 }, |
7612 | 43 [SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 }, |
44 [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
|
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 |
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 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
|
48 { |
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 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
|
50 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
|
51 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
|
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 |
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 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
|
55 { |
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 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
|
57 |
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 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
|
59 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
|
60 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
|
61 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
|
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 |
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 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
|
65 { |
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 /* 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 } |
d1d15f2dca4c
Add sample format support functions: avcodec_get_sample_fmt_name(), avcodec_get_sample_fmt(), avcodec_sample_fmt_string()
pross
parents:
5215
diff
changeset
|
73 } |
3594 | 74 |
8098 | 75 static const char* const channel_names[]={ |
76 "FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC", | |
77 "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL", | |
78 "TBC", "TBR", | |
79 [29] = "DL", | |
80 [30] = "DR", | |
81 }; | |
82 | |
11320
01d5e38a0d35
Make function get_channel_name() static: It is only used in audioconvert.c.
cehoyos
parents:
9851
diff
changeset
|
83 static const char *get_channel_name(int channel_id) |
8098 | 84 { |
85 if (channel_id<0 || channel_id>=FF_ARRAY_ELEMS(channel_names)) | |
86 return NULL; | |
87 return channel_names[channel_id]; | |
88 } | |
89 | |
90 int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name) | |
91 { | |
92 switch(nb_channels) { | |
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
93 case 1: return CH_LAYOUT_MONO; |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
94 case 2: return CH_LAYOUT_STEREO; |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
95 case 3: return CH_LAYOUT_SURROUND; |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
96 case 4: return CH_LAYOUT_QUAD; |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
97 case 5: return CH_LAYOUT_5POINT0; |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
98 case 6: return CH_LAYOUT_5POINT1; |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
99 case 8: return CH_LAYOUT_7POINT1; |
8098 | 100 default: return 0; |
101 } | |
102 } | |
103 | |
104 static const struct { | |
105 const char *name; | |
106 int nb_channels; | |
107 int64_t layout; | |
8155 | 108 } channel_layout_map[] = { |
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
109 { "mono", 1, CH_LAYOUT_MONO }, |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
110 { "stereo", 2, CH_LAYOUT_STEREO }, |
9502 | 111 { "4.0", 4, CH_LAYOUT_4POINT0 }, |
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
112 { "quad", 4, CH_LAYOUT_QUAD }, |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
113 { "5.0", 5, CH_LAYOUT_5POINT0 }, |
9410
f7bd7e90ef9f
Add names for 5.0 and 5.1 back speaker channel layouts.
jbr
parents:
8784
diff
changeset
|
114 { "5.0", 5, CH_LAYOUT_5POINT0_BACK }, |
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
115 { "5.1", 6, CH_LAYOUT_5POINT1 }, |
9410
f7bd7e90ef9f
Add names for 5.0 and 5.1 back speaker channel layouts.
jbr
parents:
8784
diff
changeset
|
116 { "5.1", 6, CH_LAYOUT_5POINT1_BACK }, |
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
117 { "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
|
118 { "7.1", 8, CH_LAYOUT_7POINT1 }, |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
119 { "7.1(wide)", 8, CH_LAYOUT_7POINT1_WIDE }, |
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8098
diff
changeset
|
120 { "7.1+downmix", 10, CH_LAYOUT_7POINT1|CH_LAYOUT_STEREO_DOWNMIX, }, |
8098 | 121 { 0 } |
122 }; | |
123 | |
12425 | 124 int64_t avcodec_get_channel_layout(const char *name) |
125 { | |
126 int i = 0; | |
127 do { | |
128 if (!strcmp(channel_layout_map[i].name, name)) | |
129 return channel_layout_map[i].layout; | |
130 i++; | |
131 } while (channel_layout_map[i].name); | |
132 | |
133 return 0; | |
134 } | |
135 | |
8098 | 136 void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout) |
137 { | |
138 int i; | |
139 | |
140 for (i=0; channel_layout_map[i].name; i++) | |
141 if (nb_channels == channel_layout_map[i].nb_channels && | |
142 channel_layout == channel_layout_map[i].layout) { | |
8784 | 143 av_strlcpy(buf, channel_layout_map[i].name, buf_size); |
8098 | 144 return; |
145 } | |
146 | |
147 snprintf(buf, buf_size, "%d channels", nb_channels); | |
148 if (channel_layout) { | |
149 int i,ch; | |
150 av_strlcat(buf, " (", buf_size); | |
151 for(i=0,ch=0; i<64; i++) { | |
152 if ((channel_layout & (1L<<i))) { | |
153 const char *name = get_channel_name(i); | |
154 if (name) { | |
155 if (ch>0) av_strlcat(buf, "|", buf_size); | |
156 av_strlcat(buf, name, buf_size); | |
157 } | |
158 ch++; | |
159 } | |
160 } | |
161 av_strlcat(buf, ")", buf_size); | |
162 } | |
163 } | |
164 | |
9511
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
165 int avcodec_channel_layout_num_channels(int64_t channel_layout) |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
166 { |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
167 int count; |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
168 uint64_t x = channel_layout; |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
169 for (count = 0; x; count++) |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
170 x &= x-1; // unset lowest set bit |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
171 return count; |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
172 } |
c2dba7ed94dc
Check that channel layout is compatible with number of channels for
jbr
parents:
9502
diff
changeset
|
173 |
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
|
174 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
|
175 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
|
176 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
|
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 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
|
180 enum SampleFormat in_fmt, int in_channels, |
7984 | 181 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
|
182 { |
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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 } |
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
|
194 |
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
|
195 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
|
196 { |
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 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
|
198 } |
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
|
199 |
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
|
200 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
|
201 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
|
202 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
|
203 { |
3594 | 204 int ch; |
205 | |
206 //FIXME optimize common cases | |
207 | |
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
|
208 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
|
209 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
|
210 const int os= out_stride[ch]; |
8635 | 211 const uint8_t *pi= in[ch]; |
3594 | 212 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
|
213 uint8_t *end= po + os*len; |
3594 | 214 if(!out[ch]) |
215 continue; | |
216 | |
217 #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
|
218 if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\ |
3594 | 219 do{\ |
220 *(otype*)po = expr; pi += is; po += os;\ | |
221 }while(po < end);\ | |
222 } | |
223 | |
5127 | 224 //FIXME put things below under ifdefs so we do not waste space for cases no codec will need |
11652
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
225 //FIXME rounding ? |
3594 | 226 |
8635 | 227 CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(const uint8_t*)pi) |
228 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8) | |
229 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<24) | |
230 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7))) | |
231 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7))) | |
232 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S16, (*(const int16_t*)pi>>8) + 0x80) | |
233 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S16, *(const int16_t*)pi) | |
234 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S16, *(const int16_t*)pi<<16) | |
235 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15))) | |
236 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15))) | |
237 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S32, (*(const int32_t*)pi>>24) + 0x80) | |
238 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S32, *(const int32_t*)pi>>16) | |
239 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32, *(const int32_t*)pi) | |
240 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) | |
241 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) | |
11652
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
242 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80)) |
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
243 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15)))) |
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
244 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31)))) |
8635 | 245 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_FLT, *(const float*)pi) |
246 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_FLT, *(const float*)pi) | |
11652
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
247 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, av_clip_uint8( lrint(*(const double*)pi * (1<<7)) + 0x80)) |
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
248 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, av_clip_int16( lrint(*(const double*)pi * (1<<15)))) |
8b6f3d3b55cb
Move clipping of audio samples (for those codecs outputting float) from decoder
rbultje
parents:
11644
diff
changeset
|
249 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31)))) |
8635 | 250 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_DBL, *(const double*)pi) |
251 else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_DBL, *(const double*)pi) | |
3594 | 252 else return -1; |
253 } | |
254 return 0; | |
255 } |