Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Anyone?

  1. #1

    Anyone?

    Anyone know what they are doing with directSound? I could use some help on my OmegaSound component. I'm having trouble knowing how big to make the sound buffer, I need to know how long the wave file is, but I have no clue on how to find this out. Anyone know? Thanks.
    Bobby Baker
    <br />Delphi Sanctuary
    <br />www.delphisanctuary.com

  2. #2

    Anyone?

    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
    Best Regards
    <br />
    <br />Jarrod Davis,
    <br />Jarrod Davis Software
    <br />http://www.jarroddavis.com

  3. #3

    Hi

    Hi! Thanks man, your a life saver. It works perfectly now. I really appreciate it, I can finally release the working sound component now
    Bobby Baker
    <br />Delphi Sanctuary
    <br />www.delphisanctuary.com

  4. #4

    Anyone?

    Coolness! Glad to hear its working.
    Best Regards
    <br />
    <br />Jarrod Davis,
    <br />Jarrod Davis Software
    <br />http://www.jarroddavis.com

  5. #5

    a little proposal

    If you're working with the wav format then try to work with the wav API. (MMIO just easier, faster and better ).
    [pascal]
    function LoadWaveFromFile(FFile:string):Boolean;
    var HIO :HMMIO;
    parent,
    child1,
    child2 :MMCKINFO;
    wavefmt:TWAVEFORMATEX;
    bufdesc:TDSBUFFERDESC;
    length1,
    length2:Cardinal;
    write1,
    write2 ointer;
    dummy :IDirectSoundBuffer;
    begin
    result:=false;
    HIO:=mmioopen(@FFile[1],nil,MMIO_READ or MMIO_ALLOCBUF);
    if HIO>0 then
    begin
    parent.fccType:=mmioStringToFourCC('wave',MMIO_TOU PPER);
    child1.ckid:=mmioStringToFourCC('fmt ',0);
    child2.ckid:=mmioStringToFourCC('data',0);
    if mmioDescend(HIO,@parent,nil,MMIO_FINDRIFF)=0 then
    if mmioDescend(HIO,@child1,@parent,MMIO_FINDCHUNK)=0 then
    if mmioread(HIO,@wavefmt,child1.cksize)=child1.cksize then
    if mmioDescend(HIO,@child2,@parent,MMIO_FINDCHUNK)=0 then
    begin
    FillChar(bufdesc,sizeof(TDSBUFFERDESC),0);
    bufdesc.dwSize:=sizeof(TDSBUFFERDESC);
    bufdesc.dwFlags:=DSBCAPS_CTRLDEFAULT;
    bufdesc.dwBufferBytes:=child2.cksize;
    bufdesc.lpwfxFormat:=@wavefmt;
    if dsound.CreateSoundBuffer(bufdesc,dummy,nil)=DS_OK then
    begin
    DSBuffer:=dummy as IDirectSoundBuffer8;
    dummy:=nil;
    if DSBuffer.Lock(0,child2.cksize,write1,length1,write 2,length2,DSBLOCK_FROMWRITECURSOR)=DS_OK then
    begin
    if (write1<>nil) then
    mmioRead(HIO,PChar(write1),length1);
    DSBuffer.Unlock(write1,length1,write2,length2);
    end;
    end;
    end;
    MMIOClose(HIO,MMIO_FHOPEN);
    result:=true;
    end;

    [/pascal]


    Tutorial, source & exe on my site
    DirectX Stuff www.jadds.de

  6. #6

    Anyone?

    But.. can you also use the winmm routine to assist in loading that wav from a resource file. My engine uses standard zip files. All game assests can be loaded from a zip archive. It would be nice to let winmm do the loading as it would be able to handle the compressed WAVs for me.
    Best Regards
    <br />
    <br />Jarrod Davis,
    <br />Jarrod Davis Software
    <br />http://www.jarroddavis.com

  7. #7

    Anyone?

    Hi, jdsgames, do you know why setting the volume wouldnt work for me? I set the volume to -10000 just to test (Should be silent) but it doesnt change it at all. I did set the control volume flag when creating it, I dont know what I could be doing wrong, any ideas? Thanks.
    Bobby Baker
    <br />Delphi Sanctuary
    <br />www.delphisanctuary.com

  8. #8

    Anyone?

    Hi Bobby,

    Check your email, I'm sending you my whole GVAudio.pas unit. It has sample and mp3 playback code. You can control the volume, master volume and many other audio related tasks. I had problems with this at first too, but for me it turned out to be a flag that was not set (control vol flag). Check out that code and let me know. If you manage to improve on it at all, but sure to send me the updates. Thanks.
    Best Regards
    <br />
    <br />Jarrod Davis,
    <br />Jarrod Davis Software
    <br />http://www.jarroddavis.com

  9. #9

    Anyone?

    But.. can you also use the winmm routine to assist in loading that wav from a resource file. My engine uses standard zip files. All game assests can be loaded from a zip archive. I would be nice to let winmm do the loading as it would be able to handle the compressed WAVs for me.
    No. If you want to load your wave from a resource file via Win32 MMApi you must first buffer the resource via TResourceStream.
    http://www.bridgespublishing.com/art..._resources.htm
    You must decompress your wav resource by yourself . Sorry but it is only a low level wav interface.
    sincerely Jan
    DirectX Stuff www.jadds.de

  10. #10

    Anyone?

    Can i have the GVAudio.pas too. I'll also take a look on it
    DirectX Stuff www.jadds.de

Page 1 of 2 12 LastLast

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
  •