// open file
fpIn := FileOpen(MP3FileName, fmOpenRead);
if (fpIn = 0) then Exit;
// find out how big the decompressed buffer will be
rawbufsize := 0;
acmStreamSize(g_mp3stream, MP3_BLOCK_SIZE, rawbufsize, ACM_STREAMSIZEF_SOURCE);
// allocate our I/O buffers
mp3Buf := PByte(LocalAlloc(LPTR, MP3_BLOCK_SIZE));
rawbuf := pByte(LocalAlloc(LPTR, rawbufsize));
// prepare the decoder
ZeroMemory(@mp3streamHead, sizeof(TACMSTREAMHEADER));
mp3streamHead.cbStruct := sizeof(TACMSTREAMHEADER);
mp3streamHead.pbSrc := mp3buf;
mp3streamHead.cbSrcLength := MP3_BLOCK_SIZE;
mp3streamHead.pbDst := rawbuf;
mp3streamHead.cbDstLength := rawbufsize;
acmStreamPrepareHeader(g_mp3stream, mp3streamHead, 0);
// let''s dump this data off to disk (for debug checking!)
RawFileName := ChangeFileExt(MP3FileName, ''.raw'');
fpOut := FileCreate(RawFileName);
if (fpOut = 0) then Exit;
FileSeek(fpIn, 0, 0);
while True do
begin
//suck in some MP3 data
Count := FileRead(fpIn, mp3buf^, MP3_BLOCK_SIZE);
if (Count <> MP3_BLOCK_SIZE) then break;
// convert the data
mmr := acmStreamConvert(g_mp3stream, mp3streamHead, ACM_STREAMCONVERTF_BLOCKALIGN);
if mmr <> 0 then
begin
MessageBox(0, ''输入参数错误。请检查你的输入参数。'', ''系统提示: '', 64);
Exit;
end;
//write the decoded PCM to disk
Count := FileWrite(fpOut, rawbuf^, mp3streamHead.cbDstLengthUsed);
if Count <> mp3streamHead.cbDstLengthUsed then
begin
MessageBox(0, ''输入参数错误。请检查你的输入参数。'', ''系统提示: '', 64);
Exit;
end;
end; ;
// clean up after yourself like a good little boy
FileClose(fpIn);
FileClose(fpOut);
acmStreamUnprepareHeader(g_mp3stream, mp3streamHead, 0);
LocalFree(LongInt(rawbuf));
LocalFree(LongInt(mp3buf));
acmStreamClose(g_mp3stream, 0);
Result := True;
end;
ConverMP3ToRaw函数是将MP3转换成RAW(RIFF格式),添加WAV文件头就是WAV文件了。