audio_convert.h 4 KB
Newer Older
Justin Ruggles's avatar
Justin Ruggles committed
1 2 3
/*
 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
 *
4
 * This file is part of FFmpeg.
Justin Ruggles's avatar
Justin Ruggles committed
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
Justin Ruggles's avatar
Justin Ruggles committed
7 8 9 10
 * 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.
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
Justin Ruggles's avatar
Justin Ruggles committed
12 13 14 15 16
 * 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
17
 * License along with FFmpeg; if not, write to the Free Software
Justin Ruggles's avatar
Justin Ruggles committed
18 19 20 21 22 23 24 25
 * 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"
26
#include "internal.h"
Justin Ruggles's avatar
Justin Ruggles committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "audio_data.h"

/**
 * 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
44
 * @param samples_align  buffer size alignment, in samples
Justin Ruggles's avatar
Justin Ruggles committed
45 46 47 48 49 50 51 52 53 54 55
 * @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.
 *
56 57 58 59 60
 * @param avr         AVAudioResampleContext
 * @param out_fmt     output sample format
 * @param in_fmt      input sample format
 * @param channels    number of channels
 * @param sample_rate sample rate (used for dithering)
61
 * @param apply_map   apply channel map during conversion
62
 * @return            newly-allocated AudioConvert context
Justin Ruggles's avatar
Justin Ruggles committed
63 64 65 66
 */
AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
                                     enum AVSampleFormat out_fmt,
                                     enum AVSampleFormat in_fmt,
67 68
                                     int channels, int sample_rate,
                                     int apply_map);
69 70 71 72 73 74 75 76 77

/**
 * Free AudioConvert.
 *
 * The AudioConvert must have been previously allocated with ff_audio_convert_alloc().
 *
 * @param ac  AudioConvert struct
 */
void ff_audio_convert_free(AudioConvert **ac);
Justin Ruggles's avatar
Justin Ruggles committed
78 79 80 81 82 83 84 85

/**
 * 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).
 *
86 87 88 89
 * The number of samples to convert is determined by in->nb_samples. The output
 * buffer must be large enough to handle this many samples. out->nb_samples is
 * set by this function before a successful return.
 *
Justin Ruggles's avatar
Justin Ruggles committed
90 91 92 93 94
 * @param ac     AudioConvert context
 * @param out    output audio data
 * @param in     input audio data
 * @return       0 on success, negative AVERROR code on failure
 */
95
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in);
Justin Ruggles's avatar
Justin Ruggles committed
96 97 98

/* arch-specific initialization functions */

99
void ff_audio_convert_init_arm(AudioConvert *ac);
Justin Ruggles's avatar
Justin Ruggles committed
100 101 102
void ff_audio_convert_init_x86(AudioConvert *ac);

#endif /* AVRESAMPLE_AUDIO_CONVERT_H */