/* -*- mode: C; mode: fold -*- */
/*
* LAME MP3 encoding engine
*
* Copyright (c) 1999-2000 Mark Taylor
* Copyright (c) 2000-2005 Takehiro Tominaga
* Copyright (c) 2000-2011 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.365 2011/10/18 21:51:20 robert Exp $ */
#pragma warning(disable:4996)
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#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;
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 <= 15960
没有合适的资源?快使用搜索试试~ 我知道了~
vs2015(c)+lametomp3.rar
共88个文件
h:23个
obj:22个
c:20个
需积分: 10 4 下载量 51 浏览量
2020-11-20
08:52:17
上传
评论
收藏 7.89MB RAR 举报
温馨提示
vs2015 编译环境 ,c语言 调用三方的 lame.h , pcm 转化mp3 文件的demo。里面包含 pcm 与对应的 MP3 文件,测试通过。
资源详情
资源评论
资源推荐
收起资源包目录
vs2015(c)+lametomp3.rar (88个子文件)
Debug
ConsoleApplication2.ilk 648KB
ConsoleApplication2.exe 381KB
ConsoleApplication2.pdb 1.38MB
.vs
ConsoleApplication2
v14
.suo 31KB
ConsoleApplication2
ConsoleApplication2.vcxproj 10KB
Debug
id3tag.obj 123KB
vc140.pdb 236KB
psymodel.obj 118KB
lame.obj 122KB
quantize.obj 92KB
vc140.idb 731KB
ConsoleApplication2.log 430B
tables.obj 24KB
gain_analysis.obj 29KB
presets.obj 43KB
VbrTag.obj 44KB
quantize_pvt.obj 57KB
lame_version.obj 21KB
takehiro.obj 60KB
main.obj 3KB
encoder.obj 32KB
set_get.obj 142KB
pcm2mp3.obj 24KB
fft.obj 26KB
mpglib_interface.obj 2KB
bitstream.obj 69KB
reservoir.obj 22KB
ConsoleA.FAE790BB.tlog
CL.read.1.tlog 454KB
link.read.1.tlog 10KB
ConsoleApplication2.lastbuildstate 216B
link.write.1.tlog 4KB
CL.write.1.tlog 17KB
link.command.1.tlog 6KB
CL.command.1.tlog 17KB
vbrquantize.obj 77KB
newmdct.obj 44KB
util.obj 56KB
0001.mp3 50KB
pcm2mp3.cpp 3KB
libmp3lame
machine.h 4KB
newmdct.h 993B
fft.h 1KB
set_get.h 3KB
encoder.c 18KB
reservoir.h 1KB
quantize.h 2KB
gain_analysis.c 19KB
bitstream.h 2KB
VbrTag.h 3KB
vbrquantize.c 46KB
lame.def 6KB
set_get.c 50KB
vector
lame_intrin.h 1013B
quantize_pvt.c 33KB
quantize_pvt.h 4KB
psymodel.h 2KB
vbrquantize.h 1KB
mpglib_interface.c 14KB
takehiro.c 37KB
lameerror.h 637B
lame-analysis.h 3KB
lame.c 81KB
util.c 25KB
lame_version.c 7KB
encoder.h 4KB
bitstream.c 35KB
lame.h 48KB
tables.c 21KB
tables.h 2KB
util.h 22KB
gain_analysis.h 4KB
id3tag.c 51KB
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
ConsoleApplication2.vcxproj.filters 5KB
0001.dat 558KB
ConsoleApplication2.vcxproj.user 222B
ConsoleApplication2.sln 1KB
ConsoleApplication2.VC.db 25.99MB
共 88 条
- 1
2004v2004
- 粉丝: 65
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0