how to play sound in a c++ program?

This is a discussion on how to play sound in a c++ program? within the C++ Programming forums, part of the General Programming Boards category; if i want to play sound in a c++ program, can win32 console application do so? what function should i ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    how to play sound in a c++ program?

    if i want to play sound in a c++ program, can win32 console application do so? what function should i use? and do i have to include any other library??

    please help, thank you so much

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    You can download sound samples here.

    This function will play a sound.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Anon
    Guest
    You can use the PlaySound() function. MSDN link:

    http://msdn.microsoft.com/library/de...mfunc_9uxw.asp

    Don't forget to link to Winmm.lib and include Mmsystem.h

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    98
    how can you play sounds not using microsoft products? is there nothing in the stl that can do this?almost every time someone on here askes for a graphic sample or a play sound sample, they are referred back to ms products.does linix, unix not have sounds and graphics?or, are you confined to the little black box?( i know better), just want to see what kind of answers we get back.

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Using the MS software to play sound is easy, especially since you seem to be working on a Windows machine, so you can use the Win32 MultiMedia API, see the links as provided above. If you don't want to use MS software, there are lots of libraries available which you can use. For example:

    http://www.thefreecountry.com/develo...ibraries.shtml

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    "can win32 console application do so?"

    The question sounded quite system specific, so we gave specific answers.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    Well last night I was looking through cprogramming's soucre code section and it had a sound example. So here ya go-

    http://www.cprogramming.com/source/w...on=Jump&LID=29

  8. #8
    Shadow12345
    Guest
    I know of a library that can play wavs and mp3s and it might be platform independant. I'll dig it up, I've posted it before I think.

    EDIT:
    yes, fmod is it, i'll include a tutorial that shows it being used


    FMOD stuff
    Last edited by Shadow12345; 01-02-2003 at 03:01 PM.

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Shadow12345
    I know of a library that can play wavs and mp3s and it might be platform independant. I'll dig it up, I've posted it before I think.
    FMOD ?

    http://www.fmod.org/
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    To nvoigt or others

    so can it be done in the win32 console application?
    i have browse through the msdn library and they have provide a function there, can it be done by just including the function in the program?

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    What kind of sound are you planning to play? wav? mp3?
    You can use PlaySound() for wav declared in windows.h
    defined in winmm.lib

  12. #12
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    SDL(libsdl.org), clanlib(clanlib.org), allegro(?? lol never looked into it), many more.. graphics, input, sound, and what not

    all three of those are platform independent. btw, C/C++ is not like BASIC with gfx and sound in the language, you have to use apis and libraries (above ).

  13. #13
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >so can it be done in the win32 console application?

    Sure. Your application must know how to handle the soundcard and how to handle the format of the file (MP3, WAV etc.) you will be using. Note that a win32 console application is in short a win32 application without a GUI.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to play a sound
    By asofaihp in forum C++ Programming
    Replies: 16
    Last Post: 09-02-2009, 09:37 PM
  2. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  3. Sound in a c program
    By c u r != me in forum C Programming
    Replies: 0
    Last Post: 03-22-2009, 04:07 PM
  4. 'C' windows sound program...
    By Klint in forum Windows Programming
    Replies: 2
    Last Post: 06-02-2005, 01:50 AM
  5. this is how you can play wavs/mp3s in a C++ program
    By Shadow12345 in forum C++ Programming
    Replies: 2
    Last Post: 12-06-2002, 04:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21