468,514 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

linux speaker beep

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?

Nov 14 '05 #1
9 7986
jg********@gmail.com <jg********@gmail.com> scribbled the following:
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.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"B-but Angus! You're a dragon!"
- Mickey Mouse
Nov 14 '05 #2

<jg********@gmail.com> wrote

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.
Nov 14 '05 #3

Joona I Palaste wrote:
jg********@gmail.com <jg********@gmail.com> scribbled the following:
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.


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.

Nov 14 '05 #4
On 18 Sep 2004 08:15:13 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote in comp.lang.c:
jg********@gmail.com <jg********@gmail.com> scribbled the following:
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.


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
news:comp.os.linux.development.apps.

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

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #5
Jack Klein wrote:
On 18 Sep 2004 08:15:13 GMT, Joona I Palaste
<pa*****@cc.helsinki.fi> wrote in comp.lang.c:
jg********@gmail.com <jg********@gmail.com> scribbled the
following:
> 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.


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 news:comp.os.linux.development.apps.

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.

Nov 14 '05 #6
Emmet Gorhsen wrote:
Jack Klein wrote:
On 18 Sep 2004 08:15:13 GMT, Joona I Palaste
<pa*****@cc.helsinki.fi> wrote in comp.lang.c:
jg********@gmail.com <jg********@gmail.com> scribbled the
following:

> 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.


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 news:comp.os.linux.development.apps.

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.


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.

Nov 14 '05 #7
Emmet Gorhsen <go*****@sailaway.net> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8

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
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 14 '05 #9
Moonie wrote:
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.

Nov 14 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Alexander Schmolck | last post: by
19 posts views Thread by Anon Email | last post: by
5 posts views Thread by a.dheeraj.kumar | last post: by
2 posts views Thread by Hai Ly Hoang | last post: by
10 posts views Thread by gentsquash | last post: by
4 posts views Thread by =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.