Recent

Author Topic: UOS - Sound recording in a memory buffer  (Read 1697 times)

Loic

  • Newbie
  • Posts: 2
UOS - Sound recording in a memory buffer
« on: March 03, 2023, 01:19:06 pm »
Dear all,

I am trying to use UOS library.
The objective is to record the sound from my microphone.
To store the sound in a buffer.
Then to display the signal in a chart (like an oscilloscope).
The code below does not work at all. => But I don't know why?

uos_CreatePlayer(SoundPlayerIndex);

SampleRate := 44100;
SampleFormat := 2; // Int16
Channels := 1; // Mono
FramesCount := 65536;

// saving in a Memory-Buffer:
SetLength(SoundBuffer, 0);
uos_AddIntoMemoryBuffer(SoundPlayerIndex, @SoundBuffer, SampleRate, SampleFormat, Channels, FramesCount);

uos_AddFromDevIn(SoundPlayerIndex);
uos_Play(SoundPlayerIndex);

sleep(3000); // Duration of recording (I don't know?)
uos_Stop(SoundPlayerIndex);
ShowMessage('Recording done');

// Diplaying in a chart
ChartSignalLine.Clear;
for p := Low(SoundBuffer) to High(SoundBuffer) do
  ChartSignalLine.AddXY(p/SampleRate*1e3, SoundBuffer[p]);

Other question, how can I do that if the recording has 2 channels?
Many thanks in advance for your reply

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: UOS - Sound recording in a memory buffer
« Reply #1 on: March 03, 2023, 03:24:08 pm »
Hello Loic.

Did you try the uos examples consoleplaymemorybuffer and simplerecorder ?
Are they working ?

For uos only problems, please use uos-forum: http://uos-forum.108.s1.nabble.com

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

Loic

  • Newbie
  • Posts: 2
Re: UOS - Sound recording in a memory buffer
« Reply #2 on: March 04, 2023, 11:06:13 am »
Hi Fred,

Thanks. Yes, I had a deep look at the examples, specifically the ones you cited.
I wasn't aware of the uos-forum. I am gonna post this issue on it.
Regards

Loic

 

TinyPortal © 2005-2018