coding help needed: How to grab live audio into Buffer and analyze?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

coding help needed: How to grab live audio into Buffer and analyze?

Frank Schiller
Hi all,

I've been trying to use uos with Lazarus (1.8.0-rc4 on linux64).
What I want to: listen to MIC and show level

my code:
  uos_CreatePlayer( 0 );
  InputIndex1 := uos_AddFromDevIn( 0 );                // Input from IN Device
  writeln('InputIndex1 : ' + inttostr(inputIndex1));
  uos_AddIntoFile( 0, 'waveform-record.wav' ); // Output into OUT Device
 uos_InputSetLevelEnable(0,InputIndex1,1);
 uos_InputAddDSP1ChanTo2Chan(0,InputIndex1);
 uos_InputAddDSPVolume(0,InputIndex1, 1, 1);
  DSPIndex:=  uos_InputAddDSP (0,0,@DSPfs,nil,nil,nil);
  uos_InputSetDSP(0, InputIndex1, DSPIndex, true);
  uos_AddIntoDevOut(0);
  uos_LoopEndProc(0,@InLoopMem);
  uos_EndProc(0, @ClosePlayer1);
  uos_Play(0); // Listen your mic with DSP effects...

where
procedure TForm1.InLoopMem;
begin
    label4.caption:= timetostr(now()) + ' Level = ' + floattostr(uos_InputGetLevelLeft(0,InputIndex1));
//    label4.caption:= timetostr(now()) + ' Size = ' + floattostr(length(waveformdata));
  writeln(timetostr(now()) + ' inLoop. InputIndex1=' + floattostr(InputIndex1));
end;            

and
function DSPfs(var Data: TuosF_Data; var fft: TuosF_FFT): TDArFloat ;
begin
   writeln('Input #chan       : ' + floattostr(data.Channels));
   writeln('Input #LevelEnable: ' + floattostr(data.LevelEnable));
   writeln('Input #TYPE       : ' + floattostr(data.TypePut));
   writeln('Input #posmem: ' + floattostr(data.posmem  ));
   writeln('Input Position: ' + floattostr(data.));
end;      

But: I can't find values of the incoming sound. Where do I have to look for it?

I have attached some code (modified example waveform.lpi, I added a "REC" Botton)

Maybe you can push me into the right direction :-)
Reply | Threaded
Open this post in threaded view
|

Re: coding help needed: How to grab live audio into Buffer and analyze?

fredvs
Administrator
Hello Frank.

> But: I can't find values of the incoming sound. Where do I have to look for it

Sorry, I do not understand.

Do you want the value in live, like for the demo SimplePlayer view-meters ?

If yes, take a look at SimplePlayer code:

...
    uos_LoopProcIn(PlayerIndex1, InputIndex1, @LoopProcPlayer1);
    ///// Assign the procedure of object to execute inside the loop

In your code you should change:

 uos_LoopEndProc(0,@InLoopMem);

with

 uos_LoopProcIn(0,0,@InLoopMem);

Fre;D







Reply | Threaded
Open this post in threaded view
|

Re: coding help needed: How to grab live audio into Buffer and analyze?

fredvs
Administrator
In reply to this post by Frank Schiller
Re-hello.

>  writeln('Input #chan       : ' + floattostr(data.Channels));

Are you using LCL widget (Lazarus)?

If yes, you should not use writeln() with LCL, it will generate a crash of your application in Windows.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: coding help needed: How to grab live audio into Buffer and analyze?

Frank Schiller
In reply to this post by fredvs
Hi fred,
thanks for your 2 quick replies.
and: yepp!

1. It works: I can read out the Buffer after changing this:
 In your code you should change:   uos_LoopEndProc(0,@InLoopMem);
with                                              uos_LoopProcIn(0,0,@InLoopMem);

et voila.

2. Yes, I ment something like your example "simplerecorder".

and (last):
those funny writeln - statements do work in Linux as debugout. I don't need them in real coding.  :-)

Great :-)