gpt4 book ai didi

lame - 使用 LAME 时开头的点击声音

转载 作者:行者123 更新时间:2023-12-04 14:03:22 25 4
gpt4 key购买 nike

我正在使用 LAME 将 WAV 文件(从音频 CD 中提取)转换为 MP3。转换结果很好,只是在文件的开头有一个“咔哒”声。在歌曲本身之前点击几乎需要 0.5 秒。

char *input_file = argv[1];
char *output_file = argv[2];

FILE *pcm = fopen(input_file, "rb");
FILE *mp3 = fopen(output_file, "wb+");

size_t nread;
int ret, nwrite;

const int PCM_SIZE = 1152;
const int MP3_SIZE = 1152;

short pcm_buffer[PCM_SIZE * 2];
unsigned char mp3_buffer[MP3_SIZE];

lame_t lame = lame_init();

// Can not put these lines at the end of conversion
id3tag_set_title(lame, "Still reminds me");
id3tag_set_artist(lame, "Anggun");

lame_set_VBR(lame, vbr_mt);
lame_set_VBR_quality(lame, 2);

ret = lame_init_params(lame);

do {
nread = fread(pcm_buffer, sizeof(short), PCM_SIZE * 2, pcm);

if (nread != 0) {
// Is this the cause of the single click?
int nsamples = nread / 2;
short buffer_l[nsamples];
short buffer_r[nsamples];

int j = 0;
int i = 0;
for (i = 0; i < nsamples; i++) {
buffer_l[i] = pcm_buffer[j++];
buffer_r[i] = pcm_buffer[j++];

}

nwrite = lame_encode_buffer(lame, buffer_l, buffer_r, nsamples,
mp3_buffer, MP3_SIZE);

} else {
nwrite = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);

}

fwrite(mp3_buffer, nwrite, 1, mp3);
} while (nread != 0);


lame_close(lame);

fclose(mp3);
fclose(pcm);

这是怎么回事?我在这里想念什么?

最佳答案

不确定您是否仍在寻找 Dave L 以外的答案,但咔哒声来自 LAME 意外编码音频文件中的标题。根据您生成的 WAV 文件, header 可能是 44 个字节。我在转换我录制的 PCM 文件时遇到了类似的问题,但在我的情况下,这些 header 是 4096 字节。如果它是一个真正的 wav 文件(因此具有 44 字节的 header ),只需使用

fseek(pcm,44,0);

打开文件后立即跳过标题内容。我还建议在您的 WAV 文件之一上使用十六进制编辑器来验证标题的大小。

一旦我跳过那个(同样,我的标题是 4096b),点击噪音就消失了。

关于lame - 使用 LAME 时开头的点击声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12346314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com