linux speaker beep

J

jgcrawford

G'day,
I'm writing a ringtone manager for nokia ringtones and I'd like to be
able to play the ringtone on the PC speaker. I've had some success in
DOS with turbo C and its sound(), delay() and nosound(). Is there
anything similar for Linux? I know I can make a simple beep with '\a',
but that's not what I need. If not, can someone please show me how to
do this with the /dev/audio device?
 
J

Joona I Palaste

G'day,
I'm writing a ringtone manager for nokia ringtones and I'd like to be
able to play the ringtone on the PC speaker. I've had some success in
DOS with turbo C and its sound(), delay() and nosound(). Is there
anything similar for Linux? I know I can make a simple beep with '\a',
but that's not what I need. If not, can someone please show me how to
do this with the /dev/audio device?

If you want comp.unix.programmer, you know where to find it.
 
J

jgcrawford

Joona said:
If you want comp.unix.programmer, you know where to find it.

Well I didn't know that was the group I wanted, since the question I
had involved DOS as well. I'll try reposting it there, thank you.
 
M

Malcolm

I'm writing a ringtone manager for nokia ringtones and I'd like to be
able to play the ringtone on the PC speaker. I've had some success in
DOS with turbo C and its sound(), delay() and nosound(). Is there
anything similar for Linux? I know I can make a simple beep with '\a',
but that's not what I need. If not, can someone please show me how to
do this with the /dev/audio device?
Audio is usually handled by third-party libraries, which are off-topic here.

Unix being unix, it might be possible to open the audio device as a standard
file using fopen(), and then write audio to it in some format or other.
However you would have to ask in a unix group whether this is allowed, and
if so what format the data has to be sent in.
 
J

Jack Klein

If you want comp.unix.programmer, you know where to find it.

Why do you keep redirecting people who specifically mention Linux in
their OT questions to comp.unix.programmer? Linux != UNIX. The
proper group for platform specific questions about Linux is

If you are going to redirect, make the effort to redirect correctly.
 
E

Emmet Gorhsen

Jack said:
Why do you keep redirecting people who specifically mention
Linux in their OT questions to comp.unix.programmer? Linux !=
UNIX. The proper group for platform specific questions about
Linux is
If you are going to redirect, make the effort to redirect
correctly.

--
OOOO OOOOO OOOO: OOOO://OO-OOOOOOOOOO.OOO OOOO OOO
OOOO.OOOO.O OOOO://OOO.OOOOOO.OOO/~OOO/O-OOO/OOO.OOOO
OOOO.OOOO.O++ OOOO://OOO.OOOOOOOOO.OOO/O++-OOO-OOOO/
OOO.OOOO.OOOO.OOOOO.O-O++
OOOO://OOO.OOOOOOO.OOOOOO.OOO.OOO/~OOO/OOOO/OOO-OOOOO.OOOO

Says a _jerk_ who is using his sig as a commercial.
 
J

joshua crawford

Emmet said:
Says a _jerk_ who is using his sig as a commercial.

Says a jerk whose sole point in posting is to call another person a
jerk. I must say I love the atmosphere in here. Thanks to Joona for the
pointer to comp.unix.programmer. My problem is mostly resolved now.
 
K

Keith Thompson

Emmet Gorhsen said:
Jack Klein wrote: [snip]
--
OOOO OOOOO OOOO: OOOO://OO-OOOOOOOOOO.OOO OOOO OOO
OOOO.OOOO.O OOOO://OOO.OOOOOO.OOO/~OOO/O-OOO/OOO.OOOO
OOOO.OOOO.O++ OOOO://OOO.OOOOOOOOO.OOO/O++-OOO-OOOO/
OOO.OOOO.OOOO.OOOOO.O-O++
OOOO://OOO.OOOOOOO.OOOOOO.OOO.OOO/~OOO/OOOO/OOO-OOOOO.OOOO

Says a _jerk_ who is using his sig as a commercial.

