Sound

This is a discussion on Sound within the C++ Programming forums, part of the General Programming Boards category; hey guys (i'm back), I've been looking on the internet for about 3.5 hours now, and still havn't found the ...

  1. #1
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88

    Question Sound

    hey guys (i'm back),

    I've been looking on the internet for about 3.5 hours now, and still havn't found the sollution.
    I'm trying to play a sound ( bling.wav ) in my Windows application.
    I can't get it to regonize bling.wav with

    Code:
    #include "bling.wav"
    neither do I know if this is the right way.. can someone show me the right direction?

    thanks
    PLay MystWind beta , within two years

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Quote Originally Posted by MystWind
    I'm trying to play a sound
    Look up the PlaySound function.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88
    this is what I allready came up with :

    Code:
    PlaySound("ding.wav",NULL,SND_ASYNC|SND_FILENAME);
    but I include it this way : [CODE]#include "ding.wav"[\CODE]
    didn;t work.

    edit : [CODE]
    #include "ding.wav"

    main() {

    PlaySound("ding.wav",NULL,SND_ASYNC|SND_FILENAME);

    return 0;
    }[\CODE] this one works but its doesnt plays the sound..

    edit: I;ve found a new clue... give me a moment and don't mention me till then.
    Last edited by MystWind; 05-09-2005 at 01:48 PM.
    PLay MystWind beta , within two years

  4. #4
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88

    Unhappy nope

    nope didn;t work out as i hoped it would:9 I'll just post my code :S can't do it alone.

    test.cpp
    Code:
    #include "ding.wav"
    #include "Mmsystem.h."
    #include "Coredll.lib."
    
    
    main() {
           
           PlaySound("ding.wav",NULL,SND_ASYNC|SND_FILENAME);
           
           return 0;
           }
    then i have ding.wav <-- the sound. and the automaticly created piece of code the dev compiler creates when you make a Windows application , headers :

    Code:
     #include <windows.h>
                #include "Mmsystem.h."
    sorry for the trouble.. I hope you guys can and are willing to help an old friend ( hmm....:P)
    PLay MystWind beta , within two years

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Well the first thing is that the #include directive is only used for including header files.
    The first argument to PlaySound is the file name in this case ding.wav so if that file is in the current directory of your program (usually the same directory that your program is in) then it will play it or you can specify the full path to the wave file.
    The other Option is to add the wav as as resource.

  6. #6
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Try this code:

    Code:
    #include "windows.h"
    #include "Mmsystem.h."
    
    
    main()
    {
    
        PlaySound("ding.wav",0,SND_SYNC|SND_FILENAME);
        return 0;
    }
    make sure that you link to winmm.lib

    for some reason the SND_ASYNC "works" on mine too but doesn't play the sound, but The SND_SYNC works and plays the sound

  7. #7
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    You must include the
    Code:
    #include <windows.h>

    Its a windows function.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by Darryl

    for some reason the SND_ASYNC "works" on mine too but doesn't play the sound, but The SND_SYNC works and plays the sound
    Probably because your program exits before the sound has a chance to play.

  9. #9
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by Quantum1024
    Probably because your program exits before the sound has a chance to play.
    Hey, you are absolutely right... I added a while (true) loop to keep it running and async worked perfectly.

  10. #10
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88
    great thanks for the help... only problem left is I don't know how to link to winmm.lib ?'

    anyone > plz tell me how to link to winmm.lib?
    Last edited by MystWind; 05-10-2005 at 12:53 PM.
    PLay MystWind beta , within two years

  11. #11
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88
    anyone?
    PLay MystWind beta , within two years

  12. #12
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by MystWind
    great thanks for the help... only problem left is I don't know how to link to winmm.lib ?'

    anyone > plz tell me how to link to winmm.lib?
    Well assuming you are using MSVC, you need to go into the project options under linker and you will find a field called additional dependencies, just type in winmm.lib...if there are other entries in there, put it after them, I think you can just seperate them with a space

  13. #13
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88
    ah great thanks a load havn;t found it yet but I'll figure ! ty!

    EDIT : ARGH ,I can't find that freakin option...I'll do it tomorrow...( i use Dev as a compiler , it doesn;t has the linker tab ) its a sub tab but i can;t add stuff there..)
    Last edited by MystWind; 05-10-2005 at 01:48 PM.
    PLay MystWind beta , within two years

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sound lags in multi-thread version
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 08-27-2008, 11:54 AM
  2. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 12:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 11:38 AM
  4. Help me modify my Sound Server
    By zdude in forum C Programming
    Replies: 1
    Last Post: 05-14-2003, 05:15 PM
  5. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 02:34 PM

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