Play Sound with C/C++

Hi everyone.
I'm trying to play some sounds using Visual C++ programming. Is there
a way to play sounds which are not stored in a wav file, but in a raw-data file as integers? In other words i want to create a function that plays a sound which is stored in a 1-D integer array (mono sound), assuming that the sample rate is 8000Hz (something like sound.m function of matlab!).
Thanx,
Theodore.

Comments

  • No matter what you do, you will need an audio library to play the sound. I used to program under MS Visual C++ with allegro library which features, among other things, a very good audio handling.

    So you take your raw sound file, convert it to the allegro sample format and make it play by allegro. If you don't know how the allegro sample structure works, you can always save your music as a wave file and load the wave file back again with allegro and play it.
  • SephirothSephiroth Fayetteville, NC, USA
    [b][red]This message was edited by Moderator at 2003-8-9 20:56:3[/red][/b][hr]
    : No matter what you do, you will need an audio library to play the sound. I used to program under MS Visual C++ with allegro library which features, among other things, a very good audio handling.
    :
    : So you take your raw sound file, convert it to the allegro sample format and make it play by allegro. If you don't know how the allegro sample structure works, you can always save your music as a wave file and load the wave file back again with allegro and play it.
    :
    OK, normally I don't post here unless I need to, but this is incorrect. You do *NOT* need a library just to play a sound. PlaySound supports the basic file formats, such as MID and WAV, and I think MP3 now, but then DirectX can play virtually everything, and it is on any Win9X, NT, or XP machine. If you needed a library to play a sound, most of Windows would not function. The "PlaySound();" function works the same in C++ as it does in C.

    *EDIT*

    Just grasped what was said in the first thread. For that custom format, I think it could be played using some core Windows functions, but would require a LOT of coding on the user's part.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]



  • :You do *NOT* need a library just to play a sound. PlaySound supports the basic file formats, such as MID and WAV, and I think MP3 now, but then DirectX can play virtually everything, and it is on any Win9X, NT, or XP machine. If you needed a library to play a sound, most of Windows would not function. The "PlaySound();" function works the same in C++ as it does in C.
    :

    Hmmmm, apologizes, I didn't know that.
    I just had a look at those sound functions supported in C and the "waveOutWrite()" function sends a data block to the given waveform-audio output device. That might be what you want. This function takes an array of raw audio data, and plays it out.
    Or as I said before you can still save you raw data in .wav format, which is very simple, and load it back again with "PlaySound()". This is a quite slow process, so you might choose it for occasional and predictable use, such as songs.

  • SephirothSephiroth Fayetteville, NC, USA
    : Or as I said before you can still save you raw data in .wav format, which is very simple, and load it back again with "PlaySound()". This is a quite slow process, so you might choose it for occasional and predictable use, such as songs.
    :
    :
    Yeah, PlaySound() isn't the best for a game that ahs frequent sounds. Use it to loop music if you don't want to go the DirectSound route, but that's about it. I tried using it after I made my first VERY lame Windows game, and it sucked for sound playback.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • : Hi everyone.
    : I'm trying to play some sounds using Visual C++ programming. Is there
    : a way to play sounds which are not stored in a wav file, but in a raw-data file as integers? In other words i want to create a function that plays a sound which is stored in a 1-D integer array (mono sound), assuming that the sample rate is 8000Hz (something like sound.m function of matlab!).
    : Thanx,
    : Theodore.
    :
    :
    i reply this post to someone else too

    hi!
    well i understand you use visual c++
    the best approch is going to unversity get book on pc hardware
    this books come with cd "sample programes", whice have low level sourch code of playing sound from simple array.
    their is sourch code in c of playing *.raw files in
    this site that i post earlier.
    http://www.cae.wisc.edu/~brodskye/other/code.html#SB16SND
    but i recommend of the first approch.

  • : [b][red]This message was edited by Moderator at 2003-8-9 20:56:3[/red][/b][hr]
    : : No matter what you do, you will need an audio library to play the sound. I used to program under MS Visual C++ with allegro library which features, among other things, a very good audio handling.
    : :
    : : So you take your raw sound file, convert it to the allegro sample format and make it play by allegro. If you don't know how the allegro sample structure works, you can always save your music as a wave file and load the wave file back again with allegro and play it.
    : :
    : OK, normally I don't post here unless I need to, but this is incorrect. You do *NOT* need a library just to play a sound. PlaySound supports the basic file formats, such as MID and WAV, and I think MP3 now, but then DirectX can play virtually everything, and it is on any Win9X, NT, or XP machine. If you needed a library to play a sound, most of Windows would not function. The "PlaySound();" function works the same in C++ as it does in C.
    :
    : *EDIT*
    :
    : Just grasped what was said in the first thread. For that custom format, I think it could be played using some core Windows functions, but would require a LOT of coding on the user's part.
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories