unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MMsystem;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function mmioFOURCC(ch1,ch2,ch3,ch4:Char)
word;
var
Tem
word;
begin
Result:=Dword(ch1);
Tem:=Dword(ch2);
Tem:=Tem Shl 8;
Result:=Result+Tem;
Tem:=Dword(ch3);
Tem:=Tem Shl 16;
Result:=Result+Tem;
Tem:=Dword(ch4);
Tem:=Tem Shl 24;
Result:=Result+Tem;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Hmio:HMMIO;
mmckinfoParent:TMMCKINFO;
mmckinfoSubChunk:TMMCKINFO;
dwFmtSize
WORD;
DWResult
WORD;
hFormat:Thandle;
pFormat
WAVEFORMATEX;
dwDataSize
WORD;
wBlockSize:WORD;
lpData
char;//Thandle;
FWaveOut:HWAVEOUT;
lpWaveHeader
wavehdr;
begin
Hmio:=mmioOpen('d:/Fang.wav',nil,MMIO_READ+MMIO_ALLOCBUF);
if HMIO=0 then
begin
ShowMessage('打开音频文件出错!');
end;
mmckinfoParent.fccType:=mmioFOURCC('W','A','V','E');
if(mmioDescend(HMIO,@mmckinfoParent,nil,MMIO_FINDRIFF)<>MMSYSERR_NOERROR) then
begin
ShowMessage('打开音频文件出错!MMiodescend');
end;
mmckinfoSubChunk.ckid:=mmioFOURCC('f','m','t',' ');
if(mmioDescend(HMIO,@mmckinfoSubChunk,@mmckinfoParent,MMIO_FINDCHUNK)<>MMSYSERR_NOERROR) then
begin
ShowMessage('打开音频文件出错!MMiodescend');
end;
dwFmtSize:=mmckinfoSubChunk.cksize;
hFormat:=LocalAlloc(LMEM_MOVEABLE,LOWORD(dwFmtSize));
if(hFormat=0) then
begin
ShowMessage('申请内存出错!');
end;
pFormat:=LocalLock(hFormat);
if (pFormat=nil) then
begin
ShowMessage('取内存首址出错!');
end;
if(mmioRead(Hmio,Pchar(pFormat),dwFmtSize)<>dwFmtSize) then
begin
ShowMessage('取内存首址出错!');
end;
if (waveOutOpen(@FWaveOut,WAVE_MAPPER,pFormat,0,0,WAVE_FORMAT_QUERY)<>MMSYSERR_NOERROR ) then
begin
ShowMessage('不支持此格式!');
end;
mmioAscend(hmio,@mmckinfoSubchunk,0);
mmckinfosubchunk.ckid:=mmiofourcc('d','a','t','a');
if mmioDescend(hmio,@mmckinfoSubchunk,@mmckinfoParent,MMIO_FINDCHUNK)<>MMSYSERR_NOERROR then
begin
ShowMessage('找不到数据块!');
end;
dwDataSize:=mmckinfoSubChunk.cksize;
if (dwDataSize=0) then
begin
ShowMessage('找不到数据块!');
end;
// pformat.nChannels:=0;
showmessage(inttostr(pformat.nChannels));
showmessage(inttostr(pformat.wFormatTag));
if (waveOutOpen(@FWaveOut,WAVE_MAPPER,pFormat,0,0,0)<>MMSYSERR_NOERROR ) then
begin
ShowMessage('打开波形出错!');
end;
wBlockSize:=pFormat.nBlockAlign;
LocalUnlock(hFormat);
LocalFree(hFormat);
lpData:=GlobalAllocPtr(GMEM_MOVEABLE+GMEM_SHARE,dwDataSize);
if (lpData=nil) then
begin
showmessage('分配内存出错11');
end;
if mmioRead(hmio,lpData,dwDataSize)<>dwDataSize then
begin
showmessage('读数据出错!');
end;
mmioClose(hmio,0);
lpWaveHeader:=GlobalAllocPtr(GMEM_MOVEABLE+GMEM_SHARE,SizeOf(WaveHdr));
if (lpWaveHeader=nil) then
begin
showmessage('分配内存出错!');
end;
lpWaveHeader.lpData:=lpdata;
lpWaveHeader.dwBufferLength:=dwDataSize;
lpWaveHeader.dwFlags:=0;
lpWaveHeader.dwLoops:=0;
if(WaveOutPrepareHeader(Fwaveout,lpWaveHeader,SizeOf(WaveHdr))<>MMSYSERR_NOERROR )then
begin
showmessage('不能定位头');
end;
dwresult:=WaveOutWrite(fwaveout,lpWaveHeader,sizeof(wavehdr));
end;
end.
播放wav的代码,改写的,有