BEEP command

Previous topic - Next topic

Quentin

for those who wants it :)) sadly for windows only

tested it under Win XP. As far as I know (from MSDN) under Win 7 the sound is played not by the pc speaker but with the sound card.

Parameters:
p_freq: frequency of the sound
p_duration: duration of the sound in millisec I guess

Code (glbasic) Select

LOCAL mx%, my%, b1%, b2%

WHILE TRUE
PRINT "Press left mouse button to BEEP!", 0, 0
MOUSESTATE mx, my, b1, b2
IF b1
glbeep(RND(255), 200)
ENDIF
SHOWSCREEN
WEND

FUNCTION dummy:
ENDFUNCTION

// ------------------------------------------------------------- //
// ---  GLBEEP  ---
// ------------------------------------------------------------- //
INLINE
DECLARE(Beep, "kernel32.dll", (unsigned int, unsigned int), bool);
ENDINLINE
FUNCTION glbeep: p_freq%, p_duration%
INLINE
Beep(p_freq, p_duration);
ENDINLINE
ENDFUNCTION // GLBEEP

Kitty Hello

on *nix you can try shellcmd with the beep command:
beep -n -f 1500 -l 2000 -n 200 -l 3000

Neurox

Quote from: Kitty Hello on 2010-Sep-16
on *nix you can try shellcmd with the beep command:
beep -n -f 1500 -l 2000 -n 200 -l 3000

Well and on GP2X ?  =D
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Cliff3D

#3
Many thanks Quentin, and Kitty.

Don't GP machines use a modified version of Linux?

I've currently expanded to:

Code (glbasic) Select
// ------------------------------------------------------------- //
// ---  GLBEEP  ---
// ------------------------------------------------------------- //
FUNCTION glbeep: p_freq%, p_duration%
SELECT PLATFORMINFO$("")
CASE "WIN32"
INLINE
DECLARE(Beep, "kernel32.dll", (unsigned int, unsigned int), bool);
ENDINLINE
INLINE
Beep(p_freq, p_duration);
ENDINLINE
CASE "LINUX"
LOCAL fRESULT, command$
command$="beep -f "+p_freq%+" -l "+p_duration%
SHELLCMD(command$, FALSE, FALSE, fRESULT)
ENDSELECT
ENDFUNCTION // GLBEEP


in the hopes of some cross-platform combatability.

Curiously, most of the search results I came across looking for the syntax to the "Beep" command for Linux gave me characters to send to stdout or actually ways to code a beep in C for Linux. I still can't help thinking that a GLBasic command supported across platofrms would be most consistent, but as a slightly kuldgy workaround this is coming across as very handy so far :D thanks :D

Quentin

good idea, but I'm not sure if you're able to compile this for Linux because of the DECLARE statement with a Windows specific part ("kernel32.dll")


Cliff3D

oops, no sooner mentioned than adjusted!

I'd like to be able to write and compile for as many platforms as possible with the minimum amount of hassle/platform-specific code, so a routine like this is second only to having it bhuilt into GLBasic, to me :)

Kitty Hello

you'd need an ?IFDEF WIN32...?ENDIF

also, using IMPORT "C" __stdcall int beep(int, int);

should work on Windows, too. - no INLINE required.

Cliff3D

Thanks. I don't have enough GLBasic experience/skill to ge tthe IMPORT working, but I managed to use the ?ifdef to hopefully improve things a little:

Code (glbasic) Select
// ------------------------------------------------------------- //
// ---  GLBEEP  ---
// ------------------------------------------------------------- //
FUNCTION glbeep: p_freq%, p_duration%
?IFDEF WIN32
INLINE
DECLARE(Beep, "kernel32.dll", (unsigned int, unsigned int), bool);
ENDINLINE
INLINE
Beep(p_freq, p_duration);
ENDINLINE
?ENDIF

?IFDEF LINUX
LOCAL fRESULT, command$
command$="beep -f "+p_freq%+" -l "+p_duration%
SHELLCMD(command$, FALSE, FALSE, fRESULT)
?ENDIF
ENDFUNCTION // GLBEEP


I'm sure it could be better/more efficient, but it seems to work (on Windows at least)

Neurox

Good job!  :booze:

this is for test :-)
Code (glbasic) Select

LOCAL LNtime = 200
glbeep( 284,LNtime )
glbeep( 586,LNtime)
glbeep( 426,LNtime )
glbeep( 379,LNtime)
glbeep( 758,LNtime )
glbeep( 426,LNtime)
glbeep( 716,LNtime )
glbeep( 426,LNtime)
glbeep( 284,LNtime )
glbeep( 568,LNtime)
glbeep( 426,LNtime )
glbeep( 379,LNtime)
glbeep( 758,LNtime )
glbeep( 426,LNtime)
glbeep( 716,LNtime )
glbeep( 426,LNtime)
glbeep( 319,LNtime )
glbeep( 568,LNtime)
glbeep( 426,LNtime )
glbeep( 426,LNtime)
glbeep( 716,LNtime )
glbeep( 426,LNtime)
glbeep( 319,LNtime )
glbeep( 568,LNtime)
glbeep( 426,LNtime )
glbeep( 379,LNtime)
glbeep( 758,LNtime )
glbeep( 426,LNtime)

Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Hemlos

Sorry to bring this back up..but something is wrong on my system i think...
I have been working on a project, and i wanted to use this functionality in windows.
Ive tried these code bits using windows xp sp3, and they all cause the program to crash when the function is called.
Any ideas?

Bing ChatGpt is pretty smart :O

Kitty Hello

More elegant way:
Code (glbasic) Select

IMPORT "C" int __stdcall Beep(int, int)

Beep(500,100)

Win32, only.

Schranz0r

Quote from: Kitty Hello on 2011-Jul-04
More elegant way:
Code (glbasic) Select

IMPORT "C" int __stdcall Beep(int, int)

Beep(500,100)

Win32, only.

Owned! :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Gary

No sound on win xp 32bit here :(

MrTAToad

Same here - but it does work in Windows 7  :blink:

Hemlos

its working on w32 xp sp3 for me.

you might need to turn on your motherboard internal speaker in your bios.

put those 2 lines at the top of any program, and itll beep.
Bing ChatGpt is pretty smart :O