Getting some sound in your DX games

This is a discussion on Getting some sound in your DX games within the Game Programming forums, part of the General Programming Boards category; Here is some intro code for you. Just got my book on directx 9 audio programming (3D math book is ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597

    Getting some sound in your DX games

    Here is some intro code for you. Just got my book on directx 9 audio programming (3D math book is now on the way) and it has taught me a lot about audio programming and much about music synthesis, tracks, segments, etc.,etc. Very good book.

    Here is some code to get you up and running.


    Code:
    IDirectMusicPerformance8 *pPerformance=NULL;
    IDirectMusicLoader8 *pLoader=NULL;
    IDirectMusicSegment8 *pSegment=NULL;
    
    //
    //Init COM
    //
    CoInitialize(NULL);
    
    //
    //Create loader
    //
    CoCreateInstance(CLSID_DirectMusicLoader,
                                  NULL,
                                  CLSCTX_INPROC,
                                  IID_IDirectMusicLoader8,
                                  (void **)&pLoader);
    
    //
    //Create Performance
    //
    CoCreateInstance(CLSID_DirectMusicPerformance,
                                  NULL,
                                  CLSCTX_INPROC,
                                  IID_IDirectMusicPerformance8,
                                  (void **)&pPerformance);
    
    //
    //Init performance
    //
    pPerformance->InitAudio(NULL,
                                             NULL,
                                             NULL,
                                             DMUS_APATH_DYNAMIC_STEREO,
                                             2,
                                             DMUS_AUDIOF_ALL,
                                             NULL);
    
    //
    //Load WAVE from current directory
    //assumes "anywavefile.wav" is file name
    if (SUCEEDED(pLoader->LoadObjectFromFile(
                                           CLSID_DirectMusicSegment,
                                           IID_IDirectMusicSegment8,
                                           L"anywavefile.wav",
                                           (LPVOID *)&pSegment))) {}
    
    //
    //Place wave data in synth
    //
    pSegment->Download(pPerformance);
    
    //
    //Finally, play the thing
    //
    pPerformance->PlaySegmentEx(
                                                      pSegment,
                                                      NULL,
                                                      NULL,
                                                      0,
                                                      0,
                                                      NULL,
                                                      NULL,
                                                      NULL);
    
    //Pause for sound to play
    //Insert code here
    
    
    //
    //Unload data
    //
    pSegment->Unload(pPerformance);
    
    //
    //Release segment from memory
    //
    pSegment->Release();
    
    //
    //Close down performance and release
    //
    pPerformance->CloseDown();
    pPerformance->Release();
    
    
    //
    //Release loader
    //
    pLoader->Release();
    
    
    //
    //Done with COM
    //
    CoUninitialize();

    Requires DirectX 9.0 and MSVC version 6.0+

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    Bubba, are you self-taught?

    Did you take any classes on programming ?

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    100% self-taught when it comes to assembly and C/C++ althought I have had some programming classes related to BASIC.

    I've read lots and lots and lots of books, PDFs, text files, tutorials, and I have been coding in C since about 1990 or so when Turbo C++ version 1.0 came out.

    I taught myself assembly language through Randall Hyde's art of assembly book and since then have read the manuals for the 8086, IA-32, and IA-64 (Itanium) Intel processors.

    I've also studied in great depth 3D mathematics, vectors, linear algebra, some calculus (which I did not have in school), algorithms, data structures, and other various topics relating to computer programming including but not limited to operating system development. Just recently I bought a slew of modern 3D books about Direct3D.

    I've also had experience coding a DOS-based sound engine so I'm also extremely interested in sound which is why I also have several books, PDF's, and text files about sound processing, filtering, etc. My newest book DirectX 9 Audio Exposed is a book chocked full of great information about how DirectAudio works in DirectX9.

    My newest book is completely about 3D math and after that I plan to get yet another one on the same topic.

    So that is about it really, how about you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. DirectSound - multiple sounds
    By Magos in forum Game Programming
    Replies: 9
    Last Post: 03-03-2004, 04:33 PM
  4. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 03:34 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21