Ring a bell

My application exits when ESCAPE is pressed. However, if another key is
pressed I’d like the application to make a sound (like an error bell
sound, like those you get when you pressed all the keys on the keyboard
at once sometimes). Is there an SDL function to do this? If not, just
some simple C++ way to do this should help.

My application exits when ESCAPE is pressed. However, if another key
is pressed I’d like the application to make a sound (like an error
bell sound, like those you get when you pressed all the keys on the
keyboard at once sometimes). Is there an SDL function to do this?

Not that I know of… If it needs to be SDL, you’d have to implement
it over the SDL audio API - but then you’d have the advantage of
having full control.

If not, just some simple C++ way to do this should help.

Well, this is totally platform dependent, and different platforms
provide different levels of control… Does your application need to
run on more than one platform?

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

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 06 May 2007 16:28, Manuel Garc?a Cabrera wrote:

David Olofson escribi?:> On Sunday 06 May 2007 16:28, Manuel Garc?a Cabrera wrote:

My application exits when ESCAPE is pressed. However, if another key
is pressed I’d like the application to make a sound (like an error
bell sound, like those you get when you pressed all the keys on the
keyboard at once sometimes). Is there an SDL function to do this?

Not that I know of… If it needs to be SDL, you’d have to implement
it over the SDL audio API - but then you’d have the advantage of
having full control.

If not, just some simple C++ way to do this should help.

Well, this is totally platform dependent, and different platforms
provide different levels of control… Does your application need to
run on more than one platform?

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

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If it’s gonna be platform dependent, never mind.

[…]

If it’s gonna be platform dependent, never mind.

Well, it’s like one line of code per platform - but even so, it’s
pretty hard to get it right without actually testing on each
platform…

You might want to have a look at my “speaker” hack over here:
http://olofson.net/mixed.html

Haven’t looked at that code in a long time, but I believe the SDL part
should be pretty portable. For a simple beep, you can drop pretty
much everything but the SDL audio setup code and the callback, I
think.

You should definitely drop the CONSOLE (Linux only, and requires root
privileges unless you’re actually running from a Linux text console)
and XBELL (X11 only) targets.

Or maybe even simpler; make a callback that just beeps at all times,
and use SDL_PauseAudio() to switch it on and off. Or even open/close
audio altogether. (No point in wasting cycles playing silence at all
times - but AFAIK, SDL audio will do just that if you just use
SDL_PauseAudio(), as that’s only meant to detach the callback.)

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

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 06 May 2007 21:26, Manuel Garc?a Cabrera wrote:

You probable want to use SDL_Mixer.

http://www.kekkai.org/roger/sdl/mixer/

See part 2: Making a noise. Substitute “error bell” for noise and some
logic like if (key != ESC) and you should be all set.

ChrisOn 5/6/07, Manuel Garc?a Cabrera wrote:

My application exits when ESCAPE is pressed. However, if another key is
pressed I’d like the application to make a sound (like an error bell
sound, like those you get when you pressed all the keys on the keyboard
at once sometimes). Is there an SDL function to do this? If not, just
some simple C++ way to do this should help.


E-Mail: Chris Nystrom <@Chris_Nystrom>
Saving the world from web programming.
http://www.newio.org/ - AIM: nystromchris