DirectSound播放声音协助除错求助(已解决) ( 积分: 100 )

  • 主题发起人 主题发起人 SonicX
  • 开始时间 开始时间
S

SonicX

Unregistered / Unconfirmed
GUEST, unregistred user!
全程没有报错,就是没声音,还请高手协助除错
var
DSound :IDirectSound8;
//DirectSound对象
DSoundBuf :IDirectSoundBuffer;
//SoundBuffer缓冲
snd_buffer :PByte;
//wav数据空间
parent,child :TMMCKInfo;
//MMCKInfo
hwav :HMMIO;
//wav句柄
DSBufferDesc :TDSBufferDesc;
//SoundBuffer结构
wfmtx :TWaveFormatEx;
//wav结构
pAudio1,
pAudio2 :PByte;
//SoundBuffer第1,2指针
pAudioLength1,
pAudioLength2:DWORD;
//SoundBuffer第1,2指针缓冲大小
tmpP :PByte;

begin

fillchar(parent, sizeof(parent), 0);
child:=parent;
hwav:=mmioOpen('c:/01.wav', nil, MMIO_READ or MMIO_ALLOCBUF);
if hwav=0 then
exit;
//查询RIFF
parent.fccType :=MAKEFOURCC('W','A','V','E');
if not (mmioDescend(hwav, @parent, nil, MMIO_FINDRIFF)=MMSYSERR_NOERROR) then
begin

mmioClose(hwav, 0);
exit;
end;

//查询fmt
child.ckid:=MAKEFOURCC('f','m','t',#0);
if not (mmioDescend(hwav, @child, @parent, 0)=MMSYSERR_NOERROR) then
begin

mmioClose(hwav, 0);
exit;
end;

//读
mmioRead(hwav, @wfmtx, sizeof(wfmtx));
if not (wfmtx.wFormatTag = WAVE_FORMAT_PCM) then
begin

mmioClose(hwav, 0);
exit;
end;

//回到fmt
mmioAscend(hwav, @child, 0);
//确定data
child.ckid:=MAKEFOURCC('d','a','t','a');
if not (mmioDescend(hwav,@child, @parent,MMIO_FINDCHUNK)=MMSYSERR_NOERROR) then
begin

mmioClose(hwav, 0);
exit;
end;

//分配空间
snd_buffer:=AllocMem(child.cksize);
//读WAV
mmioRead(hwav, @snd_buffer, child.cksize);
//关闭
mmioClose(hwav, 0);
//////////////////////////读WAV文件完毕/////////////////////
//建立DSound
if not (DirectSoundCreate8(nil, DSound, nil)=DD_OK) then
exit;
//协作等级
if not (DSound.SetCooperativeLevel(MainHandle, DSSCL_NORMAL)=DD_OK) then
exit;
//SoundBuffer结构
Fillchar(DSBufferDesc, Sizeof(DSBufferDesc),0);
DSBufferDesc.dwSize :=Sizeof(DSBufferDesc);
DSBufferDesc.dwFlags :=DSBCAPS_CTRLPAN or DSBCAPS_CTRLVOLUME or DSBCAPS_CTRLFREQUENCY or DSBCAPS_STATIC or DSBCAPS_LOCSOFTWARE;
DSBufferDesc.dwBufferBytes:=child.cksize;
DSBufferDesc.lpwfxFormat :=@wfmtx;
//建立SoundBuffer
if not (DSound.CreateSoundBuffer(DSBufferDesc, DSoundBuf, nil)=DD_OK) then
exit;
//锁定内存
if not (DSoundBuf.Lock(0, child.cksize, @pAudio1, @pAudioLength1, @pAudio2, @pAudioLength2, DSBLOCK_FROMWRITECURSOR)=DD_OK) then
exit;
CopyMemory(pAudio1, snd_buffer, pAudioLength1);
//内存复制
tmpP:=snd_buffer;
Inc(tmpP, pAudioLength1);
//指针偏移
CopyMemory(pAudio2, tmpP, pAudioLength2);
//内存复制
//解锁内存
if not (DSoundBuf.Unlock(pAudio1, pAudioLength1, pAudio2, pAudioLength2)=DD_OK) then
exit;
//播放
DSoundBuf.Play(0,0,0);
end;
 
就当散分了
后面半段代码改成
if not (DSoundBuf.Lock(0, child.cksize, @pAudio1, @pAudioLength1, @pAudio2, @pAudioLength2, DSBLOCK_FROMWRITECURSOR)=DD_OK) then
exit;
mmioRead(hwav, Pchar(pAudio1), pAudioLength1);
mmioRead(hwav, Pchar(pAudio2), pAudioLength2);
if not (DSoundBuf.Unlock(pAudio1, pAudioLength1, pAudio2, pAudioLength2)=DD_OK) then
exit;
//播放
DSoundBuf.Play(0,0,0);
 
这不是DSPACK里带的DSoundRender filter的源码吗?
 
源码也没人来解决,汗。。。
现在用DirectMusic了,呵呵
 
后退
顶部