[RoarAudio] Micro HowTo: Notify Beeps ala ^G/XBell() with RoarAudio

Philipp Schafft lion at lion.leolix.org
Sat Feb 27 23:00:30 CET 2010


flum,

with version 0.3beta5 (next release, current snapshots) RoarAudio will
come with a new feature called 'notify beeps'. Those are small sounds
which the server generates to notify the user about some event. This is
about that a console does when sending ^G or the XBell of the X Window
System (X11).

How do I use this feature?
first you need to have a connection to the server. You can create one
using roar_simple_connect(). After you are done you need to use
roar_disconnect() to disconnect from the server.
Notes:
0) You can of cause use the same connection as you use for other work
with RoarAudio. One connection per server is all you need.
1) If you do use the connection in small time intervals you can keep the
connection open. The meaning of 'small' is up to you: this may be from
1/10 secs up to some mins.
2) As soon as you disconnect from the server all running beeps will be
killed. You will need to keep the server connection open at least the
time the beep plays plus some extra ms for network/... lateny.

If you have a open connection to the server you can send notify beeps
using roar_beep(). It takes two arguments: the connection and a struct
that contains infos about the beep.
The most simple way to send a beep is using defaults:
 roar_beep(&con, NULL);

If you pass NULL as beep info struct you will get a beep with defaults.

If we want some custom beep we need to use the info struct:
 struct roar_beep beep;
 memset(&beep, 0, sizeof(beep));
 roar_beep(&con, &beep);

if you set all values in the struct to zero the server will use
defaults. This means that both given examples will result in the same
beep.

Now we can modify the beep:
 struct roar_beep beep;
 memset(&beep, 0, sizeof(beep));
 beep->time = 1000; // 1 sec in ms
 beep->freq = 523;  // 523 Hz = 'C'
 roar_beep(&con, &beep);

This will result in a beep of 523Hz for one sec.

Here is a list of all members of the struct:
 vol     - Volume 1..ROAR_BEEP_MAX_VOL,
           0 is a specal case, will result in ROAR_BEEP_DEFAULT_VOL
 time    - The time of the beep in ms, 1..ROAR_BEEP_MAX_TIME
           0 is a specal case, will result in ROAR_BEEP_DEFAULT_TIME
 freq    - The frequency of the beep in Hz, 1..ROAR_BEEP_MAX_FREQ
           0 is a specal case, will result in ROAR_BEEP_DEFAULT_FREQ
 type    - The type of the notify. see <libroar/beep.h> for a list.
           0 is a specal case, will result in ROAR_BEEP_TYPE_DEFAULT
 x, y, z - The possition of the sound relative to the listener.
           -ROAR_BEEP_MAX_POS..+ROAR_BEEP_MAX_POS
           The server may reject beeps if those values can not be
           represented (by the used channel mapping of the
           Waveform mixer). Use 0 as default.

Note: The defaults may be overwritten by roard depending on user config.
Because of this you should use 0 for defaults, not set the defaults
explicitly.

The possition information can be used to give the user a 'feeling' of
there the notify came form. This can for example be the possition of the
window or object on screen what raises the notify.
Example:
If you have a screen with width xmax and a event at possition xpos the
resulting possition for RoarAudio xroar will be:
 xroar = ROAR_BEEP_MAX_POS * (2*xpos - xmax)/xmax



Maybe this small howto helps somebody. Comments are wellcome.

-- 
Philipp.
 (Rah of PH2)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.keep-cool.org/pipermail/roaraudio/attachments/20100227/cbdd461a/attachment.pgp>


More information about the RoarAudio mailing list