Jack Klein's sig, which you apparently found so offensive you felt the
need to obfuscate it, contains his name and homepage (which is hardly
unusual), plus links to three FAQs which are extremely helpful to
readers of this newsgroup. (One could could argue the topicality of
the comp.lang.c++ FAQ, but topicality rules don't apply to sigs.) For
that matter, his homepage could be considered a form of harmless
advertising, but it also contains links to some useful information.

Quick summary: You're wrong.
 
M

Moonie

try this....Moonie

you might need to use -DUSE_WIN32 or -DUSE_DOS or -DUSE_LINUX
and if using win32 to include windows and use dos to include dos.h an
i believe i have include the right headers for linux..off topic o
course. you can scream at my programming later.



#include <time.h>

void DELAY( int msec )
{ clock_t goal;
goal = (clock_t) msec + clock();
while ( goal > clock() );
}


#if defined(USE_WIN32)

void DoSound( unsigned int freq, unsigned int time )
{
Beep( freq, time );
return;
}

#elif defined(USE_DOS)
#if defined(__DJGPP__)
#undef nosound

void nosound(void)
{
sound(0);
return;
}

void DoSound(unsigned int freq, unsigned int time)
{
sound(freq);
DELAY(time);
nosound();
return;
}
#elif defined(HAVE_SOUND)
void DoSound(unsigned int freq, unsigned int time)
{
sound(freq);
DELAY(time);
nosound();
return;
}
#else
#ifndef LOBYTE
#define LOBYTE(w) ((BYTE) (w))
#endif

#ifndef HIBYTE
#define HIBYTE(w) ((BYTE) (((USHORT) (w) >> 8) & 0xFF))
#endif

EXTERN void HWSound( unsigned );
EXTERN void HWNoSound( void );

void HWSound(unsigned int freq)
{
USHORT counter = 1193280 / freq; /* cycle counter */

outp(0x43, 0xB6); /* prepare timer */
outp(0x42, LOBYTE(counter)); /* send low byte */
outp(0x42, HIBYTE(counter)); /* send high byte */
outp(0x61, inp(0x61) | 0x03); /* turn speaker ON */
return;
}

void HWNoSound(void)
{
outp(0x61, inp(0x61) & 0xFC); /* turn speaker OFF */
return;
}

void DoSound(unsigned int freq, unsigned int time)
{
HWSound(freq);
DELAY(time);
HWNoSound();
return;
}

#endif
#else
#include <asm/io.h>
#include <signal.h>
#include <stdio.h>

#define outp outb
#define inp inb

#ifndef LOBYTE
#define LOBYTE(w) ((BYTE) (w))
#endif

#ifndef HIBYTE
#define HIBYTE(w) ((BYTE) (((USHORT) (w) >> 8) & 0xFF))
#endif

EXTERN void HWSound( unsigned );
EXTERN void HWNoSound( void );

void HWSound(unsigned int freq)
{
USHORT counter = 1193280 / freq; /* cycle counter */

outp(0x43, 0xB6); /* prepare timer */
outp(0x42, LOBYTE(counter)); /* send low byte */
outp(0x42, HIBYTE(counter)); /* send high byte */
outp(0x61, inp(0x61) | 0x03); /* turn speaker ON */
return;
}

void HWNoSound(void)
{
outp(0x61, inp(0x61) & 0xFC); /* turn speaker OFF */
return;
}

void DoSound(unsigned int freq, unsigned int time)
{
HWSound(freq);
DELAY(time);
HWNoSound();
return;
}
#endi


-
Mooni
 
J

joshua crawford

Moonie said:
try this....Moonie

you might need to use -DUSE_WIN32 or -DUSE_DOS or -DUSE_LINUX
and if using win32 to include windows and use dos to include dos.h and
i believe i have include the right headers for linux..off topic of
course. you can scream at my programming later.

Thanks. I don't use windows, and turbo c already has sound(). The linux
code segfaults on the first outp(). Looking at the man page, it seems
outb() must be
preceeded by a call to ioperm(), which needs root permissions. I
already have a solution that works for root (using ioctl()) from
comp.unix.programmer. Thanks again, anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top