2004-08-21 19:19:35 +00:00
|
|
|
/*
|
|
|
|
* Simple free lossless/lossy audio codec
|
|
|
|
* Copyright (c) 2004 Alex Beregszaszi
|
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2004-08-21 19:19:35 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-08-21 19:19:35 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2004-08-21 19:19:35 +00:00
|
|
|
* 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
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-08-21 19:19:35 +00:00
|
|
|
*/
|
|
|
|
#include "avcodec.h"
|
2009-04-13 16:20:26 +00:00
|
|
|
#include "get_bits.h"
|
2004-08-21 19:19:35 +00:00
|
|
|
#include "golomb.h"
|
2012-09-18 13:45:07 +00:00
|
|
|
#include "internal.h"
|
2013-12-10 15:11:13 +00:00
|
|
|
#include "rangecoder.h"
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2004-08-21 19:19:35 +00:00
|
|
|
* Simple free lossless/lossy audio codec
|
|
|
|
* Based on Paul Francis Harrison's Bonk (http://www.logarithmic.net/pfh/bonk)
|
|
|
|
* Written and designed by Alex Beregszaszi
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - CABAC put/get_symbol
|
|
|
|
* - independent quantizer for channels
|
|
|
|
* - >2 channels support
|
|
|
|
* - more decorrelation types
|
|
|
|
* - more tap_quant tests
|
|
|
|
* - selectable intlist writers/readers (bonk-style, golomb, cabac)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_CHANNELS 2
|
|
|
|
|
2004-09-04 11:19:37 +00:00
|
|
|
#define MID_SIDE 0
|
|
|
|
#define LEFT_SIDE 1
|
|
|
|
#define RIGHT_SIDE 2
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
typedef struct SonicContext {
|
2013-12-10 14:49:30 +00:00
|
|
|
int version;
|
2013-12-10 14:54:30 +00:00
|
|
|
int minor_version;
|
2004-09-04 11:19:37 +00:00
|
|
|
int lossless, decorrelation;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
int num_taps, downsampling;
|
|
|
|
double quantization;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
int channels, samplerate, block_align, frame_size;
|
|
|
|
|
|
|
|
int *tap_quant;
|
|
|
|
int *int_samples;
|
|
|
|
int *coded_samples[MAX_CHANNELS];
|
|
|
|
|
|
|
|
// for encoding
|
|
|
|
int *tail;
|
|
|
|
int tail_size;
|
|
|
|
int *window;
|
|
|
|
int window_size;
|
|
|
|
|
|
|
|
// for decoding
|
|
|
|
int *predictor_k;
|
|
|
|
int *predictor_state[MAX_CHANNELS];
|
|
|
|
} SonicContext;
|
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
#define LATTICE_SHIFT 10
|
|
|
|
#define SAMPLE_SHIFT 4
|
|
|
|
#define LATTICE_FACTOR (1 << LATTICE_SHIFT)
|
|
|
|
#define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
#define BASE_QUANT 0.6
|
|
|
|
#define RATE_VARIATION 3.0
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
static inline int shift(int a,int b)
|
|
|
|
{
|
|
|
|
return (a+(1<<(b-1))) >> b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int shift_down(int a,int b)
|
|
|
|
{
|
2013-06-22 19:34:11 +00:00
|
|
|
return (a>>b)+(a<0);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
static av_always_inline av_flatten void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed, uint64_t rc_stat[256][2], uint64_t rc_stat2[32][2]){
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define put_rac(C,S,B) \
|
|
|
|
do{\
|
|
|
|
if(rc_stat){\
|
|
|
|
rc_stat[*(S)][B]++;\
|
|
|
|
rc_stat2[(S)-state][B]++;\
|
|
|
|
}\
|
|
|
|
put_rac(C,S,B);\
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
if(v){
|
|
|
|
const int a= FFABS(v);
|
|
|
|
const int e= av_log2(a);
|
|
|
|
put_rac(c, state+0, 0);
|
|
|
|
if(e<=9){
|
|
|
|
for(i=0; i<e; i++){
|
|
|
|
put_rac(c, state+1+i, 1); //1..10
|
|
|
|
}
|
|
|
|
put_rac(c, state+1+i, 0);
|
|
|
|
|
|
|
|
for(i=e-1; i>=0; i--){
|
|
|
|
put_rac(c, state+22+i, (a>>i)&1); //22..31
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_signed)
|
|
|
|
put_rac(c, state+11 + e, v < 0); //11..21
|
|
|
|
}else{
|
|
|
|
for(i=0; i<e; i++){
|
|
|
|
put_rac(c, state+1+FFMIN(i,9), 1); //1..10
|
|
|
|
}
|
|
|
|
put_rac(c, state+1+9, 0);
|
|
|
|
|
|
|
|
for(i=e-1; i>=0; i--){
|
|
|
|
put_rac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_signed)
|
|
|
|
put_rac(c, state+11 + 10, v < 0); //11..21
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
put_rac(c, state+0, 1);
|
|
|
|
}
|
|
|
|
#undef put_rac
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline av_flatten int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
|
|
|
|
if(get_rac(c, state+0))
|
|
|
|
return 0;
|
|
|
|
else{
|
|
|
|
int i, e, a;
|
|
|
|
e= 0;
|
|
|
|
while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
|
|
|
|
e++;
|
2019-10-21 21:22:05 +00:00
|
|
|
if (e > 31)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2013-12-10 15:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
a= 1;
|
|
|
|
for(i=e-1; i>=0; i--){
|
|
|
|
a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
|
|
|
|
}
|
|
|
|
|
|
|
|
e= -(is_signed && get_rac(c, state+11 + FFMIN(e, 10))); //11..21
|
|
|
|
return (a^e)-e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
#if 1
|
2013-12-10 15:11:13 +00:00
|
|
|
static inline int intlist_write(RangeCoder *c, uint8_t *state, int *buf, int entries, int base_2_part)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < entries; i++)
|
|
|
|
put_symbol(c, state, buf[i], 1, NULL, NULL);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int intlist_read(RangeCoder *c, uint8_t *state, int *buf, int entries, int base_2_part)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < entries; i++)
|
|
|
|
buf[i] = get_symbol(c, state, 1);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#elif 1
|
2004-08-21 19:19:35 +00:00
|
|
|
static inline int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < entries; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
set_se_golomb(pb, buf[i]);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
|
|
|
|
{
|
|
|
|
int i;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < entries; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
buf[i] = get_se_golomb(gb);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define ADAPT_LEVEL 8
|
|
|
|
|
|
|
|
static int bits_to_store(uint64_t x)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
while(x)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
res++;
|
|
|
|
x >>= 1;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_uint_max(PutBitContext *pb, unsigned int value, unsigned int max)
|
|
|
|
{
|
|
|
|
int i, bits;
|
|
|
|
|
|
|
|
if (!max)
|
2005-12-22 01:10:11 +00:00
|
|
|
return;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
bits = bits_to_store(max);
|
|
|
|
|
|
|
|
for (i = 0; i < bits-1; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(pb, 1, value & (1 << i));
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if ( (value | (1 << (bits-1))) <= max)
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(pb, 1, value & (1 << (bits-1)));
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int read_uint_max(GetBitContext *gb, int max)
|
|
|
|
{
|
|
|
|
int i, bits, value = 0;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!max)
|
2005-12-22 01:10:11 +00:00
|
|
|
return 0;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
bits = bits_to_store(max);
|
|
|
|
|
|
|
|
for (i = 0; i < bits-1; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
if (get_bits1(gb))
|
|
|
|
value += 1 << i;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if ( (value | (1<<(bits-1))) <= max)
|
2005-12-22 01:10:11 +00:00
|
|
|
if (get_bits1(gb))
|
|
|
|
value += 1 << (bits-1);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
|
|
|
|
{
|
|
|
|
int i, j, x = 0, low_bits = 0, max = 0;
|
|
|
|
int step = 256, pos = 0, dominant = 0, any = 0;
|
|
|
|
int *copy, *bits;
|
|
|
|
|
2013-06-22 20:34:32 +00:00
|
|
|
copy = av_calloc(entries, sizeof(*copy));
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!copy)
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
if (base_2_part)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int energy = 0;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < entries; i++)
|
|
|
|
energy += abs(buf[i]);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
low_bits = bits_to_store(energy / (entries * 2));
|
|
|
|
if (low_bits > 15)
|
|
|
|
low_bits = 15;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(pb, 4, low_bits);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < entries; i++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(pb, low_bits, abs(buf[i]));
|
|
|
|
copy[i] = abs(buf[i]) >> low_bits;
|
|
|
|
if (copy[i] > max)
|
|
|
|
max = abs(copy[i]);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
2013-06-22 20:34:32 +00:00
|
|
|
bits = av_calloc(entries*max, sizeof(*bits));
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!bits)
|
|
|
|
{
|
2013-12-10 13:42:17 +00:00
|
|
|
av_free(copy);
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i <= max; i++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
for (j = 0; j < entries; j++)
|
|
|
|
if (copy[j] >= i)
|
|
|
|
bits[x++] = copy[j] > i;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// store bitstream
|
|
|
|
while (pos < x)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int steplet = step >> 8;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (pos + steplet > x)
|
|
|
|
steplet = x - pos;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < steplet; i++)
|
|
|
|
if (bits[i+pos] != dominant)
|
|
|
|
any = 1;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(pb, 1, any);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!any)
|
|
|
|
{
|
|
|
|
pos += steplet;
|
|
|
|
step += step / ADAPT_LEVEL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int interloper = 0;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
while (((pos + interloper) < x) && (bits[pos + interloper] == dominant))
|
|
|
|
interloper++;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
// note change
|
|
|
|
write_uint_max(pb, interloper, (step >> 8) - 1);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
pos += interloper + 1;
|
|
|
|
step -= step / ADAPT_LEVEL;
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (step < 256)
|
|
|
|
{
|
|
|
|
step = 65536 / step;
|
|
|
|
dominant = !dominant;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
// store signs
|
|
|
|
for (i = 0; i < entries; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
if (buf[i])
|
|
|
|
put_bits(pb, 1, buf[i] < 0);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-12-10 13:42:17 +00:00
|
|
|
av_free(bits);
|
|
|
|
av_free(copy);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
|
|
|
|
{
|
|
|
|
int i, low_bits = 0, x = 0;
|
|
|
|
int n_zeros = 0, step = 256, dominant = 0;
|
|
|
|
int pos = 0, level = 0;
|
2013-06-22 20:34:32 +00:00
|
|
|
int *bits = av_calloc(entries, sizeof(*bits));
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if (!bits)
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
if (base_2_part)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
low_bits = get_bits(gb, 4);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (low_bits)
|
|
|
|
for (i = 0; i < entries; i++)
|
|
|
|
buf[i] = get_bits(gb, low_bits);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// av_log(NULL, AV_LOG_INFO, "entries: %d, low bits: %d\n", entries, low_bits);
|
|
|
|
|
|
|
|
while (n_zeros < entries)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int steplet = step >> 8;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!get_bits1(gb))
|
|
|
|
{
|
|
|
|
for (i = 0; i < steplet; i++)
|
|
|
|
bits[x++] = dominant;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!dominant)
|
|
|
|
n_zeros += steplet;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
step += step / ADAPT_LEVEL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int actual_run = read_uint_max(gb, steplet-1);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
// av_log(NULL, AV_LOG_INFO, "actual run: %d\n", actual_run);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < actual_run; i++)
|
|
|
|
bits[x++] = dominant;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
bits[x++] = !dominant;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!dominant)
|
|
|
|
n_zeros += actual_run;
|
|
|
|
else
|
|
|
|
n_zeros++;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
step -= step / ADAPT_LEVEL;
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (step < 256)
|
|
|
|
{
|
|
|
|
step = 65536 / step;
|
|
|
|
dominant = !dominant;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
// reconstruct unsigned values
|
|
|
|
n_zeros = 0;
|
|
|
|
for (i = 0; n_zeros < entries; i++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if (pos >= entries)
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
level += 1 << low_bits;
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (buf[pos] >= level)
|
|
|
|
break;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
pos++;
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (bits[i])
|
|
|
|
buf[pos] += 1 << low_bits;
|
|
|
|
else
|
|
|
|
n_zeros++;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
pos++;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2013-12-10 13:42:17 +00:00
|
|
|
av_free(bits);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
// read signs
|
|
|
|
for (i = 0; i < entries; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
if (buf[i] && get_bits1(gb))
|
|
|
|
buf[i] = -buf[i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// av_log(NULL, AV_LOG_INFO, "zeros: %d pos: %d\n", n_zeros, pos);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void predictor_init_state(int *k, int *state, int order)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = order-2; i >= 0; i--)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int j, p, x = state[i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
for (j = 0, p = i+1; p < order; j++,p++)
|
|
|
|
{
|
|
|
|
int tmp = x + shift_down(k[j] * state[p], LATTICE_SHIFT);
|
|
|
|
state[p] += shift_down(k[j]*x, LATTICE_SHIFT);
|
|
|
|
x = tmp;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int predictor_calc_error(int *k, int *state, int order, int error)
|
|
|
|
{
|
|
|
|
int i, x = error - shift_down(k[order-1] * state[order-1], LATTICE_SHIFT);
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
int *k_ptr = &(k[order-2]),
|
2005-12-22 01:10:11 +00:00
|
|
|
*state_ptr = &(state[order-2]);
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = order-2; i >= 0; i--, k_ptr--, state_ptr--)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int k_value = *k_ptr, state_value = *state_ptr;
|
|
|
|
x -= shift_down(k_value * state_value, LATTICE_SHIFT);
|
2019-10-21 21:41:49 +00:00
|
|
|
state_ptr[1] = state_value + shift_down(k_value * (unsigned)x, LATTICE_SHIFT);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
for (i = order-2; i >= 0; i--)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
x -= shift_down(k[i] * state[i], LATTICE_SHIFT);
|
|
|
|
state[i+1] = state[i] + shift_down(k[i] * x, LATTICE_SHIFT);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-12-17 18:14:38 +00:00
|
|
|
// don't drift too far, to avoid overflows
|
2004-08-21 19:19:35 +00:00
|
|
|
if (x > (SAMPLE_FACTOR<<16)) x = (SAMPLE_FACTOR<<16);
|
|
|
|
if (x < -(SAMPLE_FACTOR<<16)) x = -(SAMPLE_FACTOR<<16);
|
|
|
|
|
|
|
|
state[0] = x;
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2009-01-13 23:44:16 +00:00
|
|
|
#if CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER
|
2004-08-21 19:19:35 +00:00
|
|
|
// Heavily modified Levinson-Durbin algorithm which
|
|
|
|
// copes better with quantization, and calculates the
|
|
|
|
// actual whitened result as it goes.
|
|
|
|
|
2015-05-15 15:26:25 +00:00
|
|
|
static int modified_levinson_durbin(int *window, int window_entries,
|
2005-12-22 01:10:11 +00:00
|
|
|
int *out, int out_entries, int channels, int *tap_quant)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
|
|
|
int i;
|
2013-06-22 20:34:32 +00:00
|
|
|
int *state = av_calloc(window_entries, sizeof(*state));
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2015-05-15 15:26:25 +00:00
|
|
|
if (!state)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
memcpy(state, window, 4* window_entries);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < out_entries; i++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int step = (i+1)*channels, k, j;
|
|
|
|
double xx = 0.0, xy = 0.0;
|
2004-08-21 19:19:35 +00:00
|
|
|
#if 1
|
2013-06-19 08:06:10 +00:00
|
|
|
int *x_ptr = &(window[step]);
|
|
|
|
int *state_ptr = &(state[0]);
|
2005-12-22 01:10:11 +00:00
|
|
|
j = window_entries - step;
|
2013-06-19 08:06:38 +00:00
|
|
|
for (;j>0;j--,x_ptr++,state_ptr++)
|
2005-12-22 01:10:11 +00:00
|
|
|
{
|
2013-06-19 08:06:10 +00:00
|
|
|
double x_value = *x_ptr;
|
|
|
|
double state_value = *state_ptr;
|
2005-12-22 01:10:11 +00:00
|
|
|
xx += state_value*state_value;
|
|
|
|
xy += x_value*state_value;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
#else
|
2005-12-22 01:10:11 +00:00
|
|
|
for (j = 0; j <= (window_entries - step); j++);
|
|
|
|
{
|
2013-06-19 08:06:10 +00:00
|
|
|
double stepval = window[step+j];
|
|
|
|
double stateval = window[j];
|
2005-12-22 01:10:11 +00:00
|
|
|
// xx += (double)window[j]*(double)window[j];
|
|
|
|
// xy += (double)window[step+j]*(double)window[j];
|
|
|
|
xx += stateval*stateval;
|
|
|
|
xy += stepval*stateval;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
#endif
|
2005-12-22 01:10:11 +00:00
|
|
|
if (xx == 0.0)
|
|
|
|
k = 0;
|
|
|
|
else
|
|
|
|
k = (int)(floor(-xy/xx * (double)LATTICE_FACTOR / (double)(tap_quant[i]) + 0.5));
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (k > (LATTICE_FACTOR/tap_quant[i]))
|
|
|
|
k = LATTICE_FACTOR/tap_quant[i];
|
|
|
|
if (-k > (LATTICE_FACTOR/tap_quant[i]))
|
|
|
|
k = -(LATTICE_FACTOR/tap_quant[i]);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
out[i] = k;
|
|
|
|
k *= tap_quant[i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
#if 1
|
2005-12-22 01:10:11 +00:00
|
|
|
x_ptr = &(window[step]);
|
|
|
|
state_ptr = &(state[0]);
|
|
|
|
j = window_entries - step;
|
2013-06-19 08:06:38 +00:00
|
|
|
for (;j>0;j--,x_ptr++,state_ptr++)
|
2005-12-22 01:10:11 +00:00
|
|
|
{
|
2013-06-19 08:06:10 +00:00
|
|
|
int x_value = *x_ptr;
|
|
|
|
int state_value = *state_ptr;
|
2005-12-22 01:10:11 +00:00
|
|
|
*x_ptr = x_value + shift_down(k*state_value,LATTICE_SHIFT);
|
|
|
|
*state_ptr = state_value + shift_down(k*x_value, LATTICE_SHIFT);
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
#else
|
2005-12-22 01:10:11 +00:00
|
|
|
for (j=0; j <= (window_entries - step); j++)
|
|
|
|
{
|
2013-06-19 08:06:10 +00:00
|
|
|
int stepval = window[step+j];
|
|
|
|
int stateval=state[j];
|
2005-12-22 01:10:11 +00:00
|
|
|
window[step+j] += shift_down(k * stateval, LATTICE_SHIFT);
|
|
|
|
state[j] += shift_down(k * stepval, LATTICE_SHIFT);
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
av_free(state);
|
2015-05-15 15:26:25 +00:00
|
|
|
return 0;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int code_samplerate(int samplerate)
|
|
|
|
{
|
|
|
|
switch (samplerate)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
case 44100: return 0;
|
|
|
|
case 22050: return 1;
|
|
|
|
case 11025: return 2;
|
|
|
|
case 96000: return 3;
|
|
|
|
case 48000: return 4;
|
|
|
|
case 32000: return 5;
|
|
|
|
case 24000: return 6;
|
|
|
|
case 16000: return 7;
|
|
|
|
case 8000: return 8;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(EINVAL);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 03:11:20 +00:00
|
|
|
static av_cold int sonic_encode_init(AVCodecContext *avctx)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
|
|
|
SonicContext *s = avctx->priv_data;
|
|
|
|
PutBitContext pb;
|
2013-12-10 14:49:30 +00:00
|
|
|
int i;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
s->version = 2;
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
if (avctx->channels > MAX_CHANNELS)
|
2004-08-22 12:40:57 +00:00
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(EINVAL); /* only stereo or mono for now */
|
2004-08-22 12:40:57 +00:00
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if (avctx->channels == 2)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->decorrelation = MID_SIDE;
|
2013-03-21 14:49:22 +00:00
|
|
|
else
|
|
|
|
s->decorrelation = 3;
|
2004-08-22 12:40:57 +00:00
|
|
|
|
2012-08-07 20:45:46 +00:00
|
|
|
if (avctx->codec->id == AV_CODEC_ID_SONIC_LS)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
s->lossless = 1;
|
|
|
|
s->num_taps = 32;
|
|
|
|
s->downsampling = 1;
|
|
|
|
s->quantization = 0.0;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
s->num_taps = 128;
|
|
|
|
s->downsampling = 2;
|
|
|
|
s->quantization = 1.0;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// max tap 2048
|
2013-06-23 17:44:24 +00:00
|
|
|
if (s->num_taps < 32 || s->num_taps > 1024 || s->num_taps % 32) {
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// generate taps
|
2013-06-22 20:34:32 +00:00
|
|
|
s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
|
2015-05-15 15:26:25 +00:00
|
|
|
if (!s->tap_quant)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < s->num_taps; i++)
|
2013-06-22 23:25:55 +00:00
|
|
|
s->tap_quant[i] = ff_sqrt(i+1);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
s->channels = avctx->channels;
|
|
|
|
s->samplerate = avctx->sample_rate;
|
|
|
|
|
2013-06-22 19:58:13 +00:00
|
|
|
s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
|
2004-08-21 19:19:35 +00:00
|
|
|
s->frame_size = s->channels*s->block_align*s->downsampling;
|
|
|
|
|
2012-09-18 15:37:41 +00:00
|
|
|
s->tail_size = s->num_taps*s->channels;
|
2013-06-22 20:34:32 +00:00
|
|
|
s->tail = av_calloc(s->tail_size, sizeof(*s->tail));
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!s->tail)
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-06-22 20:34:32 +00:00
|
|
|
s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k) );
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!s->predictor_k)
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
for (i = 0; i < s->channels; i++)
|
|
|
|
{
|
2013-06-22 20:34:32 +00:00
|
|
|
s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples));
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!s->coded_samples[i])
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-06-22 20:34:32 +00:00
|
|
|
s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
s->window_size = ((2*s->tail_size)+s->frame_size);
|
2013-06-22 20:34:32 +00:00
|
|
|
s->window = av_calloc(s->window_size, sizeof(*s->window));
|
2015-05-15 15:26:25 +00:00
|
|
|
if (!s->window || !s->int_samples)
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
avctx->extradata = av_mallocz(16);
|
|
|
|
if (!avctx->extradata)
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
init_put_bits(&pb, avctx->extradata, 16*8);
|
|
|
|
|
2013-12-10 14:49:30 +00:00
|
|
|
put_bits(&pb, 2, s->version); // version
|
2013-12-10 14:54:30 +00:00
|
|
|
if (s->version >= 1)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
2013-12-10 14:54:30 +00:00
|
|
|
if (s->version >= 2) {
|
|
|
|
put_bits(&pb, 8, s->version);
|
|
|
|
put_bits(&pb, 8, s->minor_version);
|
|
|
|
}
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(&pb, 2, s->channels);
|
|
|
|
put_bits(&pb, 4, code_samplerate(s->samplerate));
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
put_bits(&pb, 1, s->lossless);
|
|
|
|
if (!s->lossless)
|
2005-12-22 01:10:11 +00:00
|
|
|
put_bits(&pb, 3, SAMPLE_SHIFT); // XXX FIXME: sample precision
|
2004-09-04 11:19:37 +00:00
|
|
|
put_bits(&pb, 2, s->decorrelation);
|
2004-08-21 19:19:35 +00:00
|
|
|
put_bits(&pb, 2, s->downsampling);
|
|
|
|
put_bits(&pb, 5, (s->num_taps >> 5)-1); // 32..1024
|
|
|
|
put_bits(&pb, 1, 0); // XXX FIXME: no custom tap quant table
|
|
|
|
|
|
|
|
flush_put_bits(&pb);
|
|
|
|
avctx->extradata_size = put_bits_count(&pb)/8;
|
|
|
|
|
2013-12-10 14:54:30 +00:00
|
|
|
av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d.%d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
|
|
|
|
s->version, s->minor_version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
avctx->frame_size = s->block_align*s->downsampling;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-21 03:11:20 +00:00
|
|
|
static av_cold int sonic_encode_close(AVCodecContext *avctx)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
|
|
|
SonicContext *s = avctx->priv_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < s->channels; i++)
|
2013-06-23 17:45:39 +00:00
|
|
|
av_freep(&s->coded_samples[i]);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-06-23 17:45:39 +00:00
|
|
|
av_freep(&s->predictor_k);
|
|
|
|
av_freep(&s->tail);
|
|
|
|
av_freep(&s->tap_quant);
|
|
|
|
av_freep(&s->window);
|
|
|
|
av_freep(&s->int_samples);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-18 13:45:07 +00:00
|
|
|
static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
|
|
|
const AVFrame *frame, int *got_packet_ptr)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
|
|
|
SonicContext *s = avctx->priv_data;
|
2013-12-10 15:11:13 +00:00
|
|
|
RangeCoder c;
|
2004-08-21 19:19:35 +00:00
|
|
|
int i, j, ch, quant = 0, x = 0;
|
2012-09-18 13:45:07 +00:00
|
|
|
int ret;
|
|
|
|
const short *samples = (const int16_t*)frame->data[0];
|
2013-12-10 15:11:13 +00:00
|
|
|
uint8_t state[32];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2015-07-27 17:36:16 +00:00
|
|
|
if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000, 0)) < 0)
|
2012-09-18 13:45:07 +00:00
|
|
|
return ret;
|
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
ff_init_range_encoder(&c, avpkt->data, avpkt->size);
|
|
|
|
ff_build_rac_states(&c, 0.05*(1LL<<32), 256-8);
|
|
|
|
memset(state, 128, sizeof(state));
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// short -> internal
|
|
|
|
for (i = 0; i < s->frame_size; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->int_samples[i] = samples[i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if (!s->lossless)
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < s->frame_size; i++)
|
|
|
|
s->int_samples[i] = s->int_samples[i] << SAMPLE_SHIFT;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2004-09-04 11:19:37 +00:00
|
|
|
switch(s->decorrelation)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
case MID_SIDE:
|
|
|
|
for (i = 0; i < s->frame_size; i += s->channels)
|
|
|
|
{
|
|
|
|
s->int_samples[i] += s->int_samples[i+1];
|
|
|
|
s->int_samples[i+1] -= shift(s->int_samples[i], 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LEFT_SIDE:
|
|
|
|
for (i = 0; i < s->frame_size; i += s->channels)
|
|
|
|
s->int_samples[i+1] -= s->int_samples[i];
|
|
|
|
break;
|
|
|
|
case RIGHT_SIDE:
|
|
|
|
for (i = 0; i < s->frame_size; i += s->channels)
|
|
|
|
s->int_samples[i] -= s->int_samples[i+1];
|
|
|
|
break;
|
2004-09-04 11:19:37 +00:00
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
memset(s->window, 0, 4* s->window_size);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < s->tail_size; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->window[x++] = s->tail[i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
for (i = 0; i < s->frame_size; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->window[x++] = s->int_samples[i];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < s->tail_size; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->window[x++] = 0;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
for (i = 0; i < s->tail_size; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// generate taps
|
2015-05-15 15:26:25 +00:00
|
|
|
ret = modified_levinson_durbin(s->window, s->window_size,
|
2005-12-22 01:10:11 +00:00
|
|
|
s->predictor_k, s->num_taps, s->channels, s->tap_quant);
|
2015-05-15 15:26:25 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
if ((ret = intlist_write(&c, state, s->predictor_k, s->num_taps, 0)) < 0)
|
2013-06-22 19:42:04 +00:00
|
|
|
return ret;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
for (ch = 0; ch < s->channels; ch++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
x = s->tail_size+ch;
|
|
|
|
for (i = 0; i < s->block_align; i++)
|
|
|
|
{
|
|
|
|
int sum = 0;
|
|
|
|
for (j = 0; j < s->downsampling; j++, x += s->channels)
|
|
|
|
sum += s->window[x];
|
|
|
|
s->coded_samples[ch][i] = sum;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
|
|
|
// simple rate control code
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!s->lossless)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
double energy1 = 0.0, energy2 = 0.0;
|
|
|
|
for (ch = 0; ch < s->channels; ch++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < s->block_align; i++)
|
|
|
|
{
|
|
|
|
double sample = s->coded_samples[ch][i];
|
|
|
|
energy2 += sample*sample;
|
|
|
|
energy1 += fabs(sample);
|
|
|
|
}
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
energy2 = sqrt(energy2/(s->channels*s->block_align));
|
2011-05-04 15:20:49 +00:00
|
|
|
energy1 = M_SQRT2*energy1/(s->channels*s->block_align);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
// increase bitrate when samples are like a gaussian distribution
|
|
|
|
// reduce bitrate when samples are like a two-tailed exponential distribution
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
if (energy2 > energy1)
|
|
|
|
energy2 += (energy2-energy1)*RATE_VARIATION;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
quant = (int)(BASE_QUANT*s->quantization*energy2/SAMPLE_FACTOR);
|
|
|
|
// av_log(avctx, AV_LOG_DEBUG, "quant: %d energy: %f / %f\n", quant, energy1, energy2);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-06-22 23:22:26 +00:00
|
|
|
quant = av_clip(quant, 1, 65534);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
put_symbol(&c, state, quant, 0, NULL, NULL);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
quant *= SAMPLE_FACTOR;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// write out coded samples
|
|
|
|
for (ch = 0; ch < s->channels; ch++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!s->lossless)
|
|
|
|
for (i = 0; i < s->block_align; i++)
|
2013-06-23 17:42:24 +00:00
|
|
|
s->coded_samples[ch][i] = ROUNDED_DIV(s->coded_samples[ch][i], quant);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
if ((ret = intlist_write(&c, state, s->coded_samples[ch], s->block_align, 1)) < 0)
|
2013-06-22 19:42:04 +00:00
|
|
|
return ret;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
|
|
|
|
|
2018-12-19 01:40:18 +00:00
|
|
|
avpkt->size = ff_rac_terminate(&c, 0);
|
2012-09-18 13:45:07 +00:00
|
|
|
*got_packet_ptr = 1;
|
|
|
|
return 0;
|
2013-12-10 15:11:13 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2009-01-13 23:44:16 +00:00
|
|
|
#endif /* CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER */
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2009-01-13 23:44:16 +00:00
|
|
|
#if CONFIG_SONIC_DECODER
|
2009-07-16 21:37:58 +00:00
|
|
|
static const int samplerate_table[] =
|
|
|
|
{ 44100, 22050, 11025, 96000, 48000, 32000, 24000, 16000, 8000 };
|
|
|
|
|
2008-03-21 03:11:20 +00:00
|
|
|
static av_cold int sonic_decode_init(AVCodecContext *avctx)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
|
|
|
SonicContext *s = avctx->priv_data;
|
|
|
|
GetBitContext gb;
|
2013-12-10 14:49:30 +00:00
|
|
|
int i;
|
2015-09-03 23:18:13 +00:00
|
|
|
int ret;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
s->channels = avctx->channels;
|
|
|
|
s->samplerate = avctx->sample_rate;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
if (!avctx->extradata)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2015-09-03 23:18:13 +00:00
|
|
|
ret = init_get_bits8(&gb, avctx->extradata, avctx->extradata_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-12-10 14:49:30 +00:00
|
|
|
s->version = get_bits(&gb, 2);
|
2013-12-10 14:54:30 +00:00
|
|
|
if (s->version >= 2) {
|
|
|
|
s->version = get_bits(&gb, 8);
|
|
|
|
s->minor_version = get_bits(&gb, 8);
|
|
|
|
}
|
2013-12-10 15:11:13 +00:00
|
|
|
if (s->version != 2)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 14:54:30 +00:00
|
|
|
if (s->version >= 1)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
2015-05-15 15:31:58 +00:00
|
|
|
int sample_rate_index;
|
2005-12-22 01:10:11 +00:00
|
|
|
s->channels = get_bits(&gb, 2);
|
2015-05-15 15:31:58 +00:00
|
|
|
sample_rate_index = get_bits(&gb, 4);
|
|
|
|
if (sample_rate_index >= FF_ARRAY_ELEMS(samplerate_table)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid sample_rate_index %d\n", sample_rate_index);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
s->samplerate = samplerate_table[sample_rate_index];
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n",
|
|
|
|
s->channels, s->samplerate);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 15:31:58 +00:00
|
|
|
if (s->channels > MAX_CHANNELS || s->channels < 1)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2015-06-09 20:41:24 +00:00
|
|
|
avctx->channels = s->channels;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
s->lossless = get_bits1(&gb);
|
|
|
|
if (!s->lossless)
|
2005-12-22 01:10:11 +00:00
|
|
|
skip_bits(&gb, 3); // XXX FIXME
|
2004-09-04 11:19:37 +00:00
|
|
|
s->decorrelation = get_bits(&gb, 2);
|
2013-03-21 14:45:59 +00:00
|
|
|
if (s->decorrelation != 3 && s->channels != 2) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid decorrelation %d\n", s->decorrelation);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
s->downsampling = get_bits(&gb, 2);
|
2012-06-25 22:38:05 +00:00
|
|
|
if (!s->downsampling) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid downsampling value\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
s->num_taps = (get_bits(&gb, 5)+1)<<5;
|
|
|
|
if (get_bits1(&gb)) // XXX FIXME
|
2005-12-22 01:10:11 +00:00
|
|
|
av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-06-22 19:58:13 +00:00
|
|
|
s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
|
2004-08-21 19:19:35 +00:00
|
|
|
s->frame_size = s->channels*s->block_align*s->downsampling;
|
|
|
|
// avctx->frame_size = s->block_align;
|
|
|
|
|
2015-12-15 22:43:03 +00:00
|
|
|
if (s->num_taps * s->channels > s->frame_size) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"number of taps times channels (%d * %d) larger than frame size %d\n",
|
|
|
|
s->num_taps, s->channels, s->frame_size);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2013-12-10 14:54:30 +00:00
|
|
|
av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d.%d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
|
|
|
|
s->version, s->minor_version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// generate taps
|
2013-06-22 20:34:32 +00:00
|
|
|
s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
|
2015-05-15 15:26:25 +00:00
|
|
|
if (!s->tap_quant)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < s->num_taps; i++)
|
2013-06-22 23:25:55 +00:00
|
|
|
s->tap_quant[i] = ff_sqrt(i+1);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-06-22 20:34:32 +00:00
|
|
|
s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k));
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < s->channels; i++)
|
|
|
|
{
|
2013-06-22 20:34:32 +00:00
|
|
|
s->predictor_state[i] = av_calloc(s->num_taps, sizeof(**s->predictor_state));
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!s->predictor_state[i])
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < s->channels; i++)
|
|
|
|
{
|
2013-06-22 20:34:32 +00:00
|
|
|
s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples));
|
2005-12-22 01:10:11 +00:00
|
|
|
if (!s->coded_samples[i])
|
2013-06-22 19:42:04 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2013-06-22 20:34:32 +00:00
|
|
|
s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
|
2015-05-15 15:26:25 +00:00
|
|
|
if (!s->int_samples)
|
|
|
|
return AVERROR(ENOMEM);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2010-11-12 11:04:40 +00:00
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
|
2004-08-21 19:19:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-21 03:11:20 +00:00
|
|
|
static av_cold int sonic_decode_close(AVCodecContext *avctx)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
|
|
|
SonicContext *s = avctx->priv_data;
|
|
|
|
int i;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-06-23 17:45:39 +00:00
|
|
|
av_freep(&s->int_samples);
|
|
|
|
av_freep(&s->tap_quant);
|
|
|
|
av_freep(&s->predictor_k);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
for (i = 0; i < s->channels; i++)
|
|
|
|
{
|
2013-06-23 17:45:39 +00:00
|
|
|
av_freep(&s->predictor_state[i]);
|
|
|
|
av_freep(&s->coded_samples[i]);
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sonic_decode_frame(AVCodecContext *avctx,
|
2012-03-16 14:10:33 +00:00
|
|
|
void *data, int *got_frame_ptr,
|
2009-04-07 15:59:50 +00:00
|
|
|
AVPacket *avpkt)
|
2004-08-21 19:19:35 +00:00
|
|
|
{
|
2009-04-07 15:59:50 +00:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
int buf_size = avpkt->size;
|
2004-08-21 19:19:35 +00:00
|
|
|
SonicContext *s = avctx->priv_data;
|
2013-12-10 15:11:13 +00:00
|
|
|
RangeCoder c;
|
|
|
|
uint8_t state[32];
|
2012-03-16 14:10:33 +00:00
|
|
|
int i, quant, ch, j, ret;
|
2012-03-23 13:11:53 +00:00
|
|
|
int16_t *samples;
|
2013-03-21 15:00:35 +00:00
|
|
|
AVFrame *frame = data;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if (buf_size == 0) return 0;
|
|
|
|
|
2013-03-21 15:00:35 +00:00
|
|
|
frame->nb_samples = s->frame_size / avctx->channels;
|
|
|
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
2012-03-16 14:10:33 +00:00
|
|
|
return ret;
|
2013-03-21 15:00:35 +00:00
|
|
|
samples = (int16_t *)frame->data[0];
|
2012-03-16 14:10:33 +00:00
|
|
|
|
2004-08-21 19:19:35 +00:00
|
|
|
// av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
memset(state, 128, sizeof(state));
|
|
|
|
ff_init_range_decoder(&c, buf, buf_size);
|
|
|
|
ff_build_rac_states(&c, 0.05*(1LL<<32), 256-8);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
intlist_read(&c, state, s->predictor_k, s->num_taps, 0);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// dequantize
|
|
|
|
for (i = 0; i < s->num_taps; i++)
|
2005-12-22 01:10:11 +00:00
|
|
|
s->predictor_k[i] *= s->tap_quant[i];
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if (s->lossless)
|
2005-12-22 01:10:11 +00:00
|
|
|
quant = 1;
|
2004-08-21 19:19:35 +00:00
|
|
|
else
|
2013-12-10 15:11:13 +00:00
|
|
|
quant = get_symbol(&c, state, 0) * SAMPLE_FACTOR;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// av_log(NULL, AV_LOG_INFO, "quant: %d\n", quant);
|
|
|
|
|
|
|
|
for (ch = 0; ch < s->channels; ch++)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
int x = ch;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
predictor_init_state(s->predictor_k, s->predictor_state[ch], s->num_taps);
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
intlist_read(&c, state, s->coded_samples[ch], s->block_align, 1);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < s->block_align; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < s->downsampling - 1; j++)
|
|
|
|
{
|
|
|
|
s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, 0);
|
|
|
|
x += s->channels;
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, s->coded_samples[ch][i] * quant);
|
|
|
|
x += s->channels;
|
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < s->num_taps; i++)
|
|
|
|
s->predictor_state[ch][i] = s->int_samples[s->frame_size - s->channels + ch - i*s->channels];
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-09-04 11:19:37 +00:00
|
|
|
switch(s->decorrelation)
|
|
|
|
{
|
2005-12-22 01:10:11 +00:00
|
|
|
case MID_SIDE:
|
|
|
|
for (i = 0; i < s->frame_size; i += s->channels)
|
|
|
|
{
|
|
|
|
s->int_samples[i+1] += shift(s->int_samples[i], 1);
|
|
|
|
s->int_samples[i] -= s->int_samples[i+1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LEFT_SIDE:
|
|
|
|
for (i = 0; i < s->frame_size; i += s->channels)
|
|
|
|
s->int_samples[i+1] += s->int_samples[i];
|
|
|
|
break;
|
|
|
|
case RIGHT_SIDE:
|
|
|
|
for (i = 0; i < s->frame_size; i += s->channels)
|
|
|
|
s->int_samples[i] += s->int_samples[i+1];
|
|
|
|
break;
|
2004-09-04 11:19:37 +00:00
|
|
|
}
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
if (!s->lossless)
|
2005-12-22 01:10:11 +00:00
|
|
|
for (i = 0; i < s->frame_size; i++)
|
|
|
|
s->int_samples[i] = shift(s->int_samples[i], SAMPLE_SHIFT);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
|
|
|
// internal -> short
|
|
|
|
for (i = 0; i < s->frame_size; i++)
|
2007-08-11 22:48:55 +00:00
|
|
|
samples[i] = av_clip_int16(s->int_samples[i]);
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2012-03-16 14:10:33 +00:00
|
|
|
*got_frame_ptr = 1;
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2013-12-10 15:11:13 +00:00
|
|
|
return buf_size;
|
2004-08-21 19:19:35 +00:00
|
|
|
}
|
2009-07-16 21:37:58 +00:00
|
|
|
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_sonic_decoder = {
|
2011-12-30 19:00:53 +00:00
|
|
|
.name = "sonic",
|
2013-10-04 13:33:20 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Sonic"),
|
2011-12-30 19:00:53 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-07 20:45:46 +00:00
|
|
|
.id = AV_CODEC_ID_SONIC,
|
2011-12-30 19:00:53 +00:00
|
|
|
.priv_data_size = sizeof(SonicContext),
|
|
|
|
.init = sonic_decode_init,
|
|
|
|
.close = sonic_decode_close,
|
|
|
|
.decode = sonic_decode_frame,
|
2015-07-27 20:21:19 +00:00
|
|
|
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_EXPERIMENTAL,
|
2009-07-16 21:37:58 +00:00
|
|
|
};
|
2008-09-02 23:25:57 +00:00
|
|
|
#endif /* CONFIG_SONIC_DECODER */
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2009-01-13 23:44:16 +00:00
|
|
|
#if CONFIG_SONIC_ENCODER
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_sonic_encoder = {
|
2011-12-30 19:00:53 +00:00
|
|
|
.name = "sonic",
|
2013-10-04 13:33:20 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Sonic"),
|
2011-12-30 19:00:53 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-07 20:45:46 +00:00
|
|
|
.id = AV_CODEC_ID_SONIC,
|
2011-12-30 19:00:53 +00:00
|
|
|
.priv_data_size = sizeof(SonicContext),
|
|
|
|
.init = sonic_encode_init,
|
2012-09-18 13:45:07 +00:00
|
|
|
.encode2 = sonic_encode_frame,
|
2013-06-19 07:50:01 +00:00
|
|
|
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
|
2015-07-27 20:21:19 +00:00
|
|
|
.capabilities = AV_CODEC_CAP_EXPERIMENTAL,
|
2011-12-30 19:00:53 +00:00
|
|
|
.close = sonic_encode_close,
|
2004-08-21 19:19:35 +00:00
|
|
|
};
|
2008-09-03 12:33:21 +00:00
|
|
|
#endif
|
2004-08-21 19:19:35 +00:00
|
|
|
|
2009-01-13 23:44:16 +00:00
|
|
|
#if CONFIG_SONIC_LS_ENCODER
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_sonic_ls_encoder = {
|
2011-12-30 19:00:53 +00:00
|
|
|
.name = "sonicls",
|
2013-10-04 13:33:20 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),
|
2011-12-30 19:00:53 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-07 20:45:46 +00:00
|
|
|
.id = AV_CODEC_ID_SONIC_LS,
|
2011-12-30 19:00:53 +00:00
|
|
|
.priv_data_size = sizeof(SonicContext),
|
|
|
|
.init = sonic_encode_init,
|
2012-09-18 13:45:07 +00:00
|
|
|
.encode2 = sonic_encode_frame,
|
2013-06-19 07:50:01 +00:00
|
|
|
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
|
2015-07-27 20:21:19 +00:00
|
|
|
.capabilities = AV_CODEC_CAP_EXPERIMENTAL,
|
2011-12-30 19:00:53 +00:00
|
|
|
.close = sonic_encode_close,
|
2004-08-21 19:19:35 +00:00
|
|
|
};
|
|
|
|
#endif
|