Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how do I program a beep in C (QNX 6)?

227 views
Skip to first unread message

Jose A. Galvez

unread,
Apr 17, 2002, 11:57:39 AM4/17/02
to
Hello.

Does anyone know can make my PC speaker play a beep from a C program on QNX 6?

Thank you,
Jose

Mark Vickers

unread,
Apr 17, 2002, 2:40:47 PM4/17/02
to
Easiest way I know is to use ....

printf( "\a" );

This causes the speaker to emit a short beep on all the PC's I've
experimented with QNX on.

Mark


Jose A. Galvez <jaga...@iai.csic.es> wrote in message
news:3CBD9B73...@iai.csic.es...

David Bacon

unread,
Apr 17, 2002, 6:22:47 PM4/17/02
to
Just output a control-G to the terminal window (to which stdout and stderr
are connected by default). Control-G is ASCII code 7, or \a within strings.

dB

"Jose A. Galvez" <jaga...@iai.csic.es> wrote in message
news:3CBD9B73...@iai.csic.es...

Dave Green

unread,
Apr 17, 2002, 1:25:29 PM4/17/02
to

> Thank you,
> Jose

--

// beep the PC speaker

#include <stdlib.h>
#include <stdio.h>
#include <x86/inout.h>
#include <sys/neutrino.h>
#include <unistd.h>

int main()
{
int system_control=0;
unsigned long i;
unsigned long kbd, ctr;

// turn on bits 0 & 1 of kbd 0x61
ThreadCtl(_NTO_TCTL_IO, 0);

kbd = mmap_device_io(4,0x60);
ctr = mmap_device_io(4,0x40);

system_control=in8(kbd + 1);
out8(kbd + 1,system_control | 0x03);

// load control word for 8254

out8(ctr + 3, 0xb7); // bcd count, square wave,
// r/w lsb then msb, channel 2
// load counts

// to get 440Hz tone, divide 8254 clock (1.1892 MHz) by 2702

out8(ctr + 2, 0x02); // lsb count
out8(ctr + 2, 0x27); // msb count

// pause a bit...

for(i=0; i<50000000; i++);

// shut it off

system_control=in8(kbd + 1);
out8(kbd + 1,system_control & 0xfc);
return(0);

}
---

Dave Green (dgr...@qnx.com)

QNX Software Systems Ltd.
http://www.qnx.com

Dennis

unread,
Apr 17, 2002, 1:38:58 PM4/17/02
to
simple solution

printf("\a");

"Jose A. Galvez" <jaga...@iai.csic.es> wrote in message
news:3CBD9B73...@iai.csic.es...

Ian Zagorskih

unread,
Apr 19, 2002, 6:42:40 AM4/19/02
to

"John Hertell" <john.h...@removedizonetopreventspam.accom.se> wrote in
message news:a9oosp$kji$1...@inn.qnx.com...

>
> > // pause a bit...
> >
> > for(i=0; i<50000000; i++);
> >
> > // shut it off
>
>
> Iiiiihhhh.. that will not work sooo good on faster machines, why not use
a
> timer instead?
>
> didnt think ppl used to modern computers did such things :)
>

I hope that modern people on modern computers with modern operating systems
use smth like Beep(<freq>,<time>) so system speacker is supported by os on
driver's level and you don't need to access hardware by hands just to say
"be-beep" ;)

// wbr

John Hertell

unread,
Apr 19, 2002, 5:54:26 AM4/19/02
to

> // pause a bit...
>
> for(i=0; i<50000000; i++);
>
> // shut it off

Javier Barreiro

unread,
Apr 19, 2002, 9:37:49 AM4/19/02
to
if you want a bell beep, another short answer is

printf ("%c", 0x07);

Javier


"Jose A. Galvez" <jaga...@iai.csic.es> escribió en el mensaje
news:3CBD9B73...@iai.csic.es...

0 new messages