Thread: sound help

  1. #1
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    sound help

    ummmmmm, this may not be c++ programming maybe its windows, i dunno but can somebody tell me why it doesn't work
    Code:
    #include <iostream> 
    #include <windows.h> 
    #include <mmsystem.h> 
    
    main()
    { 
    	PlaySound("c:/sound.wav", NULL, PND_ASYNC); // This plays the file in the backround 
    	Sleep(400); 
    	return 0; 
    }
    it gives me this error
    C:\Program Files\DevStudio\SharedIDE\bin\sound test.cpp(9) : error C2065: 'PND_ASYNC' : undeclared identifier


    I remembered to use code tags, yay!

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    It's SND_ASYNC, not PND_ASYNC.
    "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
    Shadow12345
    Guest
    Isn't it supposed to be

    C:\soundwav

    instead of C:/sound.wav

    don't hit me.

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Nope. The file's name is sound.wav so you open sound.wav

  5. #5
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    ditto

  6. #6
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    still doesn't work

    ummmmmm i dunno, none of those things seem to work

    here's my current code
    Code:
    #include <iostream> 
    #include <windows.h> 
    #include <mmsystem.h> 
    main()
    { 
    	PlaySound("c:/sound.wav", NULL, SND_ASYNC); // This plays the file in the backround 
    	Sleep(400); 
    	return 0; 
    }
    thanks

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Try this:
    Code:
    #include <iostream> 
    #include <windows.h> 
    #include <mmsystem.h> 
    main()
    { 
    	PlaySound("c:\\sound.wav", NULL, SND_ASYNC); // This plays the file in the backround 
    	Sleep(400); 
    	return 0; 
    }
    The function also returns an error code, TRUE if successfull and FALSE if unsuccessfull. Maybe you could try checking that with some debug code. If that still doesn't work, make sure your speakers are plugged in and the volume is turned up, maybe the sound is playing but you are just not hearing it (checking the error code would help with this, you'd be able to see some output that the function returned TRUE indicating success even though you might not be able to hear anything).
    "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

  8. #8
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    still doesn't work

    even with that new code it doesn't work

    gives me these:

    sound test.obj : error LNK2001: unresolved external symbol __imp__PlaySoundA@12
    Debug/sound test.exe : fatal error LNK1120: 1 unresolved externals

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Ok, now we get to the heart of the problem. It would have been extremely usefull to have known this at the start but perhaps you never got far enough to see that message before. You need to modify your project so you add in the Winmm.Lib (I think that's the one) when you link.
    "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

  10. #10
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169
    ummmmm lol I'm afraid I don't know how to link it to my project

    do you mean just include it at the top?

  11. #11
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    ummmmm lol I'm afraid I don't know how to link it to my project

    do you mean just include it at the top?
    No, and I don't know what compiler version you are using so I'm not sure my instructions would be exact. I use Microsoft Visual Studio 6.0 and these are the steps you would go through in that version:

    1) Go to the Project menu option.
    2) Click on the Settings option.
    3) You will get a "Project Settings" window pop-up, look in the right hand portion of the window and you should see several tabs, one of which says "Link", click on that "Link" tab.
    4) The right hand portion of the "Project Settings" window will change and there will be an area labeled "Object/library modules:". Click in that area, where all the *.lib files are located, and then hit the End key to go to the end of all those files. At the end of the list of library files you need to type in "Winmm.lib" to add it to your project.
    5) Click on the "OK" button of the "Project Settings" window.
    6) Rebuild your project and the new library you just added should eliminate the error you were getting.

    If you have a different compiler your steps will likely be different but there should be some Menu options you can go through to get to your project settings. You may have do do some seaching. It sounds like you are using some version of the Microsoft Visual Studio.
    "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

  12. #12
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    If you're playing from a file on disk (which you are) then you also need to include SND_FILENAME:

    Code:
    PlaySound("sound.wav",NULL,SND_FILENAME | SND_ASYNC);

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, 01:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  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, 03:34 PM