Archived

This topic is now archived and is closed to further replies.

ace_muncher

How do I use sound in my game?

Recommended Posts

I''m making an RTS and I need to know the commands and files I need to use in order to do this correctly. I plan on using MP3 format, and DirectX. What commands do I use? Should I somehow transfer the info into an array in my game? Could I use classes? Also, if anyone has any ideas on commanding options, available units, possible can/cannot options you wanted to see in other RTS games, etc., I''m all ears. -Ace

Share this post


Link to post
Share on other sites
This is an entire program that simply plays a mp3. No headers, nothing else:

#include
#pragma comment(lib, "amstrmid.lib")

void main(void)
{
IGraphBuilder *pGraph;
IMediaControl *pMediaControl;
IMediaEvent *pEvent;
CoInitialize(NULL);

// Create the filter graph manager and query for interfaces.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

// Build the graph. IMPORTANT: Change string to a file on your system.
pGraph->RenderFile(L"D:\\Track001.mp3", NULL);

// Run the graph.
pMediaControl->Run();

// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);

// Clean up.
pMediaControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();
}

Hope that helped you.

Share this post


Link to post
Share on other sites
while that may work, you are probably better off using DirectMusic directly rather than DirectShow to play the mp3. The code is a little more complex so I won''t display it here. You''ll have to create a DirectMusic loader, a performance and an audiopath and load your mp3 into a DirectMusic segment before you play it, but with DirectMusic you will have a lot more options to work with. All of your sounds should generally go through DirectMusic in your game anyways, so creating a loader, performance, and an audiopath is necissary anyways.
I''m making a second generation API for pretty much all audio and synchronization that works off of both the DirectAudio API and the FMOD API to allow for around 30 different formats ( along with the additions of some memory dumps such as SNES SPC files, NSF Nintendo files, GYM genesis files, and some others).
I won''t be finished until December, but if you want to wait, it''s worth it. I made a new file format to replace the old DirectMusic Containers, so that now you can store many audio files, of types DirectMusic doesn''t normally support, and have easy access to them all in one, nice little file.
This might be more than what you are looking for, but it''ll make all audio and music a lot easier and still give you access to everything you''d need. I''ll contact you later if you are interested.

Matt Calabrese
Open Zelda Sound/Music Programmer,
Composer, and Musician

Share this post


Link to post
Share on other sites

Matt, is this as efficient as manually opening an MP3, decoding it, and feeding that into a dynamic DirectSound buffer? I assume doing it through DS would allow the sound card to mix it with any other SFX being played, and would accelerate it if the hardware supports it. If you slowly decompressed the MP3 and then fed the data into the direct sound buffers, memory usage would be low and CPU utilization probably wouldn''t be too bad. I thought DirectMusic was only for midi files, does it handle MP3''s efficiently?

Share this post


Link to post
Share on other sites
DirectMusic handles a whole bunch of formats in directx 8. In fact, they are trying to gradually weed out "DirectSound" and merge it with DirectMusic -- which I think you''ll see more of in the Direct X 9 API. The DirectMusic loader can load, without even needing the help of other interfaces, MP3s, PCM waves, ANY FORM OF ACM compressed wav, Segments, Scripts, toolgraphs, containers, audiopath templates, DLS instrument banks and many, many others (I highly recomend you check out the DirectMusic documentation included with the SDK). It handles mp3''s just as efficiently, or so I''m guessing. Most audio loaded through the DirectMusic loader has the potential to be streamed, as well, so you can have it whatever way you like it.
The main benefit of loading it through the DirectMusic loader and into a performance and audiopath is for the effects, as well as dynamic looping, and synchronization with events. Like I said, the documentation is very well done for once, and it''s worth checking out. While a little intimidating at first, everything is layed out very nicely.
As I said, look to December (probably be done before than), for my OZAP, OZAR, and OZAI audio formats and API. It''ll make everything a lot easier to work with, and because I''m making it joint with FMOD interfaces, it supports several mod formats as well as all of the DirectMusic loader interfaces (also, pending is SPC, NSF, etc. support as I believe I mentioned above). So keep checkin''!

---------------
Matt Calabrese
Open Zelda Sound/Music Programmer,
Composer, and Musician
http://www.OpenZelda.co.uk

~Make Your Game~

Share this post


Link to post
Share on other sites

Wow, I''m looking through the Platform SDK docs for DX8.1, and DirectMusic looks very different from what I''m used to. I had built a basic wave-based audio engine in DX7, and hadn''t looked at what''s been changed in the API since then. The section that deals with IDirectMusicLoader8, which appears to be what actually handles the different file types, lists these types:


Object type Class Extension
Audiopath CLSID_DirectMusicAudioPathConfig aud
Band CLSID_DirectMusicBand bnd
Container CLSID_DirectMusicContainer con
DLS collection CLSID_DirectMusicCollection dls
Chordmap CLSID_DirectMusicChordMap cdm
Segment CLSID_DirectMusicSegment sgt
Script CLSID_DirectMusicScript spt
Song* CLSID_DirectMusicSong sng
Style CLSID_DirectMusicStyle sty
Template CLSID_DirectMusicSegment tpl
Toolgraph CLSID_DirectMusicGraph tgr
Wave CLSID_DirectSoundWave wav


Is there a newer version that supports more file types?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
nope, that''s why I''m making my "joint" DirectX and FMOD API -- so you can use all of the DirectX formats as well as those in FMOD. The Direct X formats are the best formats in notational music... ever. Don''t think I''m exagerating either. The only problem is that currently, the only way you can play the formats is with Direct X and it is really annoying having to make sure people have Direct X 8 just so that you can take advantage of the formats -- but for now that''s the way it has to be

Share this post


Link to post
Share on other sites
nope, that's why I'm making my "joint" DirectX and FMOD API -- so you can use all of the DirectX formats as well as those in FMOD. The Direct X formats are the best formats in notational music... ever. Don't think I'm exagerating either. The only problem is that currently, the only way you can play the formats is with Direct X and it is really annoying having to make sure people have Direct X 8 just so that you can take advantage of the formats -- but for now that's the way it has to be

EDIT: Sorry for the second post, forgot to login in the last one.

---------------
Matt Calabrese
Open Zelda Sound/Music Programmer,
Composer, and Musician
http://www.OpenZelda.co.uk

~Make Your Game~

Edited by - Matt Calabrese on October 18, 2001 2:57:46 PM

Share this post


Link to post
Share on other sites
Just to clear things up in case you didn''t realize it.

The DirectMusic Loader loads MP3s, midis, acm compressed waves, etc. into Segment interfaces, so they are compatible even though they aren''t mentioned on the list.

---------------
Matt Calabrese
Open Zelda Sound/Music Programmer,
Composer, and Musician
http://www.OpenZelda.co.uk

~Make Your Game~

Share this post


Link to post
Share on other sites