#include "avcodec.h"
#include "bitstream.h"
#include "crc.h"
#include "dsputil.h"
#include "golomb.h"
#include "lls.h"
Go to the source code of this file.
Data Structures | |
struct | CompressionOptions |
struct | RiceContext |
struct | FlacSubframe |
struct | FlacFrame |
struct | FlacEncodeContext |
Defines | |
#define | FLAC_MAX_CH 8 |
FLAC audio encoder Copyright (c) 2006 Justin Ruggles <jruggle@earthlink.net>. | |
#define | FLAC_MIN_BLOCKSIZE 16 |
#define | FLAC_MAX_BLOCKSIZE 65535 |
#define | FLAC_SUBFRAME_CONSTANT 0 |
#define | FLAC_SUBFRAME_VERBATIM 1 |
#define | FLAC_SUBFRAME_FIXED 8 |
#define | FLAC_SUBFRAME_LPC 32 |
#define | FLAC_CHMODE_NOT_STEREO 0 |
#define | FLAC_CHMODE_LEFT_RIGHT 1 |
#define | FLAC_CHMODE_LEFT_SIDE 8 |
#define | FLAC_CHMODE_RIGHT_SIDE 9 |
#define | FLAC_CHMODE_MID_SIDE 10 |
#define | ORDER_METHOD_EST 0 |
#define | ORDER_METHOD_2LEVEL 1 |
#define | ORDER_METHOD_4LEVEL 2 |
#define | ORDER_METHOD_8LEVEL 3 |
#define | ORDER_METHOD_SEARCH 4 |
#define | ORDER_METHOD_LOG 5 |
#define | FLAC_STREAMINFO_SIZE 34 |
#define | MIN_LPC_ORDER 1 |
#define | MAX_LPC_ORDER 32 |
#define | MAX_FIXED_ORDER 4 |
#define | MAX_PARTITION_ORDER 8 |
#define | MAX_PARTITIONS (1 << MAX_PARTITION_ORDER) |
#define | MAX_LPC_PRECISION 15 |
#define | MAX_LPC_SHIFT 15 |
#define | MAX_RICE_PARAM 14 |
#define | rice_encode_count(sum, n, k) (((n)*((k)+1))+((sum-(n>>1))>>(k))) |
#define | LPC1(x) |
Functions | |
static void | write_streaminfo (FlacEncodeContext *s, uint8_t *header) |
Writes streaminfo metadata block to byte array. | |
static int | select_blocksize (int samplerate, int block_time_ms) |
Sets blocksize based on samplerate Chooses the closest predefined blocksize >= BLOCK_TIME_MS milliseconds. | |
static int | flac_encode_init (AVCodecContext *avctx) |
static void | init_frame (FlacEncodeContext *s) |
static void | copy_samples (FlacEncodeContext *s, int16_t *samples) |
Copy channel-interleaved input samples into separate subframes. | |
static int | find_optimal_param (uint32_t sum, int n) |
Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0. | |
static uint32_t | calc_optimal_rice_params (RiceContext *rc, int porder, uint32_t *sums, int n, int pred_order) |
static void | calc_sums (int pmin, int pmax, uint32_t *data, int n, int pred_order, uint32_t sums[][MAX_PARTITIONS]) |
static uint32_t | calc_rice_params (RiceContext *rc, int pmin, int pmax, int32_t *data, int n, int pred_order) |
static int | get_max_p_order (int max_porder, int n, int order) |
static uint32_t | calc_rice_params_fixed (RiceContext *rc, int pmin, int pmax, int32_t *data, int n, int pred_order, int bps) |
static uint32_t | calc_rice_params_lpc (RiceContext *rc, int pmin, int pmax, int32_t *data, int n, int pred_order, int bps, int precision) |
static void | apply_welch_window (const int32_t *data, int len, double *w_data) |
Apply Welch window function to audio block. | |
void | ff_flac_compute_autocorr (const int32_t *data, int len, int lag, double *autoc) |
Calculates autocorrelation data from audio samples A Welch window function is applied before calculation. | |
static void | compute_lpc_coefs (const double *autoc, int max_order, double lpc[][MAX_LPC_ORDER], double *ref) |
Levinson-Durbin recursion. | |
static void | quantize_lpc_coefs (double *lpc_in, int order, int precision, int32_t *lpc_out, int *shift) |
Quantize LPC coefficients. | |
static int | estimate_best_order (double *ref, int max_order) |
static int | lpc_calc_coefs (FlacEncodeContext *s, const int32_t *samples, int blocksize, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc, int omethod) |
Calculate LPC coefficients for multiple orders. | |
static void | encode_residual_verbatim (int32_t *res, int32_t *smp, int n) |
static void | encode_residual_fixed (int32_t *res, const int32_t *smp, int n, int order) |
static av_always_inline void | encode_residual_lpc_unrolled (int32_t *res, const int32_t *smp, int n, int order, const int32_t *coefs, int shift, int big) |
static void | encode_residual_lpc (int32_t *res, const int32_t *smp, int n, int order, const int32_t *coefs, int shift) |
static int | encode_residual (FlacEncodeContext *ctx, int ch) |
static int | encode_residual_v (FlacEncodeContext *ctx, int ch) |
static int | estimate_stereo_mode (int32_t *left_ch, int32_t *right_ch, int n) |
static void | channel_decorrelation (FlacEncodeContext *ctx) |
Perform stereo channel decorrelation. | |
static void | put_sbits (PutBitContext *pb, int bits, int32_t val) |
static void | write_utf8 (PutBitContext *pb, uint32_t val) |
static void | output_frame_header (FlacEncodeContext *s) |
static void | output_subframe_constant (FlacEncodeContext *s, int ch) |
static void | output_subframe_verbatim (FlacEncodeContext *s, int ch) |
static void | output_residual (FlacEncodeContext *ctx, int ch) |
static void | output_subframe_fixed (FlacEncodeContext *ctx, int ch) |
static void | output_subframe_lpc (FlacEncodeContext *ctx, int ch) |
static void | output_subframes (FlacEncodeContext *s) |
static void | output_frame_footer (FlacEncodeContext *s) |
static int | flac_encode_frame (AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data) |
static int | flac_encode_close (AVCodecContext *avctx) |
Variables | |
static const int | flac_samplerates [16] |
static const int | flac_blocksizes [16] |
AVCodec | flac_encoder |
#define FLAC_CHMODE_LEFT_RIGHT 1 |
Definition at line 39 of file flacenc.c.
Referenced by channel_decorrelation(), and estimate_stereo_mode().
#define FLAC_CHMODE_LEFT_SIDE 8 |
Definition at line 40 of file flacenc.c.
Referenced by channel_decorrelation(), and estimate_stereo_mode().
#define FLAC_CHMODE_MID_SIDE 10 |
Definition at line 42 of file flacenc.c.
Referenced by channel_decorrelation(), and estimate_stereo_mode().
#define FLAC_CHMODE_NOT_STEREO 0 |
Definition at line 38 of file flacenc.c.
Referenced by channel_decorrelation(), and output_frame_header().
#define FLAC_CHMODE_RIGHT_SIDE 9 |
#define FLAC_MAX_BLOCKSIZE 65535 |
#define FLAC_MAX_CH 8 |
FLAC audio encoder Copyright (c) 2006 Justin Ruggles <jruggle@earthlink.net>.
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
Definition at line 29 of file flacenc.c.
Referenced by flac_encode_init().
#define FLAC_MIN_BLOCKSIZE 16 |
#define FLAC_SUBFRAME_CONSTANT 0 |
Definition at line 33 of file flacenc.c.
Referenced by encode_residual(), encode_residual_v(), and output_subframes().
#define FLAC_SUBFRAME_FIXED 8 |
#define FLAC_SUBFRAME_LPC 32 |
#define FLAC_SUBFRAME_VERBATIM 1 |
Definition at line 34 of file flacenc.c.
Referenced by encode_residual(), encode_residual_v(), and output_subframes().
#define LPC1 | ( | x | ) |
Value:
{\ int c = coefs[(x)-1];\ p0 += c*s;\ s = smp[i-(x)+1];\ p1 += c*s;\ }
Definition at line 880 of file flacenc.c.
Referenced by encode_residual_lpc_unrolled().
#define MAX_FIXED_ORDER 4 |
#define MAX_LPC_ORDER 32 |
#define MAX_LPC_PRECISION 15 |
#define MAX_LPC_SHIFT 15 |
#define MAX_PARTITION_ORDER 8 |
#define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER) |
#define MAX_RICE_PARAM 14 |
#define MIN_LPC_ORDER 1 |
#define ORDER_METHOD_2LEVEL 1 |
#define ORDER_METHOD_4LEVEL 2 |
#define ORDER_METHOD_8LEVEL 3 |
#define ORDER_METHOD_EST 0 |
#define ORDER_METHOD_LOG 5 |
#define ORDER_METHOD_SEARCH 4 |
Definition at line 452 of file flacenc.c.
Referenced by calc_optimal_rice_params(), and estimate_stereo_mode().
static void apply_welch_window | ( | const int32_t * | data, | |
int | len, | |||
double * | w_data | |||
) | [static] |
Apply Welch window function to audio block.
Definition at line 590 of file flacenc.c.
Referenced by ff_flac_compute_autocorr().
static uint32_t calc_optimal_rice_params | ( | RiceContext * | rc, | |
int | porder, | |||
uint32_t * | sums, | |||
int | n, | |||
int | pred_order | |||
) | [static] |
static uint32_t calc_rice_params | ( | RiceContext * | rc, | |
int | pmin, | |||
int | pmax, | |||
int32_t * | data, | |||
int | n, | |||
int | pred_order | |||
) | [static] |
Definition at line 520 of file flacenc.c.
Referenced by calc_rice_params_fixed(), and calc_rice_params_lpc().
static uint32_t calc_rice_params_fixed | ( | RiceContext * | rc, | |
int | pmin, | |||
int | pmax, | |||
int32_t * | data, | |||
int | n, | |||
int | pred_order, | |||
int | bps | |||
) | [static] |
static uint32_t calc_rice_params_lpc | ( | RiceContext * | rc, | |
int | pmin, | |||
int | pmax, | |||
int32_t * | data, | |||
int | n, | |||
int | pred_order, | |||
int | bps, | |||
int | precision | |||
) | [static] |
static void calc_sums | ( | int | pmin, | |
int | pmax, | |||
uint32_t * | data, | |||
int | n, | |||
int | pred_order, | |||
uint32_t | sums[][MAX_PARTITIONS] | |||
) | [static] |
static void channel_decorrelation | ( | FlacEncodeContext * | ctx | ) | [static] |
Perform stereo channel decorrelation.
Definition at line 1201 of file flacenc.c.
Referenced by flac_encode_frame().
static void compute_lpc_coefs | ( | const double * | autoc, | |
int | max_order, | |||
double | lpc[][MAX_LPC_ORDER], | |||
double * | ref | |||
) | [static] |
Levinson-Durbin recursion.
Produces LPC coefficients from autocorrelation data.
Definition at line 647 of file flacenc.c.
Referenced by lpc_calc_coefs().
static void copy_samples | ( | FlacEncodeContext * | s, | |
int16_t * | samples | |||
) | [static] |
Copy channel-interleaved input samples into separate subframes.
Definition at line 438 of file flacenc.c.
Referenced by flac_encode_frame().
static int encode_residual | ( | FlacEncodeContext * | ctx, | |
int | ch | |||
) | [static] |
static void encode_residual_fixed | ( | int32_t * | res, | |
const int32_t * | smp, | |||
int | n, | |||
int | order | |||
) | [static] |
static void encode_residual_lpc | ( | int32_t * | res, | |
const int32_t * | smp, | |||
int | n, | |||
int | order, | |||
const int32_t * | coefs, | |||
int | shift | |||
) | [static] |
static av_always_inline void encode_residual_lpc_unrolled | ( | int32_t * | res, | |
const int32_t * | smp, | |||
int | n, | |||
int | order, | |||
const int32_t * | coefs, | |||
int | shift, | |||
int | big | |||
) | [static] |
static int encode_residual_v | ( | FlacEncodeContext * | ctx, | |
int | ch | |||
) | [static] |
static void encode_residual_verbatim | ( | int32_t * | res, | |
int32_t * | smp, | |||
int | n | |||
) | [static] |
static int estimate_best_order | ( | double * | ref, | |
int | max_order | |||
) | [static] |
static int estimate_stereo_mode | ( | int32_t * | left_ch, | |
int32_t * | right_ch, | |||
int | n | |||
) | [static] |
void ff_flac_compute_autocorr | ( | const int32_t * | data, | |
int | len, | |||
int | lag, | |||
double * | autoc | |||
) |
Calculates autocorrelation data from audio samples A Welch window function is applied before calculation.
Definition at line 610 of file flacenc.c.
Referenced by dsputil_init().
static int find_optimal_param | ( | uint32_t | sum, | |
int | n | |||
) | [static] |
Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0.
Definition at line 457 of file flacenc.c.
Referenced by calc_optimal_rice_params(), and estimate_stereo_mode().
static int flac_encode_close | ( | AVCodecContext * | avctx | ) | [static] |
static int flac_encode_frame | ( | AVCodecContext * | avctx, | |
uint8_t * | frame, | |||
int | buf_size, | |||
void * | data | |||
) | [static] |
static int flac_encode_init | ( | AVCodecContext * | avctx | ) | [static] |
static int get_max_p_order | ( | int | max_porder, | |
int | n, | |||
int | order | |||
) | [static] |
Definition at line 555 of file flacenc.c.
Referenced by calc_rice_params_fixed(), and calc_rice_params_lpc().
static void init_frame | ( | FlacEncodeContext * | s | ) | [static] |
Definition at line 404 of file flacenc.c.
Referenced by flac_encode_frame(), and vp3_decode_frame().
static int lpc_calc_coefs | ( | FlacEncodeContext * | s, | |
const int32_t * | samples, | |||
int | blocksize, | |||
int | max_order, | |||
int | precision, | |||
int32_t | coefs[][MAX_LPC_ORDER], | |||
int * | shift, | |||
int | use_lpc, | |||
int | omethod | |||
) | [static] |
Calculate LPC coefficients for multiple orders.
Definition at line 753 of file flacenc.c.
Referenced by encode_residual().
static void output_frame_footer | ( | FlacEncodeContext * | s | ) | [static] |
static void output_frame_header | ( | FlacEncodeContext * | s | ) | [static] |
static void output_residual | ( | FlacEncodeContext * | ctx, | |
int | ch | |||
) | [static] |
Definition at line 1317 of file flacenc.c.
Referenced by output_subframe_fixed(), and output_subframe_lpc().
static void output_subframe_constant | ( | FlacEncodeContext * | s, | |
int | ch | |||
) | [static] |
static void output_subframe_fixed | ( | FlacEncodeContext * | ctx, | |
int | ch | |||
) | [static] |
static void output_subframe_lpc | ( | FlacEncodeContext * | ctx, | |
int | ch | |||
) | [static] |
static void output_subframe_verbatim | ( | FlacEncodeContext * | s, | |
int | ch | |||
) | [static] |
static void output_subframes | ( | FlacEncodeContext * | s | ) | [static] |
static void put_sbits | ( | PutBitContext * | pb, | |
int | bits, | |||
int32_t | val | |||
) | [static] |
Definition at line 1244 of file flacenc.c.
Referenced by output_subframe_constant(), output_subframe_fixed(), output_subframe_lpc(), and output_subframe_verbatim().
static void quantize_lpc_coefs | ( | double * | lpc_in, | |
int | order, | |||
int | precision, | |||
int32_t * | lpc_out, | |||
int * | shift | |||
) | [static] |
Quantize LPC coefficients.
Definition at line 687 of file flacenc.c.
Referenced by lpc_calc_coefs().
static int select_blocksize | ( | int | samplerate, | |
int | block_time_ms | |||
) | [static] |
Sets blocksize based on samplerate Chooses the closest predefined blocksize >= BLOCK_TIME_MS milliseconds.
Definition at line 155 of file flacenc.c.
Referenced by flac_encode_init().
static void write_streaminfo | ( | FlacEncodeContext * | s, | |
uint8_t * | header | |||
) | [static] |
Writes streaminfo metadata block to byte array.
Definition at line 131 of file flacenc.c.
Referenced by flac_encode_init().
static void write_utf8 | ( | PutBitContext * | pb, | |
uint32_t | val | |||
) | [static] |
const int flac_blocksizes[16] [static] |
Initial value:
{ 0, 192, 576, 1152, 2304, 4608, 0, 0, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }
Definition at line 120 of file flacenc.c.
Referenced by init_frame(), and select_blocksize().
Initial value:
{ "flac", CODEC_TYPE_AUDIO, CODEC_ID_FLAC, sizeof(FlacEncodeContext), flac_encode_init, flac_encode_frame, flac_encode_close, NULL, .capabilities = CODEC_CAP_SMALL_LAST_FRAME, }
const int flac_samplerates[16] [static] |
Initial value:
{ 0, 0, 0, 0, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, 0, 0, 0, 0 }
Definition at line 114 of file flacenc.c.
Referenced by flac_encode_init().