Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Stonemonkey on May 15, 2007

Title: playing sound using winapi?
Post by: Stonemonkey on May 15, 2007
Is it possible to play raw audio data stored in memory using the winapi?

Cheers,
Fryer.
Title: Re: playing sound using winapi?
Post by: Rbz on May 15, 2007
If you are looking for playing wave files, I know one way to play it from memory using playsound:

Code: [Select]
//Play our sound
PlaySound( (const char *)soundData, NULL, SND_MEMORY);

Where "soundData" is your .wav file converted to C array buffer, something like this:

Code: [Select]
static unsigned char soundData[] = {
0x00,0x50,0x00,0x20,0x00,0x78,0x00,0x20,0x00,.....
...
...
};
Title: Re: playing sound using winapi?
Post by: Jim on May 15, 2007
If your data really is raw data without a header, you can use waveOut* functions.  Check out the gm.dls code here http://dbfinteractive.com/index.php?topic=1702.0 (http://dbfinteractive.com/index.php?topic=1702.0) for a sample of how to do that.
Or if you want something different, you can use DirectSound http://dbfinteractive.com/index.php?topic=1540.0 (http://dbfinteractive.com/index.php?topic=1540.0)

Jim
Title: Re: playing sound using winapi?
Post by: Stonemonkey on May 16, 2007
Ah, good stuff. Thanks Jim and rbraz.