SRL Archive - SRL Archives

Beep Plugin


Aftermath

2011-11-22 00:19:29

I made this for my amusement to use while playing semi-afk or to alert me when encountering a random.

Here's the API:


function Beep(freq, duration: ShortInt): Boolean;
function MessageBeep(id: Word): Boolean;

function BEEP_SIMPLE(): Word;
function BEEP_ERROR(): Word;
function BEEP_WARNING(): Word;
function BEEP_QUESTION(): Word;
function BEEP_INFORMATION(): Word;
function BEEP_OK(): Word;

The first two are the beeping functions you should use.

Beep is a hardware beep requiring an 8254 sound chip which may not work on newer computers which don't have the chip. If there is hardware support, it will beep even if software sound is disabled (unless hardware sound is also disabled). Beep will not work in Vista or XP 64-bit machines.

The frequency is in Hertz and ranges between 37 through 32,767. The duration is in milliseconds.

MessageBeep is a software beep that uses the standard Windows sounds you have set up in your control panel. To get there, go to Control Panel -> Sounds -> Sounds tab. The argument is the return value of one of the six BEEP_NAME functions listed above .

Control Panel sound correspondence (to change the sounds):

  • BEEP_SIMPLE: May not be changed. You can use this if you want to make sure that the sound is heard regardless of Control Panel configuration.
  • BEEP_ERROR: Windows Critical Stop.
  • BEEP_WARNING: Windows Exclamation.
  • BEEP_QUESTION: Windows Question.
  • BEEP_INFORMATION: Windows Asterisk.
  • BEEP_OK: Windows Default Beep.
BEEP_SIMPLE may not be changed. You can use this if you want to make sure that the sound is heard regardless of Control Panel configuration.

Both beep functions return false if they fail, or true if they succeed. If you call MessageBeep with an argument other than those provided in the six BEEP_NAME functions, it will return false, though it may play a sound nonetheless.

Here is a testing script to try out the plugin:

{Aftermath 11/22/11}
program BeepDemo;
var success: Boolean;
var freq, duration: ShortInt;
{$Loadlib SimbaBeep}
begin
freq := 750;
duration := 300;

WriteLn('Beep Test');
success := Beep(freq, duration);
WriteLn('Hardware beep: ' + BoolToStr(success));

Wait(1000);
success := MessageBeep(BEEP_SIMPLE);
WriteLn('Software beep SIMPLE: ' + BoolToStr(success));

Wait(1000);
success := MessageBeep(BEEP_ERROR);
WriteLn('Software beep ERROR: ' + BoolToStr(success));

Wait(1000);
success := MessageBeep(BEEP_WARNING);
WriteLn('Software beep WARNING: ' + BoolToStr(success));

Wait(1000);
success := MessageBeep(BEEP_QUESTION);
WriteLn('Software beep QUESTION: ' + BoolToStr(success));

Wait(1000);
success := MessageBeep(BEEP_INFORMATION);
WriteLn('Software beep INFORMATION: ' + BoolToStr(success));

Wait(1000);
success := MessageBeep(BEEP_OK);
WriteLn('Software beep OK: ' + BoolToStr(success));
end.

To install, place the attached DLL in your Plugins directory. The DLL is for use with 32-bit Simba only. This shouldn't matter much since 64-bit Simba is a buggy piece of trash anyway :)

I've attached the source. You'll need to make a Win32 DLL project in Visual Studio, and use the .def file for the module definition.

Harry

2011-11-22 01:01:40

Please post source code of the DLL.

Wizzup?

2011-11-22 06:15:41

FYI: http://docs.villavu.com/simba/scriptref/sound.html?highlight=playsound

Looking over the API, it looks good. Didn't actually test it due to lack of source code. ;)

Aftermath

2011-11-22 20:16:19

I have attached the source and the module definitions file.

nielsie95

2011-11-23 14:35:56

Cool :)
Simple, yet effective.

Aftermath

2011-11-24 20:06:05

I use this to AFK train to tell me when my prayers ran out.

program Timer;
{$Loadlib SimbaBeep}
const ToWait = 142000;
begin
Wait(ToWait);
MessageBeep(BEEP_OK);
end.

Wizzup?

2011-11-24 20:09:01

From: nielsie95
Cool :)
Simple, yet effective.


It reminds me of my Runite miner which would play the ``Halleluja'' sound (Holy hand grenade in World World Party) every time it mined a Runite ore… ;)

Source looks good.

kingarabian

2011-11-24 20:16:39

Anyway to make this send the user a text-message or an email?

Aftermath

2011-11-24 20:25:35

Of course, though if I were to make routines to send an SMS, I wouldn't put it in a plugin called 'SimbaBeep'. That's an interesting idea though, I might make that sometime.

Edit: Did some experiments with sending SMS programmatic - the current method I'm using seems to require knowing the recipient's carrier, which would be a stumbling block to a clean API. I may look for another way later

Edit 2: In the United States, text messages most often charge the receiver only, meaning that I can send to U.S. numbers for free by knowing their carriers. To send internationally, or without bothering to look up the carriers, I would need to use a pay service, which I'm not willing to pay for. So that about wraps up the discussion of my writing anything of the sort.

Edit 3: Of course, I might use this to SMS myself :D Though I doubt there'd be any reason to since I would never use bots while not keeping track of them.