Hi,

Maybe this can help. Here is some code that I am using in our GameVision engine. We are currently working on GV 2.0 and this will be the new wave file loading code. GV is currently in development so the code is not 100% tested yet. So, anything you fix/enhance, please send to me, thanks. It will prob crash if you try and load a compressed wave file:
[pascal]
function TGVAudio.WriteDataToBuffer(lpdsb: IDirectSoundBuffer; OffSet: DWord;
var SoundData; SoundBytes: DWord): Boolean;
var
AudioPtr1 : Pointer;
AudioPtr2 : Pointer;
AudioBytes1: DWord;
AudioBytes2: DWord;
h : HResult;
Temp : Pointer;
begin
Result:=True;
H:=lpdsb.Lock(OffSet, SoundBytes, AudioPtr1, AudioBytes1,
AudioPtr2, AudioBytes2, 0);
if H = DSERR_BUFFERLOST then
begin
lpdsb.Restore;
if lpdsb.Lock(OffSet, SoundBytes, AudioPtr1, AudioBytes1,
AudioPtr2, AudioBytes2, 0) <> DS_OK then Result:=False;
end else if H <> DS_OK then Result:=False;
Temp:=@SoundData;
Move(Temp^, AudioPtr1^, AudioBytes1);
if AudioPtr2 <> nil then
begin
Temp:=@SoundData;
Inc(Integer(Temp), AudioBytes1);
Move(Temp^, AudioPtr2^, AudioBytes2);
end;
if lpdsb.UnLock(AudioPtr1, AudioBytes1, AudioPtr2, AudioBytes2) <> DS_OK
then Result:=False;
end;

function TGVAudio.CreateSecondaryBufferFromWav(var lpdsb : IDirectSoundBuffer;
Name: string) : Boolean;
var Data : PChar;
FName : TFileStream;
dsbdesc : TDSBUFFERDESC;
PCM : TWaveFormatEx;
FWord : Word;
FDWord : DWord;
Chunk : String[4];
Pos : Integer;
DataSize : DWord;
begin
Result:=True;
FName:=TFileStream.Create(Name, fmOpenRead);
FillChar(dsbdesc, SizeOf(TDSBUFFERDESC), 0);
FillChar(PCM, SizeOf(TWaveFormatEx), 0);

with PCM do
begin
wFormatTag:=WAVE_FORMAT_PCM;
FName.Seek($16, soFromBeginning);
FName.Read(FWord, SizeOf(Word));
nChannels:=FWord;
FName.Read(FDWord, SizeOf(DWord));
nSamplesPerSec:=FDWord;
FName.Read(FDWord, SizeOf(DWord));
nAvgBytesPerSec:=FDWord;
FName.Read(FWord, SizeOf(Word));
nBlockAlign:=FWord;
FName.Read(FWord, SizeOf(Word));
wBitsPerSample:=FWord;
cbSize:=0;
end;

Pos:=$22;
SetLength(Chunk, 4);
repeat
FName.Seek(Pos, soFromBeginning);
FName.Read(Chunk[1], 4);
Inc(Pos);
until Chunk = 'data';
FName.Seek(Pos + 3, soFromBeginning);
FName.Read(DataSize, SizeOf(DWord));
GetMem(Data, DataSize);
FName.Read(Data^, DataSize);

dsbdesc.dwSize:=SizeOf(TDSBUFFERDESC);
dsbdesc.dwFlags:=DSBCAPS_GETCURRENTPOSITION2 or
//DSBCAPS_GLOBALFOCUS or
DSBCAPS_CTRLPAN or
DSBCAPS_CTRLVOLUME or
DSBCAPS_LOCSOFTWARE or
DSBCAPS_CTRLPOSITIONNOTIFY;

dsbdesc.dwBufferBytes:=DataSize;
dsbdesc.lpwfxFormat:=@PCM;

FName.Free;

if FDS.CreateSoundBuffer(dsbdesc, lpdsb, nil) <> DS_OK
then Result:=False;

if not WriteDataToBuffer(lpdsb, 0, Data^, DataSize) then Result:=False;
FreeMem(Data, DataSize);
end;
[/pascal]

Best Regards

Jarrod Davis
JDS Games
http://www.jdsgames.com
jdsgames@jdsgames.com