Thread: sound and graphics in C - recommandation needed

  1. #1
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265

    sound and graphics in C - recommandation needed

    so i am programming for 2 years and i would like to use "sound" and "graphics" in my programes.
    i know the sound function and the graphics library in borland but after all it's borlan XD
    so I need you to recommend about an simple graphics (2D) interface and i need you to give me an example for using sound in C (I heard a little about the beep function).
    thx!! [:

    * hope I haven't pass the rules.
    Last edited by gavra; 06-01-2008 at 06:42 AM.

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    SDL can do sound and graphics. Although for sound it does little more than play mp3s.

  3. #3
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    thank you, I'll check it later.
    still open for recommandations..

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There is the sound() function for Borland, but what you want is a music maker. Making music with sound() would be extremely laborious. Any program that can make music, will show you how to play that music, of course.

    This is the Borland C help file for sound:

    Code:
    sound   Turns PC speaker on at specified frequency.
    
     Syntax:
       void sound(unsigned frequency);
    
     Prototype in:
     dos.h
    
     Remarks:
    sound turns on the PC's speaker at a given frequency.
    
    frequency specifies the frequency of the sound in hertz (cycles per second).
    
    To turn the speaker off after a call to sound, call the function nosound.
    
     Return Value: None.
    
     Portability:
    sound works with IBM PCs and compatibles only. A corresponding function
    exists in Turbo Pascal.
    
     See Also:
      delay    nosound
    
     Example:
     /* Emits a 440-Hz tone (A above middle C) for 1 second. */
    
     #include <dos.h>
    
     int main(void)
     {
        sound(440);
        delay(1000);
        nosound();
        return 0;
     }
    Have you googled for music making programs and libraries?

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You will need a 3rd party library or engine to do sound.

    You may want to check out OpenAL.

  6. #6
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    I think i wasn't clear enough, i don't wanna play\create music (like mp3), just sound in hertz..
    I'll very glad if you give me links or something for what you are suggesting.
    thank you both.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Making sound in hertz is just what my last post's code and help was all about, what do you mean?

    Read the part in the code tags, and try the example code, in it.

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    putchar('\a');

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Gone are the days when you could hook a timer interrupt for timing and use the 8 khz PC speaker for sound based on the timer - or are they? A friend of mine at work coded something like this a very long time ago. Surprisingly it still works in a DOS window. He fires it up every now and then and we have a ball listening to some good old fashioned 8 khz PC speaker music. He actually encoded some old AC/DC songs. Just consider it an ancient form of MP3.
    Last edited by VirtualAce; 06-01-2008 at 09:15 PM.

  11. #11
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    that's what I want but this function is from borland (I use dev C++ and I prefer to have standart codes).

    for beep I must know api first?
    API is complicated )=

    rob, I have seen what you wrote somewhere but how do i control the sound? (if you can give me more details).

    last and likeable
    I didn't get you or you didn't get me.
    I am not traing to play songs XD

    thank you all [:

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Win32 API maybe?

    The manual page is pretty straight forward (http://msdn.microsoft.com/en-us/libr...77(VS.85).aspx). What do you want to know?

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If we wanted to implement Windows "Beep" in Borland code, it would looke like this:
    Code:
    BOOL WINAPI Beep(
      __in  DWORD dwFreq,
      __in  DWORD dwDuration
    )
    {
         sound(dwFreq);
         delay(dwDuration);
         nosound();
    }
    I don't think that makes it hard to do or deal with.

    Obviously, learning the ENTIRE Windows API is complicated, but understanding individual functions is (generally, and certainly in this case) simple.

    Beep

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    I compiled this code (with borland)

    Code:
    #include <stdio.h>
    #include <dos.h>
    
    int main()
    {
         sound(700);
         delay(3000);
         nosound();
         return 0;
    }
    and all I heard was the silence..
    when I tried to compile the API part I got errors.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can you get other sounds out of the system? Is the PC speaker connected?

    The Beep() function requires that you include <windows.h>

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  2. Project Lost Tomorrow recruiting Programmers and Sound Engineers
    By chewtoy in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 12-07-2005, 05:02 AM
  3. DirectX Question
    By bladerunner627 in forum Game Programming
    Replies: 2
    Last Post: 04-04-2005, 11:55 AM
  4. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  5. graphics and sound
    By gcn_zelda in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2003, 07:23 PM