Commit c8af852b authored by Justin Ruggles's avatar Justin Ruggles

Add libavresample

This is a new library for audio sample format, channel layout, and sample rate
conversion.
parent c5671aeb
......@@ -16,6 +16,7 @@ version <next>:
- RealAudio Lossless decoder
- ZeroCodec decoder
- drop support for avconv without libavfilter
- add libavresample audio conversion library
version 0.8:
......
......@@ -20,7 +20,7 @@ $(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_PATH)/%=%)); $(INSTALL))
endif
ALLFFLIBS = avcodec avdevice avfilter avformat avutil swscale
ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil swscale
IFLAGS := -I. -I$(SRC_PATH)
CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
......@@ -71,6 +71,7 @@ ALLMANPAGES = $(BASENAMES:%=%.1)
FFLIBS-$(CONFIG_AVDEVICE) += avdevice
FFLIBS-$(CONFIG_AVFILTER) += avfilter
FFLIBS-$(CONFIG_AVFORMAT) += avformat
FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
FFLIBS-$(CONFIG_AVCODEC) += avcodec
FFLIBS-$(CONFIG_SWSCALE) += swscale
......
......@@ -110,6 +110,7 @@ Component options:
--disable-avformat disable libavformat build
--disable-swscale disable libswscale build
--disable-avfilter disable video filter support [no]
--disable-avresample disable libavresample build [no]
--disable-pthreads disable pthreads [auto]
--disable-w32threads disable Win32 threads [auto]
--enable-x11grab enable X11 grabbing [no]
......@@ -927,6 +928,7 @@ CONFIG_LIST="
avdevice
avfilter
avformat
avresample
avisynth
bzlib
dct
......@@ -1536,7 +1538,7 @@ avdevice_deps="avcodec avformat"
avformat_deps="avcodec"
# programs
avconv_deps="avcodec avfilter avformat swscale"
avconv_deps="avcodec avfilter avformat avresample swscale"
avplay_deps="avcodec avformat swscale sdl"
avplay_select="rdft"
avprobe_deps="avcodec avformat"
......@@ -1684,6 +1686,7 @@ enable avcodec
enable avdevice
enable avfilter
enable avformat
enable avresample
enable avutil
enable swscale
......@@ -3385,6 +3388,7 @@ get_version LIBAVCODEC libavcodec/version.h
get_version LIBAVDEVICE libavdevice/avdevice.h
get_version LIBAVFILTER libavfilter/version.h
get_version LIBAVFORMAT libavformat/version.h
get_version LIBAVRESAMPLE libavresample/version.h
get_version LIBAVUTIL libavutil/avutil.h
get_version LIBSWSCALE libswscale/swscale.h
......@@ -3504,4 +3508,5 @@ pkgconfig_generate libavcodec "Libav codec library" "$LIBAVCODEC_VERSION" "$extr
pkgconfig_generate libavformat "Libav container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
pkgconfig_generate libavdevice "Libav device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
pkgconfig_generate libavfilter "Libav video filtering library" "$LIBAVFILTER_VERSION" "$extralibs"
pkgconfig_generate libavresample "Libav audio resampling library" "$LIBAVRESAMPLE_VERSION" "$extralibs"
pkgconfig_generate libswscale "Libav image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"
......@@ -2,16 +2,20 @@ Never assume the API of libav* to be stable unless at least 1 month has passed
since the last major version increase.
The last version increases were:
libavcodec: 2012-01-27
libavdevice: 2011-04-18
libavfilter: 2011-04-18
libavformat: 2012-01-27
libswscale: 2011-06-20
libavutil: 2011-04-18
libavcodec: 2012-01-27
libavdevice: 2011-04-18
libavfilter: 2011-04-18
libavformat: 2012-01-27
libavresample: 2012-xx-xx
libswscale: 2011-06-20
libavutil: 2011-04-18
API changes, most recent first:
2012-xx-xx - xxxxxxx - lavr 0.0.0
Add libavresample audio conversion library
2012-xx-xx - xxxxxxx - lavu 51.28.0 - audio_fifo.h
Add audio FIFO functions:
av_audio_fifo_free()
......
NAME = avresample
FFLIBS = avutil
HEADERS = avresample.h \
version.h
OBJS = audio_convert.o \
audio_data.o \
audio_mix.o \
audio_mix_matrix.o \
options.o \
resample.o \
utils.o
TESTPROGS = avresample
This diff is collapsed.
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#ifndef AVRESAMPLE_AUDIO_CONVERT_H
#define AVRESAMPLE_AUDIO_CONVERT_H
#include "libavutil/samplefmt.h"
#include "avresample.h"
#include "audio_data.h"
typedef struct AudioConvert AudioConvert;
/**
* Set conversion function if the parameters match.
*
* This compares the parameters of the conversion function to the parameters
* in the AudioConvert context. If the parameters do not match, no changes are
* made to the active functions. If the parameters do match and the alignment
* is not constrained, the function is set as the generic conversion function.
* If the parameters match and the alignment is constrained, the function is
* set as the optimized conversion function.
*
* @param ac AudioConvert context
* @param out_fmt output sample format
* @param in_fmt input sample format
* @param channels number of channels, or 0 for any number of channels
* @param ptr_align buffer pointer alignment, in bytes
* @param sample_align buffer size alignment, in samples
* @param descr function type description (e.g. "C" or "SSE")
* @param conv conversion function pointer
*/
void ff_audio_convert_set_func(AudioConvert *ac, enum AVSampleFormat out_fmt,
enum AVSampleFormat in_fmt, int channels,
int ptr_align, int samples_align,
const char *descr, void *conv);
/**
* Allocate and initialize AudioConvert context for sample format conversion.
*
* @param avr AVAudioResampleContext
* @param out_fmt output sample format
* @param in_fmt input sample format
* @param channels number of channels
* @return newly-allocated AudioConvert context
*/
AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
enum AVSampleFormat out_fmt,
enum AVSampleFormat in_fmt,
int channels);
/**
* Convert audio data from one sample format to another.
*
* For each call, the alignment of the input and output AudioData buffers are
* examined to determine whether to use the generic or optimized conversion
* function (when available).
*
* @param ac AudioConvert context
* @param out output audio data
* @param in input audio data
* @param len number of samples to convert
* @return 0 on success, negative AVERROR code on failure
*/
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in, int len);
/* arch-specific initialization functions */
void ff_audio_convert_init_x86(AudioConvert *ac);
#endif /* AVRESAMPLE_AUDIO_CONVERT_H */
This diff is collapsed.
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#ifndef AVRESAMPLE_AUDIO_DATA_H
#define AVRESAMPLE_AUDIO_DATA_H
#include <stdint.h>
#include "libavutil/audio_fifo.h"
#include "libavutil/log.h"
#include "libavutil/samplefmt.h"
#include "avresample.h"
/**
* Audio buffer used for intermediate storage between conversion phases.
*/
typedef struct AudioData {
const AVClass *class; /**< AVClass for logging */
uint8_t *data[AVRESAMPLE_MAX_CHANNELS]; /**< data plane pointers */
uint8_t *buffer; /**< data buffer */
unsigned int buffer_size; /**< allocated buffer size */
int allocated_samples; /**< number of samples the buffer can hold */
int nb_samples; /**< current number of samples */
enum AVSampleFormat sample_fmt; /**< sample format */
int channels; /**< channel count */
int allocated_channels; /**< allocated channel count */
int is_planar; /**< sample format is planar */
int planes; /**< number of data planes */
int sample_size; /**< bytes per sample */
int stride; /**< sample byte offset within a plane */
int read_only; /**< data is read-only */
int allow_realloc; /**< realloc is allowed */
int ptr_align; /**< minimum data pointer alignment */
int samples_align; /**< allocated samples alignment */
const char *name; /**< name for debug logging */
} AudioData;
int ff_audio_data_set_channels(AudioData *a, int channels);
/**
* Initialize AudioData using a given source.
*
* This does not allocate an internal buffer. It only sets the data pointers
* and audio parameters.
*
* @param a AudioData struct
* @param src source data pointers
* @param plane_size plane size, in bytes.
* This can be 0 if unknown, but that will lead to
* optimized functions not being used in many cases,
* which could slow down some conversions.
* @param channels channel count
* @param nb_samples number of samples in the source data
* @param sample_fmt sample format
* @param read_only indicates if buffer is read only or read/write
* @param name name for debug logging (can be NULL)
* @return 0 on success, negative AVERROR value on error
*/
int ff_audio_data_init(AudioData *a, void **src, int plane_size, int channels,
int nb_samples, enum AVSampleFormat sample_fmt,
int read_only, const char *name);
/**
* Allocate AudioData.
*
* This allocates an internal buffer and sets audio parameters.
*
* @param channels channel count
* @param nb_samples number of samples to allocate space for
* @param sample_fmt sample format
* @param name name for debug logging (can be NULL)
* @return newly allocated AudioData struct, or NULL on error
*/
AudioData *ff_audio_data_alloc(int channels, int nb_samples,
enum AVSampleFormat sample_fmt,
const char *name);
/**
* Reallocate AudioData.
*
* The AudioData must have been previously allocated with ff_audio_data_alloc().
*
* @param a AudioData struct
* @param nb_samples number of samples to allocate space for
* @return 0 on success, negative AVERROR value on error
*/
int ff_audio_data_realloc(AudioData *a, int nb_samples);
/**
* Free AudioData.
*
* The AudioData must have been previously allocated with ff_audio_data_alloc().
*
* @param a AudioData struct
*/
void ff_audio_data_free(AudioData **a);
/**
* Copy data from one AudioData to another.
*
* @param out output AudioData
* @param in input AudioData
* @return 0 on success, negative AVERROR value on error
*/
int ff_audio_data_copy(AudioData *out, AudioData *in);
/**
* Append data from one AudioData to the end of another.
*
* @param dst destination AudioData
* @param dst_offset offset, in samples, to start writing, relative to the
* start of dst
* @param src source AudioData
* @param src_offset offset, in samples, to start copying, relative to the
* start of the src
* @param nb_samples number of samples to copy
* @return 0 on success, negative AVERROR value on error
*/
int ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src,
int src_offset, int nb_samples);
/**
* Drain samples from the start of the AudioData.
*
* Remaining samples are shifted to the start of the AudioData.
*
* @param a AudioData struct
* @param nb_samples number of samples to drain
*/
void ff_audio_data_drain(AudioData *a, int nb_samples);
/**
* Add samples in AudioData to an AVAudioFifo.
*
* @param af Audio FIFO Buffer
* @param a AudioData struct
* @param offset number of samples to skip from the start of the data
* @param nb_samples number of samples to add to the FIFO
* @return number of samples actually added to the FIFO, or
* negative AVERROR code on error
*/
int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset,
int nb_samples);
/**
* Read samples from an AVAudioFifo to AudioData.
*
* @param af Audio FIFO Buffer
* @param a AudioData struct
* @param nb_samples number of samples to read from the FIFO
* @return number of samples actually read from the FIFO, or
* negative AVERROR code on error
*/
int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples);
#endif /* AVRESAMPLE_AUDIO_DATA_H */
This diff is collapsed.
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#ifndef AVRESAMPLE_AUDIO_MIX_H
#define AVRESAMPLE_AUDIO_MIX_H
#include <stdint.h>
#include "libavutil/samplefmt.h"
#include "avresample.h"
#include "audio_data.h"
typedef void (mix_func)(uint8_t **src, void **matrix, int len, int out_ch,
int in_ch);
typedef struct AudioMix {
AVAudioResampleContext *avr;
enum AVSampleFormat fmt;
enum AVMixCoeffType coeff_type;
uint64_t in_layout;
uint64_t out_layout;
int in_channels;
int out_channels;
int ptr_align;
int samples_align;
int has_optimized_func;
const char *func_descr;
const char *func_descr_generic;
mix_func *mix;
mix_func *mix_generic;
int16_t *matrix_q6[AVRESAMPLE_MAX_CHANNELS];
int32_t *matrix_q15[AVRESAMPLE_MAX_CHANNELS];
float *matrix_flt[AVRESAMPLE_MAX_CHANNELS];
void **matrix;
} AudioMix;
/**
* Set mixing function if the parameters match.
*
* This compares the parameters of the mixing function to the parameters in the
* AudioMix context. If the parameters do not match, no changes are made to the
* active functions. If the parameters do match and the alignment is not
* constrained, the function is set as the generic mixing function. If the
* parameters match and the alignment is constrained, the function is set as
* the optimized mixing function.
*
* @param am AudioMix context
* @param fmt input/output sample format
* @param coeff_type mixing coefficient type
* @param in_channels number of input channels, or 0 for any number of channels
* @param out_channels number of output channels, or 0 for any number of channels
* @param ptr_align buffer pointer alignment, in bytes
* @param sample_align buffer size alignment, in samples
* @param descr function type description (e.g. "C" or "SSE")
* @param mix_func mixing function pointer
*/
void ff_audio_mix_set_func(AudioMix *am, enum AVSampleFormat fmt,
enum AVMixCoeffType coeff_type, int in_channels,
int out_channels, int ptr_align, int samples_align,
const char *descr, void *mix_func);
/**
* Initialize the AudioMix context in the AVAudioResampleContext.
*
* The parameters in the AVAudioResampleContext are used to initialize the
* AudioMix context and set the mixing matrix.
*
* @param avr AVAudioResampleContext
* @return 0 on success, negative AVERROR code on failure
*/
int ff_audio_mix_init(AVAudioResampleContext *avr);
/**
* Close an AudioMix context.
*
* This clears and frees the mixing matrix arrays.
*/
void ff_audio_mix_close(AudioMix *am);
/**
* Apply channel mixing to audio data using the current mixing matrix.
*/
int ff_audio_mix(AudioMix *am, AudioData *src);
/* arch-specific initialization functions */
void ff_audio_mix_init_x86(AudioMix *am);
#endif /* AVRESAMPLE_AUDIO_MIX_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#ifndef AVRESAMPLE_INTERNAL_H
#define AVRESAMPLE_INTERNAL_H
#include "libavutil/audio_fifo.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "avresample.h"
#include "audio_convert.h"
#include "audio_data.h"
#include "audio_mix.h"
#include "resample.h"
struct AVAudioResampleContext {
const AVClass *av_class; /**< AVClass for logging and AVOptions */
uint64_t in_channel_layout; /**< input channel layout */
enum AVSampleFormat in_sample_fmt; /**< input sample format */
int in_sample_rate; /**< input sample rate */
uint64_t out_channel_layout; /**< output channel layout */
enum AVSampleFormat out_sample_fmt; /**< output sample format */
int out_sample_rate; /**< output sample rate */
enum AVSampleFormat internal_sample_fmt; /**< internal sample format */
enum AVMixCoeffType mix_coeff_type; /**< mixing coefficient type */
double center_mix_level; /**< center mix level */
double surround_mix_level; /**< surround mix level */
double lfe_mix_level; /**< lfe mix level */
int force_resampling; /**< force resampling */
int filter_size; /**< length of each FIR filter in the resampling filterbank relative to the cutoff frequency */
int phase_shift; /**< log2 of the number of entries in the resampling polyphase filterbank */
int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */
double cutoff; /**< resampling cutoff frequency. 1.0 corresponds to half the output sample rate */
int in_channels; /**< number of input channels */
int out_channels; /**< number of output channels */
int resample_channels; /**< number of channels used for resampling */
int downmix_needed; /**< downmixing is needed */
int upmix_needed; /**< upmixing is needed */
int mixing_needed; /**< either upmixing or downmixing is needed */
int resample_needed; /**< resampling is needed */
int in_convert_needed; /**< input sample format conversion is needed */
int out_convert_needed; /**< output sample format conversion is needed */
AudioData *in_buffer; /**< buffer for converted input */
AudioData *resample_out_buffer; /**< buffer for output from resampler */
AudioData *out_buffer; /**< buffer for converted output */
AVAudioFifo *out_fifo; /**< FIFO for output samples */
AudioConvert *ac_in; /**< input sample format conversion context */
AudioConvert *ac_out; /**< output sample format conversion context */
ResampleContext *resample; /**< resampling context */
AudioMix *am; /**< channel mixing context */
};
#endif /* AVRESAMPLE_INTERNAL_H */
LIBAVRESAMPLE_$MAJOR {
global: av*;
local: *;
};
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "avresample.h"
#include "internal.h"
#include "audio_mix.h"
/**
* @file
* Options definition for AVAudioResampleContext.
*/
#define OFFSET(x) offsetof(AVAudioResampleContext, x)
#define PARAM AV_OPT_FLAG_AUDIO_PARAM
static const AVOption options[] = {
{ "in_channel_layout", "Input Channel Layout", OFFSET(in_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM },
{ "in_sample_fmt", "Input Sample Format", OFFSET(in_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_NB-1, PARAM },
{ "in_sample_rate", "Input Sample Rate", OFFSET(in_sample_rate), AV_OPT_TYPE_INT, { 48000 }, 1, INT_MAX, PARAM },
{ "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM },
{ "out_sample_fmt", "Output Sample Format", OFFSET(out_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_NB-1, PARAM },
{ "out_sample_rate", "Output Sample Rate", OFFSET(out_sample_rate), AV_OPT_TYPE_INT, { 48000 }, 1, INT_MAX, PARAM },
{ "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_FLTP }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, PARAM },
{ "mix_coeff_type", "Mixing Coefficient Type", OFFSET(mix_coeff_type), AV_OPT_TYPE_INT, { AV_MIX_COEFF_TYPE_FLT }, AV_MIX_COEFF_TYPE_Q6, AV_MIX_COEFF_TYPE_NB-1, PARAM, "mix_coeff_type" },
{ "q6", "16-bit 10.6 Fixed-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_Q6 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
{ "q15", "32-bit 17.15 Fixed-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_Q15 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
{ "flt", "Floating-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_FLT }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
{ "center_mix_level", "Center Mix Level", OFFSET(center_mix_level), AV_OPT_TYPE_DOUBLE, { M_SQRT1_2 }, -32.0, 32.0, PARAM },
{ "surround_mix_level", "Surround Mix Level", OFFSET(surround_mix_level), AV_OPT_TYPE_DOUBLE, { M_SQRT1_2 }, -32.0, 32.0, PARAM },
{ "lfe_mix_level", "LFE Mix Level", OFFSET(lfe_mix_level), AV_OPT_TYPE_DOUBLE, { 0.0 }, -32.0, 32.0, PARAM },
{ "force_resampling", "Force Resampling", OFFSET(force_resampling), AV_OPT_TYPE_INT, { 0 }, 0, 1, PARAM },
{ "filter_size", "Resampling Filter Size", OFFSET(filter_size), AV_OPT_TYPE_INT, { 16 }, 0, 32, /* ??? */ PARAM },
{ "phase_shift", "Resampling Phase Shift", OFFSET(phase_shift), AV_OPT_TYPE_INT, { 10 }, 0, 30, /* ??? */ PARAM },
{ "linear_interp", "Use Linear Interpolation", OFFSET(linear_interp), AV_OPT_TYPE_INT, { 0 }, 0, 1, PARAM },
{ "cutoff", "Cutoff Frequency Ratio", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, { 0.8 }, 0.0, 1.0, PARAM },
{ NULL },
};
static const AVClass av_resample_context_class = {
.class_name = "AVAudioResampleContext",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
AVAudioResampleContext *avresample_alloc_context(void)
{
AVAudioResampleContext *avr;
avr = av_mallocz(sizeof(*avr));
if (!avr)
return NULL;
avr->av_class = &av_resample_context_class;
av_opt_set_defaults(avr);
avr->am = av_mallocz(sizeof(*avr->am));
if (!avr->am) {
av_free(avr);
return NULL;
}
avr->am->avr = avr;
return avr;
}
const AVClass *avresample_get_class(void)
{
return &av_resample_context_class;
}
This diff is collapsed.
/*
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
* 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
*/
#ifndef AVRESAMPLE_RESAMPLE_H
#define AVRESAMPLE_RESAMPLE_H
#include "avresample.h"
#include "audio_data.h"
typedef struct ResampleContext ResampleContext;
/**
* Allocate and initialize a ResampleContext.
*
* The parameters in the AVAudioResampleContext are used to initialize the
* ResampleContext.
*
* @param avr AVAudioResampleContext
* @return newly-allocated ResampleContext
*/
ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr);
/**
* Free a ResampleContext.
*
* @param c ResampleContext
*/
void ff_audio_resample_free(ResampleContext **c);
/**
* Resample audio data.
*
* Changes the sample rate.
*
* @par
* All samples in the source data may not be consumed depending on the
* resampling parameters and the size of the output buffer. The unconsumed
* samples are automatically added to the start of the source in the next call.
* If the destination data can be reallocated, that may be done in this function
* in order to fit all available output. If it cannot be reallocated, fewer
* input samples will be consumed in order to have the output fit in the
* destination data buffers.
*
* @param c ResampleContext
* @param dst destination audio data
* @param src source audio data
* @param consumed number of samples consumed from the source
* @return number of samples written to the destination
*/
int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src,
int *consumed);
#endif /* AVRESAMPLE_RESAMPLE_H */
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
*/
#ifndef AVRESAMPLE_VERSION_H
#define AVRESAMPLE_VERSION_H
#define LIBAVRESAMPLE_VERSION_MAJOR 0
#define LIBAVRESAMPLE_VERSION_MINOR 0
#define LIBAVRESAMPLE_VERSION_MICRO 0
#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \
LIBAVRESAMPLE_VERSION_MINOR, \
LIBAVRESAMPLE_VERSION_MICRO)
#define LIBAVRESAMPLE_VERSION AV_VERSION(LIBAVRESAMPLE_VERSION_MAJOR, \
LIBAVRESAMPLE_VERSION_MINOR, \
LIBAVRESAMPLE_VERSION_MICRO)
#define LIBAVRESAMPLE_BUILD LIBAVRESAMPLE_VERSION_INT
#define LIBAVRESAMPLE_IDENT "Lavr" AV_STRINGIFY(LIBAVRESAMPLE_VERSION)
/**
* These FF_API_* defines are not part of public API.
* They may change, break or disappear at any time.
*/
#endif /* AVRESAMPLE_VERSION_H */
OBJS += x86/audio_convert_init.o \
x86/audio_mix_init.o
YASM-OBJS += x86/audio_convert.o \
x86/audio_mix.o
;******************************************************************************
;* x86 optimized Format Conversion Utils
;* Copyright (c) 2008 Loren Merritt
;*
;* 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
;******************************************************************************
%include "x86inc.asm"
%include "x86util.asm"
SECTION_TEXT
;-----------------------------------------------------------------------------
; void ff_conv_fltp_to_flt_6ch(float *dst, float *const *src, int len,
; int channels);
;-----------------------------------------------------------------------------
%macro CONV_FLTP_TO_FLT_6CH 0
cglobal conv_fltp_to_flt_6ch, 2,8,7, dst, src, src1, src2, src3, src4, src5, len
%if ARCH_X86_64
mov lend, r2d
%else
%define lend dword r2m
%endif
mov src1q, [srcq+1*gprsize]
mov src2q, [srcq+2*gprsize]
mov src3q, [srcq+3*gprsize]
mov src4q, [srcq+4*gprsize]
mov src5q, [srcq+5*gprsize]
mov srcq, [srcq]
sub src1q, srcq
sub src2q, srcq
sub src3q, srcq
sub src4q, srcq
sub src5q, srcq
.loop:
mova m0, [srcq ]
mova m1, [srcq+src1q]
mova m2, [srcq+src2q]
mova m3, [srcq+src3q]
mova m4, [srcq+src4q]
mova m5, [srcq+src5q]
%if cpuflag(sse)
SBUTTERFLYPS 0, 1, 6
SBUTTERFLYPS 2, 3, 6
SBUTTERFLYPS 4, 5, 6
movaps m6, m4
shufps m4, m0, q3210
movlhps m0, m2
movhlps m6, m2
movaps [dstq ], m0
movaps [dstq+16], m4
movaps [dstq+32], m6
movaps m6, m5
shufps m5, m1, q3210
movlhps m1, m3
movhlps m6, m3
movaps [dstq+48], m1
movaps [dstq+64], m5
movaps [dstq+80], m6
%else ; mmx
SBUTTERFLY dq, 0, 1, 6
SBUTTERFLY dq, 2, 3, 6
SBUTTERFLY dq, 4, 5, 6
movq [dstq ], m0
movq [dstq+ 8], m2
movq [dstq+16], m4
movq [dstq+24], m1
movq [dstq+32], m3
movq [dstq+40], m5
%endif
add srcq, mmsize
add dstq, mmsize*6
sub lend, mmsize/4
jg .loop
%if mmsize == 8
emms
RET
%else
REP_RET
%endif
%endmacro
INIT_MMX mmx
CONV_FLTP_TO_FLT_6CH
INIT_XMM sse
CONV_FLTP_TO_FLT_6CH
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#include "config.h"
#include "libavutil/cpu.h"
#include "libavresample/audio_convert.h"
extern void ff_conv_fltp_to_flt_6ch_mmx(float *dst, float *const *src, int len);
extern void ff_conv_fltp_to_flt_6ch_sse(float *dst, float *const *src, int len);
av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
{
#if HAVE_YASM
int mm_flags = av_get_cpu_flags();
if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) {
ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
}
if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
6, 16, 4, "SSE", ff_conv_fltp_to_flt_6ch_sse);
}
#endif
}
;******************************************************************************
;* x86 optimized channel mixing
;* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
;*
;* 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
;******************************************************************************
%include "x86inc.asm"
%include "x86util.asm"
SECTION_TEXT
;-----------------------------------------------------------------------------
; void ff_mix_2_to_1_fltp_flt(float **src, float **matrix, int len,
; int out_ch, int in_ch);
;-----------------------------------------------------------------------------
%macro MIX_2_TO_1_FLTP_FLT 0
cglobal mix_2_to_1_fltp_flt, 3,4,6, src, matrix, len, src1
mov src1q, [srcq+gprsize]
mov srcq, [srcq ]
sub src1q, srcq
mov matrixq, [matrixq ]
VBROADCASTSS m4, [matrixq ]
VBROADCASTSS m5, [matrixq+4]
ALIGN 16
.loop:
mulps m0, m4, [srcq ]
mulps m1, m5, [srcq+src1q ]
mulps m2, m4, [srcq+ mmsize]
mulps m3, m5, [srcq+src1q+mmsize]
addps m0, m0, m1
addps m2, m2, m3
mova [srcq ], m0
mova [srcq+mmsize], m2
add srcq, mmsize*2
sub lend, mmsize*2/4
jg .loop
%if mmsize == 32
vzeroupper
RET
%else
REP_RET
%endif
%endmacro
INIT_XMM sse
MIX_2_TO_1_FLTP_FLT
INIT_YMM avx
MIX_2_TO_1_FLTP_FLT
/*
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
*
* 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
*/
#include "config.h"
#include "libavutil/cpu.h"
#include "libavresample/audio_mix.h"
extern void ff_mix_2_to_1_fltp_flt_sse(float **src, float **matrix, int len,
int out_ch, int in_ch);
extern void ff_mix_2_to_1_fltp_flt_avx(float **src, float **matrix, int len,
int out_ch, int in_ch);
av_cold void ff_audio_mix_init_x86(AudioMix *am)
{
#if HAVE_YASM
int mm_flags = av_get_cpu_flags();
if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
2, 1, 16, 8, "SSE", ff_mix_2_to_1_fltp_flt_sse);
}
if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
2, 1, 32, 16, "AVX", ff_mix_2_to_1_fltp_flt_avx);
}
#endif
}
......@@ -585,3 +585,12 @@
pminsd %1, %3
pmaxsd %1, %2
%endmacro
%macro VBROADCASTSS 2 ; dst xmm/ymm, src m32
%if cpuflag(avx)
vbroadcastss %1, %2
%else ; sse
movss %1, %2
shufps %1, %1, 0
%endif
%endmacro
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