28 #define DEFAULT_FRAME_SIZE 4096
29 #define DEFAULT_SAMPLE_SIZE 16
30 #define MAX_CHANNELS 8
31 #define ALAC_EXTRADATA_SIZE 36
32 #define ALAC_FRAME_HEADER_SIZE 55
33 #define ALAC_FRAME_FOOTER_SIZE 3
35 #define ALAC_ESCAPE_CODE 0x1FF
36 #define ALAC_MAX_LPC_ORDER 30
37 #define DEFAULT_MAX_PRED_ORDER 6
38 #define DEFAULT_MIN_PRED_ORDER 4
39 #define ALAC_MAX_LPC_PRECISION 9
40 #define ALAC_MAX_LPC_SHIFT 9
42 #define ALAC_CHMODE_LEFT_RIGHT 0
43 #define ALAC_CHMODE_LEFT_SIDE 1
44 #define ALAC_CHMODE_RIGHT_SIDE 2
45 #define ALAC_CHMODE_MID_SIDE 3
79 const int16_t *input_samples)
84 const int16_t *sptr = input_samples + ch;
93 int k,
int write_sample_size)
156 memcpy(s->
lpc[ch].
lpc_coeff, coefs[opt_order-1], opt_order*
sizeof(
int));
168 sum[0] = sum[1] = sum[2] = sum[3] = 0;
169 for (i = 2; i < n; i++) {
170 lt = left_ch[i] - 2*left_ch[i-1] + left_ch[i-2];
171 rt = right_ch[i] - 2*right_ch[i-1] + right_ch[i-2];
172 sum[2] +=
FFABS((lt + rt) >> 1);
173 sum[3] +=
FFABS(lt - rt);
179 score[0] = sum[0] + sum[1];
180 score[1] = sum[0] + sum[3];
181 score[2] = sum[1] + sum[3];
182 score[3] = sum[2] + sum[3];
186 for (i = 1; i < 4; i++) {
187 if (score[i] < score[best]) {
210 for (i = 0; i < n; i++) {
211 right[i] = left[i] - right[i];
218 for (i = 0; i < n; i++) {
220 right[i] = left[i] - right[i];
221 left[i] = tmp + (right[i] >> 31);
228 for (i = 0; i < n; i++) {
230 left[i] = (tmp + right[i]) >> 1;
231 right[i] = tmp - right[i];
260 residual[0] = samples[0];
262 residual[i] = samples[i] - samples[i-1];
265 for (i = lpc.
lpc_order + 1; i < s->avctx->frame_size; i++) {
266 int sum = 1 << (lpc.
lpc_quant - 1), res_val, j;
269 sum += (samples[lpc.
lpc_order-j] - samples[0]) *
277 res_val = residual[i];
281 int neg = (res_val < 0);
283 while(index >= 0 && (neg ? (res_val < 0):(res_val > 0))) {
285 int sign = (val ?
FFSIGN(val) : 0);
305 int sign_modifier = 0, i, k;
311 k = av_log2((history >> 9) + 3);
328 if (history < 128 && i < s->avctx->frame_size) {
329 unsigned int block_size = 0;
331 k = 7 - av_log2(history) + ((history + 16) >> 6);
333 while (*samples == 0 && i < s->avctx->frame_size) {
340 sign_modifier = (block_size <= 0xFFFF);
351 int prediction_type = 0;
379 if (prediction_type == 15) {
470 "invalid prediction orders: min=%d max=%d\n",
489 int buf_size,
void *
data)
493 int i, out_bytes, verbatim_flag = 0;
500 if (buf_size < 2 * s->max_coded_frame_size) {
#define DEFAULT_MIN_PRED_ORDER
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
#define FF_COMPRESSION_DEFAULT
AlacLPCContext lpc[MAX_CHANNELS]
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_sample_buffers(AlacEncodeContext *s, const int16_t *input_samples)
int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int max_shift, int zero_shift)
Calculate LPC coefficients for multiple orders.
AVFrame * coded_frame
the picture in the bitstream
static av_cold int alac_encode_init(AVCodecContext *avctx)
#define DEFAULT_MAX_PRED_ORDER
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
enum AVSampleFormat sample_fmt
audio sample format
static void alac_linear_predictor(AlacEncodeContext *s, int ch)
static void alac_entropy_coder(AlacEncodeContext *s)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
struct AlacLPCContext AlacLPCContext
int interlacing_leftweight
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static int init(AVCodecParserContext *s)
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int32_t sample_buf[MAX_CHANNELS][DEFAULT_FRAME_SIZE]
static void calc_predictor_params(AlacEncodeContext *s, int ch)
#define ALAC_MAX_LPC_PRECISION
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct RiceContext RiceContext
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
static int put_bits_count(PutBitContext *s)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
static void write_compressed_frame(AlacEncodeContext *s)
#define ALAC_CHMODE_LEFT_SIDE
#define ALAC_MAX_LPC_ORDER
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int frame_size
Samples per packet, initialized when calling 'init'.
int sample_rate
samples per second
#define ALAC_MAX_LPC_SHIFT
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Levinson-Durbin recursion.
#define ORDER_METHOD_EST
LPC utility code Copyright (c) 2006 Justin Ruggles justin.ruggles@gmail.com
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
static av_const int sign_extend(int val, unsigned bits)
static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define ALAC_CHMODE_LEFT_RIGHT
#define ALAC_CHMODE_RIGHT_SIDE
static av_cold int alac_encode_close(AVCodecContext *avctx)
AVSampleFormat
all in native-endian format
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
#define MKBETAG(a, b, c, d)
int lpc_coeff[ALAC_MAX_LPC_ORDER+1]
int32_t predictor_buf[DEFAULT_FRAME_SIZE]
int channels
number of audio channels
int key_frame
1 -> keyframe, 0-> not
#define DEFAULT_SAMPLE_SIZE
struct AlacEncodeContext AlacEncodeContext
#define ALAC_EXTRADATA_SIZE
#define DEFAULT_FRAME_SIZE
ALAC audio encoder Copyright (c) 2008 Jaikrishnan Menon realityman@gmx.net
static void alac_stereo_decorrelation(AlacEncodeContext *s)
static void encode_scalar(AlacEncodeContext *s, int x, int k, int write_sample_size)
static void write_frame_header(AlacEncodeContext *s, int is_verbatim)
static int alac_encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data)