procedure TForm1.FormShow(Sender: TObject);
var
hRet: HRESULT;
BufDesc: TDSBufferDesc_DX7;
Format: TWaveFormatEx;
PCM: TWaveFormatEx;
begin
hRet := DirectSoundCreate(nil, DXSound, nil);
if hRet <> DS_OK then
begin
ErrorOut(hRet, 'DirectSoundCreate');
Close;
end;
hRet := DXsound.SetCooperativeLevel(Handle, DSSCL_Priority);
if hRet <> DS_OK then
begin
ErrorOut(hRet, 'SetCooperativeLevel');
Close;
end;
FillChar(BufDesc, SizeOf(TDSBufferDesc), 0);
BufDesc.dwSize := SizeOf(TDSBufferDesc);
BufDesc.dwFlags := DSBCAPS_PRIMARYBUFFER;
BufDesc.dwBufferBytes := 0;
BufDesc.lpwfxFormat := nil;
hRet := DXSound.CreateSoundBuffer(BufDesc, DXSPBuffer, nil);
if hRet <> DS_OK then
begin
ErrorOut(hRet, 'CreateSoundBuffer');
Close;
end;
FillChar(PCM, SizeOf(TWaveFormatEx), 0);
with PCMdo
begin
wFormatTag := WAVE_FORMAT_PCM;
nChannels := 2;
nSamplesPerSec := 44100;
nBlockAlign := 4;
wBitsPerSample := 16;
cbSize := 0;
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
nBlockAlign := (wBitsPerSample div 8) * nChannels;
// = 4
end;
hRet := DXSPBuffer.SetFormat(PCM);
if hRet <> DS_OK then
begin
ErrorOut(hRet, 'SetFormat');
Close;
end;
if not CreateSecondaryBufferFromWav(DXSound, DXSSBuffer1, WaveFile) then
showmessage('error');
if not CreateSecondaryBufferFromWav(DXSound, DXSSBuffer2, WaveFile) then
showmessage('error');
end;