Commit b384e031 authored by Justin Ruggles's avatar Justin Ruggles

lavfi: add volume filter

Based on the volume filter in FFmpeg written by Stefano Sabatini
<stefasab@gmail.com>.
parent 9d5c62ba
......@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
version <next>:
- ashowinfo audio filter
- 24-bit FLAC encoding
- audio volume filter
version 9_beta2:
......
......@@ -359,6 +359,59 @@ not meant to be used directly, it is inserted automatically by libavfilter
whenever conversion is needed. Use the @var{aformat} filter to force a specific
conversion.
@section volume
Adjust the input audio volume.
The filter accepts the following named parameters:
@table @option
@item volume
Expresses how the audio volume will be increased or decreased.
Output values are clipped to the maximum value.
The output audio volume is given by the relation:
@example
@var{output_volume} = @var{volume} * @var{input_volume}
@end example
Default value for @var{volume} is 1.0.
@item precision
Mathematical precision.
This determines which input sample formats will be allowed, which affects the
precision of the volume scaling.
@table @option
@item fixed
8-bit fixed-point; limits input sample format to U8, S16, and S32.
@item float
32-bit floating-point; limits input sample format to FLT. (default)
@item double
64-bit floating-point; limits input sample format to DBL.
@end table
@end table
@subsection Examples
@itemize
@item
Halve the input audio volume:
@example
volume=volume=0.5
volume=volume=1/2
volume=volume=-6.0206dB
@end example
@item
Increase input audio power by 6 decibels using fixed-point precision:
@example
volume=volume=6dB:precision=fixed
@end example
@end itemize
@c man end AUDIO FILTERS
@chapter Audio Sources
......
......@@ -35,6 +35,7 @@ OBJS-$(CONFIG_CHANNELMAP_FILTER) += af_channelmap.o
OBJS-$(CONFIG_CHANNELSPLIT_FILTER) += af_channelsplit.o
OBJS-$(CONFIG_JOIN_FILTER) += af_join.o
OBJS-$(CONFIG_RESAMPLE_FILTER) += af_resample.o
OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o
OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
......
This diff is collapsed.
/*
* This file is part of Libav.
*
* Libav 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.
*
* Libav 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 Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* audio volume filter
*/
#ifndef AVFILTER_AF_VOLUME_H
#define AVFILTER_AF_VOLUME_H
#include "libavutil/common.h"
#include "libavutil/float_dsp.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
enum PrecisionType {
PRECISION_FIXED = 0,
PRECISION_FLOAT,
PRECISION_DOUBLE,
};
typedef struct VolumeContext {
const AVClass *class;
AVFloatDSPContext fdsp;
enum PrecisionType precision;
double volume;
int volume_i;
int channels;
int planes;
enum AVSampleFormat sample_fmt;
void (*scale_samples)(uint8_t *dst, const uint8_t *src, int nb_samples,
int volume);
int samples_align;
} VolumeContext;
#endif /* AVFILTER_AF_VOLUME_H */
......@@ -46,6 +46,7 @@ void avfilter_register_all(void)
REGISTER_FILTER (CHANNELSPLIT,channelsplit,af);
REGISTER_FILTER (JOIN, join, af);
REGISTER_FILTER (RESAMPLE, resample, af);
REGISTER_FILTER (VOLUME, volume, af);
REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
......
......@@ -29,7 +29,7 @@
#include "libavutil/avutil.h"
#define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 2
#define LIBAVFILTER_VERSION_MINOR 3
#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