sounds

How do I play sounds in CPP? Whats the command? I know it ain’t a opengl question, but usually game programmers know much about this stuff too…

I hope so anyway…

you have to have a sound library to handle all of the necessary routines…
either you code one yourself or you use one
written by someone else

DirectSound is an probably a good choice
if your coding for Win32… there are others
for different platforms

there is also a promising library that is
being built which is very similar in concept
to OpenGL - its a cross platform 3D library
for sound
check it out at www.openal.org

The “PlaySound” function defined in <mmsystem.h> may do well for your purpose.
It’s as simple as that:

  • PlaySound(“wavefile.wav”,0,SND_ASYNC|SND_FILENAME)
    for playing wavefiles directly.
  • PlaySound((char*)snd_addr,0,SND_ASYNC|SND_MEMORY)
    for playing a wavefile loaded into memory.
    For more complex stuff (e.g. surround-sound etc.) you’ll have to stick to DirectSound.

thanx, I’ll try that…

For playing digital music, you can use the Midas Sound System. This library can play the *.MOD *.S3M *.IT *.XM … music-formats. I think it is able to play single sounds, too. Setup is really simple but if you like you can also choose, which sound output should be used (DirectSound …).

Marc