Thread: adding sound in graphics.h

  1. #1
    Registered User
    Join Date
    Apr 2011
    Location
    Adana/TURKEY
    Posts
    2

    adding sound in graphics.h

    i'm having problems adding sound to my game in graphics.h and main problem is; i don't know how to add sound does anybody know how to add sound?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    On which OS?

    On windows you just #include windows.h and mmsytem.h then you can use the PlaySound() api call...

    I don't know about Mac, Linux or BSD... maybe the others can fill you in...

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    What compiler are you using? What operating system?

    Jim

  4. #4
    Registered User
    Join Date
    Apr 2011
    Location
    Adana/TURKEY
    Posts
    2
    my os is windows. and i'm using devc++ 4.9
    Last edited by hakanali; 04-25-2011 at 03:31 PM.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by hakanali View Post
    my os is windows. and i'm using devc++ 4.9
    Ok do yourself a favour and update to Pelles C It has a full set of resource editors and all the windows headers and libraries... so you will be able to include your sound events into the program's resources instead of relying upon external files.... The Pelles C help file is amazing so I shouldn't expect you'll have much trouble changing over.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I don't think just switching IDEs is going to be very helpful. Dev-C++ is a decent program -- and since the OP is using graphics.h, I'm guessing that means a port of Borland's ancient libraries to Windows (with kbhit() etc). So switching to another IDE and at the same time using the Windows headers might not be productive.

    On the other hand, it's not the best idea to use graphics.h as you might have guessed. It's very outdated and you'll find certain tasks (like playing sound...) to be difficult. I'd probably suggest, when you have time, that you try out a more modern library. Such as the Windows API that Pelles C apparently provides, if you wish (Dev-C++ also has these libraries, though perhaps not the resource editors).

    Or if you want to be more portable you could try the SDL (libsdl.org). (The mingw devel package works with Dev-C++.) The SDL is a cross-platform library that makes it easy to draw primitives, bitmap files, play sounds, read mouse and keyboard and joystick events, etc. It's what I'd personally suggest you learn in the long run. But do your research.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by dwks View Post
    I don't think just switching IDEs is going to be very helpful.
    Pelles C is more than just an IDE... it is a complete windows development system.
    Pelle has written his own compiler (based loosly upon LCC), his own resource editors and compilers and his own assembler as part of the package. And, yes, you can probably use the libraries you're recommending with it (although it's Plain C-99 no C++).

    FWIW... I don't make recommendations lightly and certainly not because it's what I use. Pelles C has earned it's stripes with me. Despite my ongoing search for a "better than C" language to work with I keep ending up back with it... because it really is the best setup I've seen (and yes I've even tried some commercial ones along the way). If you don't believe me, take a cruise through the help file... you'll understand.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    My point was mainly that while Pelles C may be an excellent windows development system (I've never tried it), I'm not sure that's what the OP wants. Sounds like he or she is using a port of Borland's libraries, and so might be better off using Allegro or the SDL, which are more similar to graphics.h than Windows development is.

    If I ever feel the urge to develop on Windows for some reason I'll have to check out Pelles C.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by dwks View Post
    My point was mainly that while Pelles C may be an excellent windows development system (I've never tried it), I'm not sure that's what the OP wants. Sounds like he or she is using a port of Borland's libraries, and so might be better off using Allegro or the SDL, which are more similar to graphics.h than Windows development is.

    If I ever feel the urge to develop on Windows for some reason I'll have to check out Pelles C.
    And my point was simply: "Don't knock it until you try it!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sound and graphics in C - recommandation needed
    By gavra in forum C Programming
    Replies: 50
    Last Post: 06-05-2008, 07:41 AM
  2. Adding sound to console apps
    By DarkMortar in forum C Programming
    Replies: 16
    Last Post: 05-24-2006, 11:53 PM
  3. Adding 2D graphics in OpenGL
    By Da-Nuka in forum Game Programming
    Replies: 7
    Last Post: 04-05-2005, 02:26 PM
  4. There is a problem with adding sound to my application...
    By Finchie_88 in forum C++ Programming
    Replies: 9
    Last Post: 12-31-2004, 01:19 PM
  5. graphics and sound
    By gcn_zelda in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2003, 07:23 PM

Tags for this Thread