From: Progga <abulfazl@juniv.edu>
To: linux-c-programming@vger.kernel.org
Cc: icemanind@yahoo.com
Subject: Re: Speaker Sound
Date: Sat, 11 Mar 2006 07:32:38 +0600 [thread overview]
Message-ID: <20060311013238.GA605@ju.Imrashi.net.bd> (raw)
In-Reply-To: <20060310193329.726.qmail@web51414.mail.yahoo.com>
[-- Attachment #1.1: Type: text/plain, Size: 289 bytes --]
> }
>
> 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.
[-- Attachment #1.2: music.c++ --]
[-- Type: text/plain, Size: 1329 bytes --]
// 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 #2: Type: application/pgp-signature, Size: 187 bytes --]
prev parent reply other threads:[~2006-03-11 1:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-10 19:33 Speaker Sound Alan Bryan
2006-03-11 1:32 ` Progga [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060311013238.GA605@ju.Imrashi.net.bd \
--to=abulfazl@juniv.edu \
--cc=icemanind@yahoo.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).