473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 8400
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alexander Schmolck | last post by:
This is only partly a python question, but what is the easiest way to get python to (reliably) beep under linux? By reliably I mean that ``print "\b"`` won't do because it depends on the terminal...
19
by: Anon Email | last post by:
Hi everyone, Let's see, now. This question is about the capabilities of ANSI C++. I want to write and compile code in ANSI C++ that, when compiled, will make the computer speaker beep; or, at...
5
by: a.dheeraj.kumar | last post by:
How to play wav files through the internal speaker?
2
by: Hai Ly Hoang | last post by:
Hi, I want to make a beep from PC speaker (like C++ beep(), not a beep from sound-card). How to do that ? Thanks
1
by: strancho | last post by:
hi guys: i am rather new to C++. By using beep(hz, duration), I figured out a way to drive computer speaker. However, my project requires me to create sound from the sound card. Do you happen...
10
by: gentsquash | last post by:
Can javascript (easily) produce a click from the PC-speaker? This is the speaker that is (well, used to be) directly on the CPU-card and was -I believe- intended to give feedback to the typist,...
4
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, This is for a WPF (3.5) application. We have a requirement to produce sounds on an internal speaker (in the case that no external sound device is available). I know of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.