Author Topic: playing sound using winapi?  (Read 3384 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
playing sound using winapi?
« on: May 15, 2007 »
Is it possible to play raw audio data stored in memory using the winapi?

Cheers,
Fryer.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: playing sound using winapi?
« Reply #1 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,.....
...
...
};
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: playing sound using winapi?
« Reply #2 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 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

Jim
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: playing sound using winapi?
« Reply #3 on: May 16, 2007 »
Ah, good stuff. Thanks Jim and rbraz.