/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006 Antonius Hellmann
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
// Shine is an MP3 encoder
// Copyright (C) 1999-2000 Gabriel Bouvigne
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library 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
// Library General Public License for more details.
#ifndef SIMULATOR
#include <inttypes.h>
#include "codeclib.h"
CODEC_ENC_HEADER
#define ENC_PADDING_FRAMES1 2
#define ENC_PADDING_FRAMES2 4
#define ENC_DELAY_SAMP 576
#define ENC_DELAY_SIZE (ENC_DELAY_SAMP*4)
#define SAMP_PER_FRAME1 1152
#define SAMP_PER_FRAME2 576
#define PCM_CHUNK_SIZE1 (SAMP_PER_FRAME1*4)
#define PCM_CHUNK_SIZE2 (SAMP_PER_FRAME2*4)
#define SAMPL2 576
#define SBLIMIT 32
#define HTN 16
#define memcpy ci->memcpy
#define memset ci->memset
#define putlong(c, s) if(s+sz <= 32) { cc = (cc << s) | c; sz+= s; } \
else { putbits(cc, sz); cc = c; sz = s; }
typedef struct {
int type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */
int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */
int bitrate;
int padding;
int num_bands;
long bitr_id;
int smpl_id;
} mpeg_t;
/* Side information */
typedef struct {
uint32_t part2_3_length;
int count1; /* number of 0-1-quadruples */
uint32_t global_gain;
uint32_t table_select[4];
uint32_t region_0_1;
uint32_t address1;
uint32_t address2;
uint32_t address3;
long quantStep;
long additStep;
uint32_t max_val;
} side_info_t;
typedef struct {
side_info_t cod_info[2][2];
mpeg_t mpg;
long frac_per_frame;
long byte_per_frame;
long slot_lag;
int sideinfo_len;
int mean_bits;
int ResvSize;
int channels;
int rec_mono_mode;
int granules;
long samplerate;
} config_t;
typedef struct {
int bitpos; /* current bitpos for writing */
uint32_t bbuf[263];
} BF_Data;
struct huffcodetab {
int len; /* max. index */
const uint8_t *table; /* pointer to array[len][len] */
const uint8_t *hlen; /* pointer to array[len][len] */
};
struct huffcodebig {
int len; /* max. index */
int linbits; /* number of linbits */
int linmax; /* max number stored in linbits */
};
#define shft4(x) ((x + 8) >> 4)
#define shft9(x) ((x + 256) >> 9)
#define shft13(x) ((x + 4096) >> 13)
#define shft15(x) ((x + 16384) >> 15)
#define shft16(x) ((x + 32768) >> 16)
#define shft_n(x,n) ((x) >> n)
#define SQRT 724 /* sqrt(2) * 512 */
static short mfbuf [2*(1152+512)] IBSS_ATTR; /* 3328 Bytes */
static int sb_data [2][2][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */
static int mdct_freq [SAMPL2] IBSS_ATTR; /* 2304 Bytes */
static char mdct_sign [SAMPL2] IBSS_ATTR; /* 576 Bytes */
static short enc_data [SAMPL2] IBSS_ATTR; /* 1152 Bytes */
static uint32_t scalefac [23] IBSS_ATTR; /* 92 Bytes */
static BF_Data CodedData IBSS_ATTR; /* 1056 Bytes */
static int ca [8] IBSS_ATTR; /* 32 Bytes */
static int cs [8] IBSS_ATTR; /* 32 Bytes */
static int cx [9] IBSS_ATTR; /* 36 Bytes */
static int win [18][4] IBSS_ATTR; /* 288 Bytes */
static short enwindow [15*27+24] IBSS_ATTR; /* 862 Bytes */
static short int2idx [4096] IBSS_ATTR; /* 8192 Bytes */
static uint8_t ht_count [2][2][16] IBSS_ATTR; /* 64 Bytes */
static uint32_t tab01 [ 16] IBSS_ATTR; /* 64 Bytes */
static uint32_t tab23 [ 9] IBSS_ATTR; /* 36 Bytes */
static uint32_t tab56 [ 16] IBSS_ATTR; /* 64 Bytes */
static uint32_t tab1315 [256] IBSS_ATTR; /* 1024 Bytes */
static uint32_t tab1624 [256] IBSS_ATTR; /* 1024 Bytes */
static uint32_t tab789 [ 36] IBSS_ATTR; /* 144 Bytes */
static uint32_t tabABC [ 64] IBSS_ATTR; /* 256 Bytes */
static uint8_t t1HB [ 4] IBSS_ATTR;
static uint8_t t2HB [ 9] IBSS_ATTR;
static uint8_t t3HB [ 9] IBSS_ATTR;
static uint8_t t5HB [ 16] IBSS_ATTR;
static uint8_t t6HB [ 16] IBSS_ATTR;
static uint8_t t7HB [ 36] IBSS_ATTR;
static uint8_t t8HB [ 36] IBSS_ATTR;
static uint8_t t9HB [ 36] IBSS_ATTR;
static uint8_t t10HB [ 64] IBSS_ATTR;
static uint8_t t11HB [ 64] IBSS_ATTR;
static uint8_t t12HB [ 64] IBSS_ATTR;
static uint8_t t13HB [256] IBSS_ATTR;
static uint8_t t15HB [256] IBSS_ATTR;
static uint16_t t16HB [256] IBSS_ATTR;
static uint16_t t24HB [256] IBSS_ATTR;
static uint8_t t1l [ 8] IBSS_ATTR;
static uint8_t t2l [ 9] IBSS_ATTR;
static uint8_t t3l [ 9] IBSS_ATTR;
static uint8_t t5l [ 16] IBSS_ATTR;
static uint8_t t6l [ 16] IBSS_ATTR;
static uint8_t t7l [ 36] IBSS_ATTR;
static uint8_t t8l [ 36] IBSS_ATTR;
static uint8_t t9l [ 36] IBSS_ATTR;
static uint8_t t10l [ 64] IBSS_ATTR;
static uint8_t t11l [ 64] IBSS_ATTR;
static uint8_t t12l [ 64] IBSS_ATTR;
static uint8_t t13l [256] IBSS_ATTR;
static uint8_t t15l [256] IBSS_ATTR;
static uint8_t t16l [256] IBSS_ATTR;
static uint8_t t24l [256] IBSS_ATTR;
static struct huffcodetab ht [HTN] IBSS_ATTR;
|