Results 1 to 8 of 8

Thread: DirectSound

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    DirectSound

    Where do I go to create a DirectSound file, and how do I use it to play certain audio files in a game?

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: DirectSound

    What do mean by a DirectSound file? DirectSound can play most common audio formats.

    There are a few DirectSound wrapper classes around the Web. Better ones raise an event when a sound has finished playing.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    Re: DirectSound

    Just to clarify, I have retrieved this sample code from another site:

    Code:
    private DS.Device sounddevice;
    private SecondaryBuffer (sound);
    
    using Microsoft.DirectX.DirectSound;
    using DS = Microsoft.DirectX.DirectSound;
    
    private void InitializeSound()
     {
         sounddevice = new DS.Device();
         sounddevice.SetCooperativeLevel(this, CooperativeLevel.Normal);
     
         BufferDescription description = new BufferDescription();
         description.ControlEffects = false;
         (name)sound = new SecondaryBuffer("(soundname).wav", description, sounddevice);
         (name)sound.Play(0, BufferPlayFlags.Default);
     } 
    
     SecondaryBuffer new(name)sound = (name)sound.Clone(sounddevice);
     new(name)sound.Play(0, BufferPlayFlags.Default);
    
     private ArrayList soundlist = new ArrayList();
    
     soundlist.Add(new(name)sound);
    
     private void SoundAffairs()
     {
         if (soundlist.Count > 0)
         {
             for (int i = soundlist.Count - 1; i > -1; i--)
             {
                 SecondaryBuffer currentsound = (SecondaryBuffer)soundlist[i];
                 if (!currentsound.Status.Playing)
                 {
                     currentsound.Dispose();
                     soundlist.RemoveAt(i);
                 }
             }
         }
     }
    Is a sound list similiar to the following (taken from my Press Your Luck game that was semi-created by another person):

    [events]
    # Buzzer sound
    buzz
    # Buzz-in sound
    buzzIn
    # Ding sound
    ding
    # Crowd sound
    crowd
    # Board sound
    board2
    # Pass sound
    passSpin
    # Freeze (during Whammy round)
    freeze
    # Whammy "boing"
    bounce
    # Whammy buzzer (only)
    endWhammy
    # Whammy "boom" (during Whammy round)
    bounce
    # Lose-1-Whammy sound
    loseWhammy
    # Null sound
    empty
    [music]
    # Opening theme
    openTheme1b
    # End Question R1
    QR1end
    # Start Money R1
    MR1start
    # End Money R1
    MR1end
    # Start Question R2
    QR2start
    # End Question R2
    QR2end
    # Start Money R2
    MR2start
    # Win music
    win
    # Start post-game summary
    startSummary
    # Prize music
    prize
    # Closing theme
    endTheme1
    [prompts]
    Press1
    Press2
    Press3

    And do I create an DirectX or ActiveX control file for the DirectSound code?

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: DirectSound

    I guess you could make a ActiveX control but you don't need to. You can interface with DirectSound with pure VB and a reference to DirectX 7 or 8.

    This is the first google hit I got.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    Re: DirectSound

    DirectX control will only allow me to use certain sound quality and other stuff. It will not reference the .wav filename to play it in a form. Unless I overlooked something. What will I reference the sound from if I wish to play it in a form?

    Can someone please upload a sample so I can see more clearly?

  6. #6
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: DirectSound

    DirectSound is a part of DirectX. It gives complete control over volume, pitch, balance, samples per second, bitrate etc. It can play up to 64 sounds simultaneously. The sounds themselves might be in a resource or Dll or on disk and can be of multiple formats.

    This all can be done in VB with a reference to DirectX.

    I'm away from home for the next few days when I get back and if someone does not beat me to it I'll post up an example (which I can test first).

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    Re: DirectSound

    Quote Originally Posted by Milk
    The sounds themselves might be in a resource or Dll or on disk and can be of multiple formats.

    This all can be done in VB with a reference to DirectX.
    Quote Originally Posted by Milk
    I'm away from home for the next few days when I get back and if someone does not beat me to it I'll post up an example (which I can test first).
    That would be great!

  8. #8
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: DirectSound

    Milk

    @JonSea31: If you just want to avoid to diggin into advanced level of audio handling, you can always get a simple wrapper dll that is will play the audio for you. There's i havent found any really cheap solution, but mostly you can use them in your home (just like in freeware products as well), for free. For example, take a look at FMOD, or BASS, those have got built-in codecs to play numerous (both common/uncommon) file formats. You can get equalizer's, and some of the effect capabilities that is would be needed for a game programming. But the solutions are also fit for simple audio player applications as well.

    Fmod: http://www.fmod.org/
    Bass: http://www.un4seen.com/

    Read the licences carefully to avoid any copyright issues.

Posting Permissions

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



Click Here to Expand Forum to Full Width