Recent

Author Topic: [UOS/PortAudio] Minimizing Audio Latency?  (Read 3584 times)

Hobbit1972

  • New Member
  • *
  • Posts: 25
[UOS/PortAudio] Minimizing Audio Latency?
« on: February 06, 2023, 01:00:43 pm »
Hi!

I'm using UOS (with PortAudio lib) to route MicIn to SpkOut:
Code: Pascal  [Select][+][-]
  1.   uos_CreatePlayer(0);
  2.   uos_AddIntoDevOut(0);
  3.   uos_AddFromDevIn(0);
  4.   uos_Play(0);
  5.  

This gives me quite audible latency between in and out. I Tried to fiddle with the paramters of AddFromDevIn like
Code: Pascal  [Select][+][-]
  1.  uos_AddFromFrvIn(0,-1,4,-1,-1,-1,128,-1);
but this doesn't change much.

Is there some way to reduce latency here?

Tx!

Fred vS

  • Hero Member
  • *****
  • Posts: 3256
    • StrumPract is the musicians best friend
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #1 on: February 06, 2023, 02:39:53 pm »
Hello.

Please take a look at the examples in /uos/examples/.
There is also a uos-forum: http://uos-forum.108.s1.nabble.com/

Thanks.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #2 on: February 06, 2023, 02:51:43 pm »
@Hobbit1972

Which OS, which SoundCard, which AudioDriver do You use ?

Did You try ASIO or JACK (JACK@GitHub) ?

On Windows, I use PortAudio together with ASIO4ALL to obtain incredible, crystal-clear low-latency Sound
with Audios and Videos(!) with my FFmpeg-based Audio/Video-RenderingEngine FFPlay4Laz.
« Last Edit: February 06, 2023, 03:01:10 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #3 on: February 06, 2023, 03:00:09 pm »
@Fred vS: any particular example touching latency in mind?
The latency value is seconds? milliseconds? foo units?  :)

@metis:
Win11 64bit. Out-of-the-box card&driver of my mainboard. As the program should run on different platforms, general ideas would be appreciated.

Tx


Fred vS

  • Hero Member
  • *****
  • Posts: 3256
    • StrumPract is the musicians best friend
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #4 on: February 06, 2023, 03:13:14 pm »
@Fred vS: any particular example touching latency in mind?
The latency value is seconds? milliseconds? foo units?  :)

Please try SimplePlayer demo.
About latency: http://www.portaudio.com/docs/latency.html

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3256
    • StrumPract is the musicians best friend
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #5 on: February 06, 2023, 03:22:09 pm »
Hi!

I'm using UOS (with PortAudio lib) to route MicIn to SpkOut:

Re-hello.

Did you try the simplerecorder.lpi example?
Is the sound ok?
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #6 on: February 06, 2023, 03:36:20 pm »
@Fred vS:
Yes, SimplePlayer runs and is okay. Except "play revers" where it gets jumpy.


Fred vS

  • Hero Member
  • *****
  • Posts: 3256
    • StrumPract is the musicians best friend
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #7 on: February 06, 2023, 03:55:34 pm »
@Fred vS:
Yes, SimplePlayer runs and is okay. Except "play revers" where it gets jumpy.

Ha, ok, ( hum, jumpy with what kind of audio files, mp3, wav, ogg, ... ?)

And what about SimpleRecorder, is the mic-input to output sound ok ?
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #8 on: February 06, 2023, 04:16:05 pm »
@Fred vS:
Yes, SimplePlayer runs and is okay. Except "play revers" where it gets jumpy.

Ha, ok, ( hum, jumpy with what kind of audio files, mp3, wav, ogg, ... ?)

And what about SimpleRecorder, is the mic-input to output sound ok ?

ogg. plays backwards till it reaches 0:00:00.743, jumps to 0:00:01.114, plays backwards... and so on...

Recorder: let me check that out...

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #9 on: February 06, 2023, 04:18:41 pm »
And what about SimpleRecorder, is the mic-input to output sound ok ?

SimpleRecorder: I'd say latency is ~1/4s, just like in my program.

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #10 on: February 06, 2023, 04:23:13 pm »
@Fred vS:
FYI: as the compiler threw an error not knowing which overloed function to use, I made this change in uos.pas:
Code: Pascal  [Select][+][-]
  1.           if StreamIn[x].AACI.lwDataLen > (StreamIn[x].AACI.BitsPerSample div 8) then
  2.             StreamIn[x].Data.outframes := trunc(comp(StreamIn[x].AACI.lwDataLen) Div (StreamIn[x].AACI.
  3.                                           BitsPerSample Div 8))
  4.  
I added comp() to get it to work.

Fred vS

  • Hero Member
  • *****
  • Posts: 3256
    • StrumPract is the musicians best friend
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #11 on: February 06, 2023, 04:26:58 pm »
ogg. plays backwards till it reaches 0:00:00.743, jumps to 0:00:01.114, plays backwards... and so on...

Ok, I will check this asap with ogg files, write you later.

[EDIT] Ha, ok, I see, it is wanted  ;).
If reverse-song reach to begin, there is a loop with first chunck.
This reverse effect is to show how to use the uos-dsp feature, feel free to adapt the code like you want.

SimpleRecorder: I'd say latency is ~1/4s, just like in my program.

Sorry but I did not understand.  :-[
Is the sound ok or not?
« Last Edit: February 06, 2023, 06:45:56 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3256
    • StrumPract is the musicians best friend
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #12 on: February 06, 2023, 04:28:38 pm »
@Fred vS:
FYI: as the compiler threw an error not knowing which overloed function to use, I made this change in uos.pas:
Code: Pascal  [Select][+][-]
  1.           if StreamIn[x].AACI.lwDataLen > (StreamIn[x].AACI.BitsPerSample div 8) then
  2.             StreamIn[x].Data.outframes := trunc(comp(StreamIn[x].AACI.lwDataLen) Div (StreamIn[x].AACI.
  3.                                           BitsPerSample Div 8))
  4.  
I added comp() to get it to work.

Please give the error you get from the compiler.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #13 on: February 06, 2023, 04:30:36 pm »
SimpleRecorder: I'd say latency is ~1/4s, just like in my program.

Sorry but I did not understand.  :-[
Is the sound ok or not?

Sound is (and was alaways) okay, but processing time (=latency) is too long for my purposes. Between me speaking in the mic and hearing my voice in the speaker is ~250ms  :o

ofc Win was and is a pain in the a** concerning these kind of things.  :(

Hobbit1972

  • New Member
  • *
  • Posts: 25
Re: [UOS/PortAudio] Minimizing Audio Latency?
« Reply #14 on: February 06, 2023, 04:32:07 pm »
@Fred vS:
FYI: as the compiler threw an error not knowing which overloed function to use, I made this change in uos.pas:
Code: Pascal  [Select][+][-]
  1.           if StreamIn[x].AACI.lwDataLen > (StreamIn[x].AACI.BitsPerSample div 8) then
  2.             StreamIn[x].Data.outframes := trunc(comp(StreamIn[x].AACI.lwDataLen) Div (StreamIn[x].AACI.
  3.                                           BitsPerSample Div 8))
  4.  
I added comp() to get it to work.

Please give the error you get from the compiler.

Here you go:
Code: Pascal  [Select][+][-]
  1. uos.pas(10381,43) Error: Can't determine which overloaded function to call

 

TinyPortal © 2005-2018