Recent

Author Topic: Is There a Manner to Make a Sound Beep System CrossPlatform??No Libs???  (Read 3606 times)

lestroso

  • Full Member
  • ***
  • Posts: 134
    • FaSasoftware
Is There a Manner to Make a Sound Beep System CrossPlatform??No Libs???

Hi i'm trying to work with lazarus ide...but i'm having problems to find any instructions to make a simple beep sound...

Now..i'm working on a mac os x..but i would like to compile for windows too ......

Can somebody help me with fresh code example crossplatforms???...thanks a lot..

Lestroso  :-[


BobDog

  • Sr. Member
  • ****
  • Posts: 394

With Liuux it should be libc.so, but windows it is 'msvcrt.dll'
The linux beeb could be 'Beep' (not necessarilly the same as windows '_beep')
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program beeps;
  4.  
  5.                                                             //libc.so   linux
  6.  
  7.  procedure beep(freq:integer;duration:integer);cdecl external 'msvcrt.dll' name '_beep';
  8. begin
  9. beep(1000,200);
  10. writeln('Press enter to end . . .');
  11. readln;
  12.  beep(200,500);
  13. end.

I wouldn't call these external libs as such, linux and Windows are written in C, so it is ever present awaiting instructions.
But some folk will disagree.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
With Liuux it should be libc.so, but windows it is 'msvcrt.dll'
[...etc...]
I wouldn't call these external libs as such, linux and Windows are written in C, so it is ever present awaiting instructions.
But some folk will disagree.

Balderdash! You don't need either, in Windows or Linux. In Windows, for example, you can use a simple system call to sndPlaySound and, probably, something similar in Linux, MacOS, etc.

LIBC should only be used when you aboslutely need compatibility with Kylix. And almost the only use of MSVCRT (that is, the MS Visual C Run-Time) is to be able to mimick exactly some piece of Visual C code. Both are external libraries, with little to do with the system itself.

So yeah, "some folk will disagree" :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Well lucamar, post an example so we can run it as a simple console application.

And hey, skip the Balderdash! and Bull, I am only putting an idea forward, lestroso can only but try it out.


Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
The link from Howardpc is correct. I based a solution on this code:
Code: Pascal  [Select][+][-]
  1. program bell;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
  3. uses sysutils;
  4.  
  5.   procedure Beepme;
  6.   begin
  7.     // this may or may not work on modern machines, but is cross-platform.
  8.     // but you can replace this body with OS specific code that actually plays a wav.
  9.     // #7 is the BELL signal from the ASCII set. If your PC has an old school internal speaker it should work.
  10.     writeln(#7);
  11.     // This makes no sound, but is just to show the beep works
  12.     writeln('Beeped');
  13.   end;
  14.  
  15. begin
  16.  // OnBeep is a global event handler declared in sysutils
  17.  // Just hook our demo
  18.  OnBeep := @BeepMe;
  19.  // and with any luck, beep...
  20.  Beep;
  21. end.

This is the preferred way to hook a cross-platform beep with just platform specific implementation.
« Last Edit: March 20, 2019, 07:32:21 pm by Thaddy »
Specialize a type, not a var.

lestroso

  • Full Member
  • ***
  • Posts: 134
    • FaSasoftware
Dear Friends!!!
I'm sorry for my bad question......I have express my self in a bad manner.....

In truth i need to play the sound of the computer system.with-or-without any libs to make cross platform..when you make an alert or show any other notify...i need the sound system play in my computer....

Can somebody help me??? thanks A lot in advance..to you...

Best regards,
Lestroso

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
That is a futile exercise, because e.g. server blades contain no sound hardware. That's also why FPC just provides the functionality I described. (Several times....)
Did you understand my answer?  Otherwise - just in this case - ask it in your native language or your second language.
« Last Edit: March 20, 2019, 09:15:57 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018