CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Sound

General discussion

by cyracks » 29 Sep 2017 23:20

Hello,

I would like to know if it is possible to create a beep like sound with any mobile component ?
(I am creating inventory mobile app which will allow users to scan inventory barcodes and I would like to produce two different sounds. One indicating successful match and other indicating error in code reading)

Thx, Tomaž
cyracks
 
Posts: 92
Joined: 09 Feb 2016 12:47

by assapan » 02 Oct 2017 08:24

What i have done , is when i show a frame for error i do run a beep script
Code: Select all
JQDialogOptions.OnOpen.Script:=BeepScript(UserSession.Parametres.BeepErreur,True)


Code: Select all
function BeepScript(Params: string; AvecEntete: Boolean; EntreAccolades: Boolean = true): string;
var
  Duree, Frequence: Integer;
  Types: String;
begin
{$IFNDEF NOBEEP}
  ExtraitParametresBeep(Params, Duree, Frequence, Types);
  Result := format('beep(%d,%d,1,''%s'');', [Duree, Frequence, Types]);

  if EntreAccolades then
    Result := '{' + Result + '}';

  if AvecEntete then
    Result := 'function (e)' + Result;
{$ELSE}
  Result := '';
{$ENDIF}
end;

procedure AddBeepScript(PreHeader: TStringList);
begin
{$IFNDEF NOBEEP}
  PreHeader.Add('<script>');
  PreHeader.Add('  //if you have another AudioContext class use that one, as some browsers have a limit');
  PreHeader.Add('var audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext);');
  PreHeader.Add('');
  PreHeader.Add('//All arguments are optional:');
  PreHeader.Add('');
  PreHeader.Add('//duration of the tone in milliseconds. Default is 500');
  PreHeader.Add('//frequency of the tone in hertz. default is 440');
  PreHeader.Add('//volume of the tone. Default is 1, off is 0.');
  PreHeader.Add('//type of tone. Possible values are sine, square, sawtooth, triangle, and custom. Default is sine.');
  PreHeader.Add('//callback to use on end of tone');
  PreHeader.Add('function beep(duration, frequency, volume, type, callback) {');
  PreHeader.Add('    var oscillator = audioCtx.createOscillator();');
  PreHeader.Add('    var gainNode = audioCtx.createGain();');
  PreHeader.Add('');
  PreHeader.Add('    oscillator.connect(gainNode);');
  PreHeader.Add('    gainNode.connect(audioCtx.destination);');
  PreHeader.Add('');
  PreHeader.Add('    if (volume){gainNode.gain.value = volume;};');
  PreHeader.Add('    if (frequency){oscillator.frequency.value = frequency;}');
  PreHeader.Add('    if (type){oscillator.type = type;}');
  PreHeader.Add('    if (callback){oscillator.onended = callback;}');
  PreHeader.Add('');
  PreHeader.Add('    oscillator.start();');
  PreHeader.Add('    setTimeout(function(){oscillator.stop()}, (duration ? duration : 500));');
  PreHeader.Add('};');
  PreHeader.Add('</script>');
{$ENDIF}
end;
Want to visit Ardeche http://leclosdelarc.fr/index.php
The Pont d’Arc Cavern http://en.cavernedupontdarc.fr
Image
User avatar
assapan
 
Posts: 600
Joined: 16 Dec 2013 12:04
Location: France

by cyracks » 02 Oct 2017 21:28

Hi assapan.

thank you for trying to help. Could you please also copy the definition of "ExtraitParametresBeep" procedure, now i get error: "Undeclared identifier: 'ExtraitParametresBeep'"

Regards,
Tomaž
cyracks
 
Posts: 92
Joined: 09 Feb 2016 12:47

by assapan » 03 Oct 2017 07:59

Hi,
you don't need it ,
Duree, = duration
Frequence = frequency
, Types = type

have a look to source
Code: Select all
//duration of the tone in milliseconds. Default is 500');
//frequency of the tone in hertz. default is 440');
//volume of the tone. Default is 1, off is 0.');
//type of tone. Possible values are sine, square, sawtooth, triangle, and custom. Default is sine.'
Want to visit Ardeche http://leclosdelarc.fr/index.php
The Pont d’Arc Cavern http://en.cavernedupontdarc.fr
Image
User avatar
assapan
 
Posts: 600
Joined: 16 Dec 2013 12:04
Location: France

by cyracks » 07 Oct 2017 22:42

Thank you assapan, it works.

Clarification for other beginners :)

1) Script needs to be put to page header
uses ServerController
...
AddBeepScript(IWServerController.HTMLHeaders);

2) function BeepScript should set script on event
IWCGJQMButton1.JQMButtonOptions.Events.OnVClick.Script := BeepScript(True);
cyracks
 
Posts: 92
Joined: 09 Feb 2016 12:47


Return to General

cron

Who is online

Users browsing this forum: No registered users and 2 guests

Contact Us.