lame mp3 wav文件转mp3 单通道

int read, write;
FILE *pcm = fopen("/Users/liuchan_xin/Desktop/音视频播放与保存例子/ipcamera.wav", "rb");
FILE *mp3 = fopen("/Users/liuchan_xin/Desktop/file.mp3", "wb");

int PCM_SIZE = 640;
int MP3_SIZE = 8192;

short int pcm_buffer[PCM_SIZE];
unsigned char mp3_buffer[MP3_SIZE];

lame_t lame = lame_init();

lame_set_num_channels(lame,1);
lame_set_in_samplerate(lame,8000);
lame_set_brate(lame,8);
lame_set_mode(lame,3);
lame_set_quality(lame,2); /* 2=high 5 = medium 7=low */

lame_init_params(lame);

do {
read = fread(pcm_buffer, sizeof(short int), PCM_SIZE, pcm);

if (read == 0)
write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
else
{
write = lame_encode_buffer(lame,
pcm_buffer, NULL,
read,mp3_buffer,MP3_SIZE);
}

fwrite(mp3_buffer, write, 1, mp3);
} while (read != 0);

NSLog(@"save success");

lame_close(lame);
fclose(mp3);
fclose(pcm);


评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值