/* -*- mode: C; mode: fold -*- */
/*
* LAME MP3 encoding engine
*
* Copyright (c) 1999-2000 Mark Taylor
* Copyright (c) 2000-2005 Takehiro Tominaga
* Copyright (c) 2000-2017 Robert Hegemann
* Copyright (c) 2000-2005 Gabriel Bouvigne
* Copyright (c) 2000-2004 Alexander Leidinger
*
* 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.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* $Id: lame.c,v 1.377 2017/09/26 12:14:02 robert Exp $ */
#include "config.h"
#include "lame.h"
#include "machine.h"
#include "encoder.h"
#include "util.h"
#include "lame_global_flags.h"
#include "gain_analysis.h"
#include "bitstream.h"
#include "quantize_pvt.h"
#include "set_get.h"
#include "quantize.h"
#include "psymodel.h"
#include "version.h"
#include "VbrTag.h"
#include "tables.h"
#if defined(__FreeBSD__) && !defined(__alpha__)
#include <floatingpoint.h>
#endif
#ifdef __riscos__
#include "asmstuff.h"
#endif
#ifdef __sun__
/* woraround for SunOS 4.x, it has SEEK_* defined here */
#include <unistd.h>
#endif
#define LAME_DEFAULT_QUALITY 3
int
is_lame_global_flags_valid(const lame_global_flags * gfp)
{
if (gfp == NULL)
return 0;
if (gfp->class_id != LAME_ID)
return 0;
return 1;
}
int
is_lame_internal_flags_valid(const lame_internal_flags * gfc)
{
if (gfc == NULL)
return 0;
if (gfc->class_id != LAME_ID)
return 0;
if (gfc->lame_init_params_successful <=0)
return 0;
return 1;
}
static FLOAT
filter_coef(FLOAT x)
{
if (x > 1.0)
return 0.0;
if (x <= 0.0)
return 1.0;
return cos(PI / 2 * x);
}
static void
lame_init_params_ppflt(lame_internal_flags * gfc)
{
SessionConfig_t *const cfg = &gfc->cfg;
/***************************************************************/
/* compute info needed for polyphase filter (filter type==0, default) */
/***************************************************************/
int band, maxband, minband;
FLOAT freq;
int lowpass_band = 32;
int highpass_band = -1;
if (cfg->lowpass1 > 0) {
minband = 999;
for (band = 0; band <= 31; band++) {
freq = band / 31.0;
/* this band and above will be zeroed: */
if (freq >= cfg->lowpass2) {
lowpass_band = Min(lowpass_band, band);
}
if (cfg->lowpass1 < freq && freq < cfg->lowpass2) {
minband = Min(minband, band);
}
}
/* compute the *actual* transition band implemented by
* the polyphase filter */
if (minband == 999) {
cfg->lowpass1 = (lowpass_band - .75) / 31.0;
}
else {
cfg->lowpass1 = (minband - .75) / 31.0;
}
cfg->lowpass2 = lowpass_band / 31.0;
}
/* make sure highpass filter is within 90% of what the effective
* highpass frequency will be */
if (cfg->highpass2 > 0) {
if (cfg->highpass2 < .9 * (.75 / 31.0)) {
cfg->highpass1 = 0;
cfg->highpass2 = 0;
MSGF(gfc, "Warning: highpass filter disabled. " "highpass frequency too small\n");
}
}
if (cfg->highpass2 > 0) {
maxband = -1;
for (band = 0; band <= 31; band++) {
freq = band / 31.0;
/* this band and below will be zereod */
if (freq <= cfg->highpass1) {
highpass_band = Max(highpass_band, band);
}
if (cfg->highpass1 < freq && freq < cfg->highpass2) {
maxband = Max(maxband, band);
}
}
/* compute the *actual* transition band implemented by
* the polyphase filter */
cfg->highpass1 = highpass_band / 31.0;
if (maxband == -1) {
cfg->highpass2 = (highpass_band + .75) / 31.0;
}
else {
cfg->highpass2 = (maxband + .75) / 31.0;
}
}
for (band = 0; band < 32; band++) {
FLOAT fc1, fc2;
freq = band / 31.0f;
if (cfg->highpass2 > cfg->highpass1) {
fc1 = filter_coef((cfg->highpass2 - freq) / (cfg->highpass2 - cfg->highpass1 + 1e-20));
}
else {
fc1 = 1.0f;
}
if (cfg->lowpass2 > cfg->lowpass1) {
fc2 = filter_coef((freq - cfg->lowpass1) / (cfg->lowpass2 - cfg->lowpass1 + 1e-20));
}
else {
fc2 = 1.0f;
}
gfc->sv_enc.amp_filter[band] = fc1 * fc2;
}
}
static void
optimum_bandwidth(double *const lowerlimit, double *const upperlimit, const unsigned bitrate)
{
/*
* Input:
* bitrate total bitrate in kbps
*
* Output:
* lowerlimit: best lowpass frequency limit for input filter in Hz
* upperlimit: best highpass frequency limit for input filter in Hz
*/
int table_index;
typedef struct {
int bitrate; /* only indicative value */
int lowpass;
} band_pass_t;
const band_pass_t freq_map[] = {
{8, 2000},
{16, 3700},
{24, 3900},
{32, 5500},
{40, 7000},
{48, 7500},
{56, 10000},
{64, 11000},
{80, 13500},
{96, 15100},
{112, 15600},
{128, 17000},
{160, 17500},
{192, 18600},
{224, 19400},
{256, 19700},
{320, 20500}
};
table_index = nearestBitrateFullIndex(bitrate);
(void) freq_map[table_index].bitrate;
*lowerlimit = freq_map[table_index].lowpass;
/*
* Now we try to choose a good high pass filtering frequency.
* This value is currently not used.
* For fu < 16 kHz: sqrt(fu*fl) = 560 Hz
* For fu = 18 kHz: no high pass filtering
* This gives:
*
* 2 kHz => 160 Hz
* 3 kHz => 107 Hz
* 4 kHz => 80 Hz
* 8 kHz => 40 Hz
* 16 kHz => 20 Hz
* 17 kHz => 10 Hz
* 18 kHz => 0 Hz
*
* These are ad hoc values and these can be optimized if a high pass is available.
*/
/* if (f_low <= 16000)
f_high = 16000. * 20. / f_low;
else if (f_low <= 18000)
f_high = 180. - 0.01 * f_low;
else
f_high = 0.;*/
/*
* When we sometimes have a good highpass filter, we can add the highpass
* frequency to the lowpass frequency
*/
/*if (upperlimit != NULL)
*upperlimit = f_high;*/
(void) upperlimit;
}
static int
optimum_samplefreq(int lowpassfreq, int input_samplefreq)
{
/*
* Rules:
* - if possible, sfb21 should NOT be used
*
*/
int suggested_samplefreq = 44100;
if (input_samplefreq >= 48000)
suggested_samplefreq = 48000;
else if (input_samplefreq >= 44100)
suggested_samplefreq = 44100;
else if (input_samplefreq >= 32000)
suggested_samplefreq = 32000;
else if (input_samplefreq >= 24000)
suggested_samplefreq = 24000;
else if (input_samplefreq >= 22050)
suggested_samplefreq = 22050;
else if (input_samplefreq >= 16000)
suggested_samplefreq = 16000;
else if (input_samplefreq >= 12000)
suggested_samplefreq = 12000;
else if (input_samplefreq >= 11025)
suggested_samplefreq = 11025;
else if (input_samplefreq >= 8000)
suggested_samplefreq = 8000;
if (lowpassfreq == -1)
return suggested_samplefreq;
if (lowpassfreq <=
没有合适的资源?快使用搜索试试~ 我知道了~
libmp3lame编码解码mp3文件
共63个文件
h:35个
c:27个
mk:1个
需积分: 50 42 下载量 87 浏览量
2018-02-27
09:49:16
上传
评论 1
收藏 253KB ZIP 举报
温馨提示
libmp3lame是第三方开源的编解码mp3的C代码工具,androidstudio可直接引入编译
资源推荐
资源详情
资源评论
收起资源包目录
MP3.zip (63个子文件)
mp3enc
machine.h 4KB
newmdct.h 993B
fft.h 1KB
set_get.h 3KB
encoder.c 18KB
version.c 7KB
reservoir.h 1KB
quantize.h 2KB
gain_analysis.c 20KB
bitstream.h 2KB
VbrTag.h 3KB
vbrquantize.c 46KB
set_get.c 53KB
quantize_pvt.c 33KB
quantize_pvt.h 4KB
psymodel.h 2KB
vbrquantize.h 1KB
takehiro.c 37KB
lameerror.h 637B
lame-analysis.h 3KB
lame.c 83KB
util.c 25KB
encoder.h 4KB
bitstream.c 35KB
config.h 829B
lame.h 50KB
tables.c 21KB
tables.h 2KB
util.h 21KB
gain_analysis.h 4KB
id3tag.c 52KB
VbrTag.c 31KB
version.h 2KB
id3tag.h 2KB
newmdct.c 36KB
l3side.h 2KB
presets.c 15KB
fft.c 10KB
lame_global_flags.h 8KB
quantize.c 64KB
psymodel.c 69KB
reservoir.c 10KB
Android.mk 1003B
mp3dec
tabinit.c 6KB
common.c 10KB
mpglib.h 3KB
l2tables.h 12KB
decode_i386.h 1KB
layer3.h 1KB
decode_i386.c 10KB
tabinit.h 1KB
common.h 1KB
interface.h 2KB
mpg123.h 4KB
huffman.h 17KB
layer2.h 1KB
layer1.c 7KB
layer2.c 13KB
layer1.h 1KB
dct64_i386.c 12KB
dct64_i386.h 1021B
interface.c 21KB
layer3.c 63KB
共 63 条
- 1
资源评论
航行在蓝天的蚂蚱
- 粉丝: 111
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功