Execute Beep

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Execute Beep

Phoenix
Hello,
you can implement a method like "Beep (frequency, duration, volume)" that works by creating the sound directly in the buffer without having any audio files.
Also is there a chance to run Midi files with UOS?

 Thanks in any case
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
>
Phoenix wrote
Hello,
you can implement a method like "Beep (frequency, duration, volume)" that works by creating the sound directly in the buffer without having any audio files.
Hello.

Do you want a new method Beep(frequency, duration, volume) ?
It is possible to do it with AddFromSynth().

Phoenix wrote
Also is there a chance to run Midi files with UOS?
It is in the todo list.

Fre;D
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

Phoenix
Hello,

ok thanks,
i did not see AddFromSynth ()

meantime.. i was inspired by seeing these:
http://openal.996291.n3.nabble.com/Waveform-and-queued-buffers-td5047.html
https://gitlab.vanderhoning.net/mvdhoning/doal/blob/master/Tutorials/17/Unit1.pas

I was thinking of something like that:

 procedure TTestClass.LoadBeep;
  Const
   dim = 22050;
  Var
   i, input,output: Integer;
   thebuffer: array of cfloat;
   thebufferinfos: TuosF_BufferInfos;
  begin
   SetLength(thebuffer,dim);
   for i:= 0 to dim-1 do
    thebuffer[i]:= Round(100 * Sin(i * (2 * pi) / 50.0) + 128);

   with thebufferinfos do
   begin
    SampleRate      := 44100;//44100 div 4
    SampleRateRoot  := SampleRate;
    SampleFormat    := 0;//float
    Channels        := 1;//mono
    Filename        := '';
    Title           := '';
    Copyright       := '';
    Software        := '';
    Artist          := '';
    Comment         := '';
    Date            := '';
    //Tag             := ;
    Album           := '';
    //Genre           := ;
    //HDFormat        := ;
    //Sections        := ;
    //Encoding        := ;
    //bitrate         := 192*1000;
    //Length          := ;
    LibOpen         := 0;
    Ratio           := 2;
   end;

   input:= uos_AddFromMemoryBuffer(line,thebuffer,thebufferinfos, -1, -1);
   if input = -1 then
    raise Exception.Create('');

   output:= uos_AddIntoDevOut(line,-1,-1,
             uos_InputGetSampleRate(line,input),
             uos_InputGetChannels(line,input), 0,-1);
   if output = -1 then
    raise Exception.Create('');

   uos_InputSetLevelEnable(line,input, 2);
   //uos_InputAddDSPVolume(line,input, 1,1); ???
  end;    

But i can not change the volume (maybe there is a mistake): if you enable the line "???" i do not hear the sound properly (on Windows 10).
Also there is probably something that can be improved (thebufferinfos values, ..)

Can you do something like using AddFromSynth ()?
The idea would be to avoid Sleep () for the duration of the beep (seen in the example "consolesynth" that uses AddFromSynth ()).

 PS. Using a Beep () method you could use the "morseTL" example without audio files

  Thank You
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
Phoenix wrote
i did not see AddFromSynth ()
Hello.

There is consolesynth.pas demo to show how to use it.


Phoenix wrote
But i can not change the volume (maybe there is a mistake): if you enable the line "???" i do not hear the sound properly (on Windows 10).
Did you try with the  consolesynth.pas demo ?
Here no problems.


Fre;D
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

Phoenix
Hello,

fredvs wrote
Did you try with the  consolesynth.pas demo ?
It is ok.
I would like to try a solution without using "sleep ()" for the duration of the sound.

fredvs wrote
Here no problems.
I tested LoadBeep; In linux it does not output the beep then with or without the line "uos_InputAddDSPVolume" you get the same result.

In Windows 10 without "uos_InputAddDSPVolume" I get the correct beep while with "uos_InputAddDSPVolume" fails (like linux).

Is this a bug?

  Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
Phoenix wrote
I tested LoadBeep; In linux it does not output the beep then with or without the line "uos_InputAddDSPVolume" you get the same result.

In Windows 10 without "uos_InputAddDSPVolume" I get the correct beep while with "uos_InputAddDSPVolume" fails (like linux).

Is this a bug?

  Thanks
Hello.

OK, I will test it asap (I am overbooked now ).

Thanks to note it.

Fre;D


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
In reply to this post by Phoenix
Phoenix wrote
I tested LoadBeep; In linux it does not output the beep then with or without the line "uos_InputAddDSPVolume" you get the same result.

  Thanks
I did not try yet to use uos_InputAddDSPVolume() for synthesizer but why not using simply :

InputSetSynth(InputIndex: cint32; Frequency: float; VolumeL: float; VolumeR: float; Enable : boolean);
  // Frequency : in Hertz (-1 = do not change)
  // VolumeL :  from 0 to 1 (-1 = do not change)
  // VolumeR :  from 0 to 1 (-1 = do not change)
  // Enabled : true or false ;

If you only want to change the volume, just do:

InputSetSynth(InputIndex, -1, VolumeL, VolumeR, true);

PS: I will chek uos_InputAddDSPVolume() for synthetizer ASAP.

Fre;D
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

Phoenix
Hello.
Certainly, as a second alternative i will use InputSetSynth().
Changing volume does not cause any problems.

fredvs wrote
I did not try yet to use uos_InputAddDSPVolume() for synthesizer..
fredvs wrote
I will check uos_InputAddDSPVolume() for synthetizer ASAP
Note: in my "LoadBeep", uos_InputAddDSPVolume() is for uos_AddFromMemoryBuffer() not for uos_AddFromSynth()

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
Phoenix wrote
Note: in my "LoadBeep", uos_InputAddDSPVolume() is for uos_AddFromMemoryBuffer() not for uos_AddFromSynth()
Ha, OK. (I did not understood that  )

Huh... asap.

Fre;D
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
This post was updated on .
In reply to this post by Phoenix
Hello Phoenix.

In your code:

thebuffer[i]:= Round(100 * Sin(i * (2 * pi) / 50.0) + 128);

---> you rounded the data (to get integer ?).

But in thebufferinfos:

SampleFormat := 0;//float

So it could not work.

Try to use float data (from -1 to 1) or SampleFormat > 0   (int32 -->.SampleFormat = 1, int16 -->.SampleFormat = 2)

PS: In last commit 3e05121..698958b , added Duration parameter for AddFromSynth() / InputSetSynth(). You may define now the duration of the synth sound.

Fre;D
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

Phoenix
Hello,
I did not control the range for audio data: my stupid error.
Windows 10 also works with incorrect data: it's sad

I've changed scale [-1..1] is now working,
thanks for the added "duration" parameter.

Thanks so much!!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execute Beep

fredvs
Administrator
Phoenix wrote
I've changed scale [-1..1] is now working,
thanks for the added "duration" parameter.
Yep, I am happy that it works.

In very last commit 698958b..b6e8af7, if duration = 0 ---> endless wave.

Fre;D


Loading...