# Simple bell

**URL:** <https://discourse.libsdl.org/t/simple-bell/11190>\
**Category:** SDL Development\
**Created:** [August 21, 2004, 5:43pm UTC](https://discourse.libsdl.org/t/simple-bell/11190 "2004-08-21T17:43:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Harper](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/scott_harper/32/349_2.png) [@Scott\_Harper](https://discourse.libsdl.org/u/Scott_Harper)\
**Post date:** [August 21, 2004, 5:43pm UTC](https://discourse.libsdl.org/t/simple-bell/11190/1 "2004-08-21T17:43:42Z")

</div>

RenE J.V. Bertin wrote:

> Hello,
> 
> I’ve been looking for a very simple SDL\_bell or SDL\_beep functionality,

Um… The only thing I could really think of is to just write your own  
function that plays a brief sound clip of a bell or a beep, and then  
call it like you otherwise would.

–Scott

---

<div class="post-metadata">

**Author:** ![David\_Olofson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_olofson/32/115_2.png) [@David\_Olofson](https://discourse.libsdl.org/u/David_Olofson)\
**Post date:** [August 21, 2004, 6:09pm UTC](https://discourse.libsdl.org/t/simple-bell/11190/2 "2004-08-21T18:09:21Z")

</div>

That might have been my PC-speaker hack. It has three output  
“drivers”; Linux Console (Linux-only AFAIK, and works only for root  
unless you’re actually running in a real Linux text console), X  
(XBell() obviously) and SDL audio (any platform with digital audio  
output; uses a simple PC speaker synth).

You could just throw the sound effect sequencer stuff away and use the  
speaker driver/emulator layer. It has a Borland/DOS style  
sound()/nosound() API for real time control. Doesn’t get much simpler  
than that, I think…

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.  
| Free/Open Source audio engine for games and multimedia. |  
| MIDI, modular synthesis, real time effects, scripting,… |  
`-----------------------------------\> [http://audiality.org](http://audiality.org) -’  
— [http://olofson.net](http://olofson.net) — [http://www.reologica.se](http://www.reologica.se) —On Thursday 19 August 2004 22.11, RenE J.V. Bertin wrote:

> Hello,
> 
> I’ve been looking for a very simple SDL\_bell or SDL\_beep  
> functionality, something like the XBell() function, just to play an  
> alert to the user (or rather, subject: I’m preparing to use SDL in  
> psychophysics experiments). Google showed my attempts to implement  
> some sort of PC speaker driver, but nothing easily useful for what  
> I have in mind. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Donny\_Viszneki](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/donny_viszneki/32/360_2.png) [@Donny\_Viszneki](https://discourse.libsdl.org/u/Donny_Viszneki)\
**Post date:** [August 21, 2004, 10:54pm UTC](https://discourse.libsdl.org/t/simple-bell/11190/3 "2004-08-21T22:54:46Z")

</div>

> Hello,
> 
> I’ve been looking for a very simple SDL\_bell or SDL\_beep  
> functionality, something like the XBell() function, just to play an  
> alert to the user (or rather, subject: I’m preparing to use SDL in  
> psychophysics experiments). Google showed my attempts to implement  
> some sort of PC speaker driver, but nothing easily useful for what I  
> have in mind.  
> Any suggestions?

What, may I ask, are psycho physics?On Aug 19, 2004, at 4:11 PM, RenE J.V. Bertin wrote:

> Thanks!
> 
> RenE Bertin
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Brian\_Raiter](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@Brian\_Raiter](https://discourse.libsdl.org/u/Brian_Raiter)\
**Post date:** [August 22, 2004, 4:21am UTC](https://discourse.libsdl.org/t/simple-bell/11190/4 "2004-08-22T04:21:45Z")

</div>

> I’ve been looking for a very simple SDL\_bell or SDL\_beep  
> functionality, something like the XBell() function, just to play an  
> alert to the user

I second that! In my own SDL code I’ve done it this way:

#ifdef WIN32  
#include “windows.h”  
void ding(void)  
{  
MessageBeep(0);  
}  
#else  
void ding(void)  
{  
fputc(‘\a’, stderr);  
fflush(stderr);  
}  
#endif

My code has only been ported to Windows and Linux, and I have  
absolutely no idea if any of the other platforms (Mac, Be, etc) need  
special handling, too.

It would definitely be useful if SDL had a portable function that  
supplied this.

b

---

<div class="post-metadata">

**Author:** ![Pierre\_G\_Richard](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@Pierre\_G\_Richard](https://discourse.libsdl.org/u/Pierre_G_Richard)\
**Post date:** [August 22, 2004, 8:05am UTC](https://discourse.libsdl.org/t/simple-bell/11190/5 "2004-08-22T08:05:54Z")

</div>

I wrote a beep(freq, duration) just sending a sine wave to SDL\_Audio and  
playing with both the AudioSpec.freq and loop time in the callback.

Looks like a sledge-hammer for a simple bell, but, if you have the need for  
playing a wave, this doesn’t add much to your existing code.

I can post the code here if anyone is interested.

Petrus
