Re: Speaker Sound

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> }
> 
> The problem is, I'm not sure if I can just read and
> output bytes from a port. Any alternate way would be
> appreciated!

Sample code attached.
Mainly based on the Linux Programmer's Guide.
Runs as suid root.
Depends on ncurses.
Press q-i buttons for various tones.

   // Simple harmonium - needs root's privilege to run .


#include<sys/ioctl.h>
#include<sys/kd.h>
#include<sys/types.h>
#include<fcntl.h>
#include<unistd.h>
#include<cerrno>
#include<cstdlib>
#include<curses.h>
#include<iostream>




void
main ( )
{

  char ch ;
  int freq, fd = open ("/dev/console", O_WRONLY);


    initscr() ;




    while( 1 ){


          ch = getch() ;

          switch( ch ){

             case 'u' :

             freq = 46   ;

             break ;


             case 'y' :

             freq = 48   ;

             break ;



             case 't' :

             freq = 53   ;

             break ;


             case 'r' :

             freq = 59   ;

             break ;



             case 'e' :

             freq = 65  ;

             break ;



             case 'w' :

             freq =  70  ;

             break ;



             case 'q' :

             freq =  80  ;

             break ;



             case 'i' :

             freq = 90 ;

             break ;


             default:

               freq = -1 ;

                   }


          if( freq == -1 )break ;

          freq *=10 ;


          ioctl (fd, KIOCSOUND, freq );

          usleep ( 200000 );

          ioctl( fd, KIOCSOUND, 0 ) ;

                                 }



  close (fd);

  endwin() ;

}

Attachment: pgptdBWBFAJLx.pgp
Description: PGP signature


[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux