Commit 37cc443c authored by Stefano Sabatini's avatar Stefano Sabatini Committed by Stefano Sabatini

lavfi: add audio convert filter

Add aconvert filter to perform sample format, channel layout, and
packing format conversion.

The aconvert code depends on audio conversion code in libavcodec, so
this requires a dependency on libavcodec.

Based on previous work by S.N. Hemanth Meenakshisundaram and Mina Nagy
Zaki, performed for the GSoC 2010 and 2011.
parent 553c5e9f
......@@ -55,6 +55,7 @@ easier to use. The changes are:
- H.264 Decoding on Android via Stagefright
- Prores decoder
- BIN/XBIN/ADF/IDF text file decoder
- aconvert audio filter added
version 0.8:
......
......@@ -1575,6 +1575,7 @@ udp_protocol_deps="network"
# filters
abuffer_filter_deps="strtok_r"
aconvert_filter_deps="strtok_r"
aformat_filter_deps="strtok_r"
amovie_filter_deps="avcodec avformat"
blackframe_filter_deps="gpl"
......
......@@ -99,6 +99,42 @@ build.
Below is a description of the currently available audio filters.
@section aconvert
Convert the input audio format to the specified formats.
The filter accepts a string of the form:
"@var{sample_format}:@var{channel_layout}:@var{packing_format}".
@var{sample_format} specifies the sample format, and can be a string or
the corresponding numeric value defined in @file{libavutil/samplefmt.h}.
@var{channel_layout} specifies the channel layout, and can be a string
or the corresponding numer value defined in @file{libavutil/chlayout.h}.
@var{packing_format} specifies the type of packing in output, can be one
of "planar" or "packed", or the corresponding numeric values "0" or "1".
The special parameter "auto", signifies that the filter will
automatically select the output format depending on the output filter.
Some examples follow.
@itemize
@item
Convert input to unsigned 8-bit, stereo, packed:
@example
aconvert=u8:stereo:packed
@end example
@item
Convert input to unsigned 8-bit, automatically select out channel layout
and packing format:
@example
aconvert=u8:auto:auto
@end example
@end itemize
@section aformat
Convert the input audio to one of the specified formats. The framework will
......
......@@ -2,6 +2,8 @@ include $(SUBDIR)../config.mak
NAME = avfilter
FFLIBS = avutil
FFLIBS-$(CONFIG_ACONVERT_FILTER) += avcodec
FFLIBS-$(CONFIG_AMOVIE_FILTER) += avformat avcodec
FFLIBS-$(CONFIG_ARESAMPLE_FILTER) += avcodec
FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec
......@@ -20,6 +22,7 @@ OBJS = allfilters.o \
OBJS-$(CONFIG_AVCODEC) += avcodec.o
OBJS-$(CONFIG_ACONVERT_FILTER) += af_aconvert.o
OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o
OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o
......
This diff is collapsed.
/*
* Copyright (c) 2011 Mina Nagy Zaki
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* audio rematrixing functions, based on functions from libavcodec/resample.c
*/
#if defined(FLOATING)
# define DIV2 /2
#else
# define DIV2 >>1
#endif
REMATRIX_FUNC_SIG(stereo_to_mono_packed)
{
while (nb_samples >= 4) {
outp[0][0] = (inp[0][0] + inp[0][1]) DIV2;
outp[0][1] = (inp[0][2] + inp[0][3]) DIV2;
outp[0][2] = (inp[0][4] + inp[0][5]) DIV2;
outp[0][3] = (inp[0][6] + inp[0][7]) DIV2;
outp[0] += 4;
inp[0] += 8;
nb_samples -= 4;
}
while (nb_samples--) {
outp[0][0] = (inp[0][0] + inp[0][1]) DIV2;
outp[0]++;
inp[0] += 2;
}
}
REMATRIX_FUNC_SIG(stereo_downmix_packed)
{
while (nb_samples--) {
*outp[0]++ = inp[0][0];
*outp[0]++ = inp[0][1];
inp[0] += aconvert->in_nb_channels;
}
}
REMATRIX_FUNC_SIG(mono_to_stereo_packed)
{
while (nb_samples >= 4) {
outp[0][0] = outp[0][1] = inp[0][0];
outp[0][2] = outp[0][3] = inp[0][1];
outp[0][4] = outp[0][5] = inp[0][2];
outp[0][6] = outp[0][7] = inp[0][3];
outp[0] += 8;
inp[0] += 4;
nb_samples -= 4;
}
while (nb_samples--) {
outp[0][0] = outp[0][1] = inp[0][0];
outp[0] += 2;
inp[0] += 1;
}
}
/**
* This is for when we have more than 2 input channels, need to downmix to mono
* and do not have a conversion formula available. We just use first two input
* channels - left and right. This is a placeholder until more conversion
* functions are written.
*/
REMATRIX_FUNC_SIG(mono_downmix_packed)
{
while (nb_samples--) {
outp[0][0] = (inp[0][0] + inp[0][1]) DIV2;
inp[0] += aconvert->in_nb_channels;
outp[0]++;
}
}
REMATRIX_FUNC_SIG(mono_downmix_planar)
{
FMT_TYPE *out = outp[0];
while (nb_samples >= 4) {
out[0] = (inp[0][0] + inp[1][0]) DIV2;
out[1] = (inp[0][1] + inp[1][1]) DIV2;
out[2] = (inp[0][2] + inp[1][2]) DIV2;
out[3] = (inp[0][3] + inp[1][3]) DIV2;
out += 4;
inp[0] += 4;
inp[1] += 4;
nb_samples -= 4;
}
while (nb_samples--) {
out[0] = (inp[0][0] + inp[1][0]) DIV2;
out++;
inp[0]++;
inp[1]++;
}
}
/* Stereo to 5.1 output */
REMATRIX_FUNC_SIG(stereo_to_surround_5p1_packed)
{
while (nb_samples--) {
outp[0][0] = inp[0][0]; /* left */
outp[0][1] = inp[0][1]; /* right */
outp[0][2] = (inp[0][0] + inp[0][1]) DIV2; /* center */
outp[0][3] = 0; /* low freq */
outp[0][4] = 0; /* FIXME: left surround: -3dB or -6dB or -9dB of stereo left */
outp[0][5] = 0; /* FIXME: right surroud: -3dB or -6dB or -9dB of stereo right */
inp[0] += 2;
outp[0] += 6;
}
}
REMATRIX_FUNC_SIG(stereo_to_surround_5p1_planar)
{
while (nb_samples--) {
*outp[0]++ = *inp[0]; /* left */
*outp[1]++ = *inp[1]; /* right */
*outp[2]++ = (*inp[0] + *inp[1]) DIV2; /* center */
*outp[3]++ = 0; /* low freq */
*outp[4]++ = 0; /* FIXME: left surround: -3dB or -6dB or -9dB of stereo left */
*outp[5]++ = 0; /* FIXME: right surroud: -3dB or -6dB or -9dB of stereo right */
inp[0]++; inp[1]++;
}
}
/*
5.1 to stereo input: [fl, fr, c, lfe, rl, rr]
- Left = front_left + rear_gain * rear_left + center_gain * center
- Right = front_right + rear_gain * rear_right + center_gain * center
Where rear_gain is usually around 0.5-1.0 and
center_gain is almost always 0.7 (-3 dB)
*/
REMATRIX_FUNC_SIG(surround_5p1_to_stereo_packed)
{
while (nb_samples--) {
*outp[0]++ = inp[0][0] + (0.5 * inp[0][4]) + (0.7 * inp[0][2]); //FIXME CLIPPING!
*outp[0]++ = inp[0][1] + (0.5 * inp[0][5]) + (0.7 * inp[0][2]); //FIXME CLIPPING!
inp[0] += 6;
}
}
REMATRIX_FUNC_SIG(surround_5p1_to_stereo_planar)
{
while (nb_samples--) {
*outp[0]++ = *inp[0] + (0.5 * *inp[4]) + (0.7 * *inp[2]); //FIXME CLIPPING!
*outp[1]++ = *inp[1] + (0.5 * *inp[5]) + (0.7 * *inp[2]); //FIXME CLIPPING!
inp[0]++; inp[1]++; inp[2]++; inp[3]++; inp[4]++; inp[5]++;
}
}
#undef DIV2
#undef REMATRIX_FUNC_NAME
#undef FMT_TYPE
......@@ -34,6 +34,7 @@ void avfilter_register_all(void)
return;
initialized = 1;
REGISTER_FILTER (ACONVERT, aconvert, af);
REGISTER_FILTER (AFORMAT, aformat, af);
REGISTER_FILTER (ANULL, anull, af);
REGISTER_FILTER (ARESAMPLE, aresample, af);
......
......@@ -29,7 +29,7 @@
#include "libavutil/rational.h"
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 42
#define LIBAVFILTER_VERSION_MINOR 43
#define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment