Advertisement

Using Direct Sound for Interactive Soundtracking

Started by May 27, 2001 11:38 AM
3 comments, last by Coded 23 years, 5 months ago
Hi, I am currently working on a way to make interactive music for games or anything else. The general idea of this is that a song is composed together in realtime depending upon the situation that one is in. I want to use Direct X to do this but I am having trouble seeing the big picture of what the help files are talking about. I was wondering if anyone could send me a source of how to just play a wav file or better yet, mix and loop wavs. If anybody wants more information about what I am trying to do, please feel free to icq or IM me. I think this idea has a lot of potential since it not only improves the song that is being played but it also takes up much less space since the only wav files needed are small loops and samples. - Jefferson ICQ: 10679611 IM: Jefferson Hobbs
This is the slowest and easiest way to play a sound with DirectX8


void CMotorSound::Init()
{
//Initialisation of COM
CoInitialize(NULL);

CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader8, (void**) &Loader);

CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, IID_IDirectMusicPerformance8, (void**) &Performance);


//Audio parameters
Performance->InitAudio(NULL, NULL, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 64, DMUS_AUDIOF_ALL, NULL);
}

void CMoteurSound::Joue(char file[20])
{
WCHAR wFile[20];

//Convert to WCHAR
MultiByteToWideChar(CP_ACP, 0, fichier, -1, wFichier, 20);


//Load the file
Loader->LoadObjectFromFile(CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8, wFichier, (LPVOID*)&Segment);

Segment->Download(Performance);

//Play the sound
Performance->PlaySegmentEx(
Segment,
NULL,
NULL,
0,
0,
NULL,
NULL,
NULL);
}

void CMoteurSound::Quitte()
{
//Stop playing all sounds
Performance->Stop(NULL, NULL, 0, 0);
Performance->CloseDown();

//Delete objects
Loader->Release();
Performance->Release();

if (Segment)
Segment->Release();

//Quit COM
CoUninitialize();
}



Edited by - HiddenInBSP on May 27, 2001 12:52:59 PM
Advertisement
If you had a bunch of audio clips and two or more sound buffers, you could possibly do a crossfade transition between them, a la FreeSpace''s dynamic music. I don''t know that there''s a way to actually generate good music on the fly, though, I think everything''s going to have to be precomposed.
Well half of the composing is done before hand...I want to make 3 back buffers of 2-4 bars, one for the current state of the song, one for a higher state and one for a lower state and possibly a 4th one will be introduced later on for a major state change. Initially, these buffers are gonna be holding premaid stuff that I made so I can see how well this will run. However, I would like to make it so that it can produce a more ramdom song by giving the program more power to do the mixing of the samples and loops. The primary buffer will simply look at the current state at the end of each bar and grab from the respective back buffer. There are other things that I plan to do with it so it sounds better and has a solid structure to it but thats basically how it works.
No need to reinvent the wheel. DirectMusic does all of this in several easy-to-use API calls. You should check it out. Load up DirectMusic Producer and read the Help file. Everything you''re talking about doing from scratch is already done for you. All you need to do is load your MIDI and/or audio data into DirectMusic segments, feed DMProducer some information about the clips you''re importing, like key, tempo, intensity level, stuff like that, and let it randomize playback as much or as little as you want.


Ed Lima - ELM&M
ed@edlima.com
http://www.edlima.com
Ed Lima - ELM&Med@edlima.comhttp://www.edlima.com

This topic is closed to new replies.

Advertisement