473,915 Members | 5,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8453
jg********@gmai l.com <jg********@gma il.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.progr ammer, you know where to find it.

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

<jg********@gma il.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********@gmai l.com <jg********@gma il.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.progr ammer, 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.hel sinki.fi>
wrote in comp.lang.c:
jg********@gmai l.com <jg********@gma il.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.progr ammer, you know where to find it.


Why do you keep redirecting people who specifically mention Linux in
their OT questions to comp.unix.progr ammer? Linux != UNIX. The
proper group for platform specific questions about Linux is
news:comp.os.li nux.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.l earn.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.hel sinki.fi> wrote in comp.lang.c:
jg********@gmai l.com <jg********@gma il.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.progr ammer, you know where to find it.


Why do you keep redirecting people who specifically mention
Linux in their OT questions to comp.unix.progr ammer? Linux !=
UNIX. The proper group for platform specific questions about
Linux is news:comp.os.li nux.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.O OO/O++-OOO-OOOO/
OOO.OOOO.OOOO.O OOOO.O-O++
OOOO://OOO.OOOOOOO.OOO OOO.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.hel sinki.fi> wrote in comp.lang.c:
jg********@gmai l.com <jg********@gma il.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.progr ammer, you know where to find it.


Why do you keep redirecting people who specifically mention
Linux in their OT questions to comp.unix.progr ammer? Linux !=
UNIX. The proper group for platform specific questions about
Linux is news:comp.os.li nux.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.O OO/O++-OOO-OOOO/
OOO.OOOO.OOOO.O OOOO.O-O++
OOOO://OOO.OOOOOOO.OOO OOO.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.progr ammer. My problem is mostly resolved now.

Nov 14 '05 #7
Emmet Gorhsen <go*****@sailaw ay.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.O OO/O++-OOO-OOOO/
OOO.OOOO.OOOO.O OOOO.O-O++
OOOO://OOO.OOOOOOO.OOO OOO.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_Keit h) 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_WIN 32)

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(unsigne d int freq, unsigned int time)
{
sound(freq);
DELAY(time);
nosound();
return;
}
#elif defined(HAVE_SO UND)
void DoSound(unsigne d 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(unsigne d 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(unsigne d 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(unsigne d 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(unsigne d 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.progr ammer. 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
25035
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 settings -- so I guess I'm looking for some simple way to more or less directly access the internal speaker (maybe writing to something in /dev/). 'as
19
56803
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 least, SHOULD make the computer speaker beep. I know that whether the computer speaker actually beeps or not is largely dependent on the OS I'm using. But I'm not so much concerned about that (at this stage). I just want to know if ANSI C++...
5
4079
by: a.dheeraj.kumar | last post by:
How to play wav files through the internal speaker?
2
13387
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
3162
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 to know how this works? or is there a command like that? I was going to generate it from wave file. However, it is just too cumbershome.. thanks for the help
10
2480
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, making a click-sound on each keypress. On Unix/Linux/MacOSX systems, you can hear this click by typing ^g (control g) into a shell/terminal. This is also the click made by ^g when it is typed in Emacs, or when Emacs signals an error.
4
5513
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 Console.Beep(frequency, duration), but I wondered if there is a better, more controllable way. Basically, the user will be toggling a (hardware) switch on and off. When it is on, we need to play a tone, and
0
10039
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3370
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.