没事,研究了一下用mpg123库进行mp3解码,呵呵,成功了,生成的wav正常播放。
基于0.59r版的。
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include "mpg123.h"
#include "mpglib.h"
char buf[16384];
struct mpstr mp;
int main(int argc, char **argv)
{
int size;
char out[8192];
int len,ret;
FILE *fin, *fout;
DWORD dsize1 = 37555192, dsize2 = 16;
WAVEFORMATEX waveform;
waveform.wFormatTag
=WAVE_FORMAT_PCM;
waveform.nChannels
=2;
waveform.nSamplesPerSec =44100;
waveform.nAvgBytesPerSec=44100*2;
waveform.nBlockAlign =16*2/8;
waveform.wBitsPerSample =16;
waveform.cbSize
=0;
fin = fopen(argv[1], "rb");
fout = fopen(argv[2], "wb");
if(!fin || !fout)
{
printf("error file create or open!\n");
return 1;
}
fwrite("RIFF", 1, 4, fout);
fwrite(&dsize1, 1, 4, fout);
fwrite("WAVE", 1, 4, fout);
fwrite("fmt ", 1, 4, fout);
fwrite(&dsize2, 1, 4, fout);
fwrite(&waveform.wFormatTag, 1, 2, fout);
fwrite(&waveform.nChannels, 1, 2, fout);
fwrite(&waveform.nSamplesPerSec, 1, 4, fout);
fwrite(&waveform.nAvgBytesPerSec, 1, 4, fout);
fwrite(&waveform.nBlockAlign, 1, 2, fout);
fwrite(&waveform.wBitsPerSample, 1, 2, fout);
fwrite("data", 1, 4, fout);
dsize1 += 8;
fwrite(&dsize1, 1, 4, fout);
InitMP3(&mp);
while(1) {
len = fread(buf,1,16384, fin); //first must be 1,else decode err!
if(len <= 0)
break;
ret = decodeMP3(&mp,buf,len,out,8192,&size);
while(ret == MP3_OK) {
fwrite(out, 1, size,fout);
ret = decodeMP3(&mp,NULL,0,out,8192,&size);
}
}
fclose(fin);
fclose(fout);
return 0;
}