Results 1 to 2 of 2

Thread: Doom SND Files and DirectSound

  1. #1

    Doom SND Files and DirectSound

    Hi, I've been hammering away at a way to get .SND files from Doom to play using DirectX as part of a project I'm doing for "fun" (masochism) using a little bit of code from Delphi Doom (mostly the sampling), and a little code from another article that I've seen floating around here, but I'm having no success so far. The following code does not produce any DirectX errors (other than a lost buffer, which is restored), but it doesn't produce any sound either. Also, when I close the application, it crashes. Anyway, here's what I have in a test form's Create event:

    [pascal]procedure TForm1.FormCreate(Sender: TObject);
    var
    BufferDesc: DSBUFFERDESC;
    AudioPtr1,AudioPtr2,Temp: Pointer;
    AudioBytes1,AudioBytes2: DWORD;
    SNDSound: PChar;
    FName: TFileStream;
    DataSize: Integer;
    begin
    FName := TFileStream.Create('d:\DSSHOTGN.snd',fmOpenRead);
    DataSize := FName.Size - 8;
    FName.Seek(8,soFromBeginning); //8-byte header

    GetMem(SNDSound,DataSize);
    FName.Read(SNDSound^, DataSize);
    FName.Free;
    FreeMem(SNDSound,DataSize);

    if DirectSoundCreate(nil, DirectSound, nil) <> DS_OK then
    begin
    DirectSound := nil;
    ShowMessage('Could not create DS.');
    exit;
    end;

    if DirectSound.SetCooperativeLevel(Self.Handle, DSSCL_PRIORITY) <> DS_OK then ShowMessage('Cannot set coop.');

    PCMFormat.wFormatTag := WAVE_FORMAT_PCM;
    PCMFormat.nChannels := 1;
    PCMFormat.nSamplesPerSec := 11025;
    PCMFormat.cbSize := 0;
    PCMFormat.nBlockAlign := 1;
    PCMFormat.nAvgBytesPerSec := 11025;
    PCMFormat.wBitsPerSample := 8;

    ZeroMemory(@BufferDesc, SizeOf(DSBUFFERDESC));
    BufferDesc.dwSize := SizeOf(DSBUFFERDESC);
    BufferDesc.dwFlags := DSBCAPS_PRIMARYBUFFER;
    BufferDesc.dwBufferBytes := 0;
    BufferDesc.lpwfxFormat := nil;

    if DirectSound.CreateSoundBuffer(BufferDesc, DirectSoundBuffer, nil) <> DS_OK then
    begin
    ShowMessage('Cannot create sound buffer.');
    DirectSoundBuffer := nil;
    end
    else
    begin
    if DirectSoundBuffer.SetFormat(PCMFormat) <> DS_OK then ShowMessage('Cannot set format.');
    Temp := @SNDSound;
    if DirectSoundBuffer.Lock(0,Length(SNDSound),AudioPtr 1,AudioBytes1,AudioPtr2,AudioBytes2,0) = DSERR_BUFFERLOST then
    begin
    DirectSoundBuffer.Restore;
    if DirectSoundBuffer.Lock(0,DataSize,AudioPtr1,AudioB ytes1,AudioPtr2,AudioBytes2,0) <> DS_OK then ShowMessage('Cannot lock.');
    Move(Temp^,AudioPtr1^,AudioBytes1);
    if DirectSoundBuffer.Unlock(AudioPtr1,AudioBytes1,Aud ioPtr2,AudioBytes2) <> DS_OK then ShowMessage('Not unlocking.');
    end;
    if DirectSoundBuffer.Play(0, 0, 0) <> DS_OK then ShowMessage('Cannot play.');
    end;

    PCMFormat.wFormatTag := WAVE_FORMAT_PCM;
    PCMFormat.nChannels := 1;
    PCMFormat.nSamplesPerSec := 11025;
    PCMFormat.nBlockAlign := 1;
    PCMFormat.nAvgBytesPerSec := 11025;
    PCMFormat.wBitsPerSample := 8;
    PCMFormat.cbSize := 0;
    end;[/pascal]

    Can anyone offer any insight as to what I'm doing wrong here?
    Thanks.

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Doom SND Files and DirectSound

    Hey, nice!

    People here that might be able to help you best may be, BeRo [size=9px](maker of his own BeRo Tracker, made with Delphi/Free Pascal)[/size], Clootie [size=9px](DirectX expert extrodinate)[/size] and Jimmy Valavanis [size=9px](known for all his Total Conversion series of id Software game engines)[/size].
    Jason McMillen
    Pascal Game Development
    Co-Founder





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •