Author Topic: BEEP command  (Read 5574 times)

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
BEEP command
« on: 2010-Sep-16 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10766
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: BEEP command
« Reply #1 on: 2010-Sep-16 »
on *nix you can try shellcmd with the beep command:
beep -n -f 1500 -l 2000 -n 200 -l 3000

Offline Neurox

  • Mr. Polyvector
  • ***
  • Posts: 184
    • View Profile
    • http://www.borzini.it
Re: BEEP command
« Reply #2 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

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Re: BEEP command
« Reply #3 on: 2010-Sep-17 »
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
« Last Edit: 2010-Sep-17 by Cliff3D »

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: BEEP command
« Reply #4 on: 2010-Sep-17 »
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")


Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Re: BEEP command
« Reply #5 on: 2010-Sep-17 »
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 :)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10766
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: BEEP command
« Reply #6 on: 2010-Sep-17 »
you'd need an ?IFDEF WIN32...?ENDIF

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

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

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Re: BEEP command
« Reply #7 on: 2010-Sep-20 »
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)

Offline Neurox

  • Mr. Polyvector
  • ***
  • Posts: 184
    • View Profile
    • http://www.borzini.it
Re: BEEP command
« Reply #8 on: 2010-Sep-21 »
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

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1645
  • Particle Hawk
    • View Profile
Re: BEEP command
« Reply #9 on: 2011-Jul-03 »
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?

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10766
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: BEEP command
« Reply #10 on: 2011-Jul-04 »
More elegant way:
Code: (glbasic) [Select]
IMPORT "C" int __stdcall Beep(int, int)

Beep(500,100)
Win32, only.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5088
  • O Rly?
    • View Profile
Re: BEEP command
« Reply #11 on: 2011-Jul-05 »
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 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Gary

  • Dr. Type
  • ****
  • Posts: 313
    • View Profile
Re: BEEP command
« Reply #12 on: 2011-Jul-05 »
No sound on win xp 32bit here :(

MrTAToad

  • Guest
Re: BEEP command
« Reply #13 on: 2011-Jul-05 »
Same here - but it does work in Windows 7  :blink:

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1645
  • Particle Hawk
    • View Profile
Re: BEEP command
« Reply #14 on: 2011-Jul-05 »
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.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)