Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <i86.h>
    void sound( unsigned frequency );

Description:
    The sound function turns on the PC's speaker at the specified frequency.
     The frequency is in Hertz (cycles per second).  The speaker can be
    turned off by calling the  nosound function after an appropriate amount
    of time.

Returns:
    The sound function has no return value.

See Also:
    delay, nosound

Example:
    #include <i86.h>

    /*
        The numbers in this table are the timer divisors
        necessary to produce the pitch indicated in the
        lowest octave that is supported by the "sound"
        function.

        To raise the pitch by N octaves, simply divide the
        number in the table by 2**N since a pitch which is
        an octave above another has double the frequency of
        the original pitch.

        The frequency obtained by these numbers is given by
        1193180 / X where X is the number obtained in the
        table.
    */

    unsigned short Notes[] = {
            19327 ,        /* C b            */
            18242 ,        /* C              */
            17218 ,        /* C #   ( D b )  */
            16252 ,        /* D              */
            15340 ,        /* D #   ( E b )  */
            14479 ,        /* E     ( F b )  */
            13666 ,        /* F     ( E # )  */
            12899 ,        /* F #   ( G b )  */
            12175 ,        /* G              */
            11492 ,        /* G #   ( A b )  */
            10847 ,        /* A              */
            10238 ,        /* A #   ( B b )  */
            9664 ,         /* B     ( C b )  */
            9121 ,         /* B #            */
            0
    };

    #define FACTOR  1193180
    #define OCTAVE  4

    void main()             /* play the scale */
      {
        int i;
        for( i = 0; Notes[i]; ++i ) {
          sound( FACTOR / (Notes[i] / (1 << OCTAVE)) );
          delay( 200 );
          nosound();
        }
      }

Classification:
    Intel

Systems:
    DOS, Win, QNX

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson