Like Tree1Likes
  • 1 Post By CommonTater

Simple sounds

This is a discussion on Simple sounds within the C Programming forums, part of the General Programming Boards category; Hello, I need to play sound in my c code. It could be wav, mp3 doesnt matter.. searched in web ...

  1. #1
    wyy
    wyy is offline
    Registered User
    Join Date
    Apr 2011
    Posts
    5

    Simple sounds

    Hello,

    I need to play sound in my c code. It could be wav, mp3 doesnt matter.. searched in web but didnt found simple solution.

    Any suggestions?

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    Possibly printf("\a") but it's not guaranteed to work on all platforms.

  3. #3
    wyy
    wyy is offline
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    Quote Originally Posted by nonoob View Post
    Possibly printf("\a") but it's not guaranteed to work on all platforms.
    yea it works got 'a' sound ;D i can do the same with Beep(100, 500); but needed more difficult for wav, mp3 files:>

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by wyy View Post
    Hello,

    I need to play sound in my c code. It could be wav, mp3 doesnt matter.. searched in web but didnt found simple solution.

    Any suggestions?
    Which os... which compiler...

    On windows with a GUI capable compiler you can #include <windows.h> and #include <mmsystem.h> then use the PlaySound() api call (and yes, it works from console programs).
    wyy likes this.

  5. #5
    wyy
    wyy is offline
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    Working on Win XP, Microsoft Visual NET 2003 :>

  6. #6
    wyy
    wyy is offline
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    Quote Originally Posted by CommonTater View Post
    Which os... which compiler...

    On windows with a GUI capable compiler you can #include <windows.h> and #include <mmsystem.h> then use the PlaySound() api call (and yes, it works from console programs).
    Well.. A bit strange for me.

    Code:
    PlaySound(TEXT("swish.wav"), NULL, SND_FILENAME);
    If after compiling i run program by pressing F5 from MS Visual SOUND WORKS
    If i just open exe file from folder, or by using cmd (type: program.exe ).. i get just little "pyp" sound, but not the original wav.
    Last edited by wyy; 04-27-2011 at 01:22 PM.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's because your program is closing before the sound completes... you can try adding SND_SYNC which should hold your program until the sound completes.... otherwise just put Sleep(5000); (for 5 seconds) right before the program exits.

    Code:
    PlaySound("swish.wav",NULL,SND_FILENAME | SND_SYNC);
    
    
    // optional
    Sleep(1000);
    return 0; }
    Last edited by CommonTater; 04-27-2011 at 01:29 PM.

  8. #8
    wyy
    wyy is offline
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    khekhe

    I figuret out.

    It works fine now. The problem was that my exe file was in debug folder, and wav file in other destination. So i copied wav file to debug folder.

    Thanks for help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sounds in C?
    By louieansonng in forum Game Programming
    Replies: 8
    Last Post: 08-22-2009, 09:22 AM
  2. sounds in C
    By llinocoe in forum C Programming
    Replies: 3
    Last Post: 09-23-2008, 11:21 AM
  3. Ads with sounds
    By ober in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 03-30-2005, 10:38 AM
  4. Sounds
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-17-2003, 06:27 AM
  5. Sounds, or no sounds?
    By face_master in forum C++ Programming
    Replies: 3
    Last Post: 09-03-2001, 05:29 PM

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