Skip to content

A lot of noise #128

@Dingtaiqi

Description

@Dingtaiqi

I don't know why the converted pcm sounds so noisy

`
#include <stdio.h>
#include <stdlib.h>
#define MINIMP3_IMPLEMENTATION
#define AUDIO_BUF_SIZE MINIMP3_MAX_SAMPLES_PER_FRAME
#include "minimp3.h"

int main() {
size_t samples;
size_t cur_pos = 0;

unsigned char *input_buf = NULL;
/*unsigned char *input_buf; - input byte stream*/

int data_size = 0;
//打开MP3文件
FILE* file=fopen("uy.mp3", "r");
FILE* fout=fopen("uy.pcm", "a");

//获取MP3文件长度
fseek(file, 0, SEEK_END);
data_size = (int)ftell(file);

//读取整个MP3文件
fseek(file, 0, SEEK_SET);
input_buf = malloc(data_size);
fread(input_buf, 1, data_size, file);

//初始化minimp3的解码器结构
static mp3dec_t mp3d;
mp3dec_init(&mp3d);

//定义mp3dec_frame_info_t
mp3dec_frame_info_t info;
short pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
long long mp3len = 0;

//逐帧解码并且播放MP3
samples = mp3dec_decode_frame(&mp3d, input_buf, data_size, pcm, &info);
while(samples) {
printf("%d%d\r\n",&pcm, samples);
fwrite(pcm,sizeof(pcm),1,fout);
//fputs(pcm,fout);
mp3len += info.frame_bytes;
samples = mp3dec_decode_frame(&mp3d, input_buf + mp3len, data_size - mp3len, pcm, &info);
}

free(input_buf);

return 0;

}`
Audio with https://music.163.com/song/media/outer/url?id=2155422573.mp3
There is another question, how many “samples” should be when decoding, I have always been 1152

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions