Difference between revisions of "uos"

From Free Pascal wiki
Jump to navigationJump to search
 
(21 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[File:uoslogo.png|right]]
 
[[File:uoslogo.png|right]]
 +
 
'''uos''' (United OpenLib of Sound) is a multi-platform package of audio handling routines that unifies the best open-source audio libraries.
 
'''uos''' (United OpenLib of Sound) is a multi-platform package of audio handling routines that unifies the best open-source audio libraries.
  
== Features ==
+
= Features =
 +
 
 
* play .mp3, .ogg, .wav, .flac, .m4a, .opus and cdrom audio files.
 
* play .mp3, .ogg, .wav, .flac, .m4a, .opus and cdrom audio files.
 
* 16, 32 or float 32 bit resolution
 
* 16, 32 or float 32 bit resolution
Line 9: Line 11:
 
* play multiple inputs and outputs simultaneously
 
* play multiple inputs and outputs simultaneously
 
* internet audio streaming of mp3 and opus files.
 
* internet audio streaming of mp3 and opus files.
 +
* produce sound by the build-in synthesizer.
  
 
Uos can use the [[SoundTouch]], [[PortAudio]], [[SndFile]], [[Mpg123]], [[Faad]], [[OpusFile]] and [[Mp4ff]] audio libraries.  
 
Uos can use the [[SoundTouch]], [[PortAudio]], [[SndFile]], [[Mpg123]], [[Faad]], [[OpusFile]] and [[Mp4ff]] audio libraries.  
  
Included in the package:  Examples and binary libraries for Linux 32/64, arm-Rapsberry Pi, Windows 32/64, Mac OSX 32 and FreeBSD 32/64.  
+
Included in the package:  Examples and binary libraries for Linux 32/64, arm aarch64 Raspberry Pi, Windows 32/64, macOS 32/64 and FreeBSD 32/64.
 +
 
 +
= Download =
  
== Download ==
 
 
* http://fredvs.github.io/uos/
 
* http://fredvs.github.io/uos/
* http://github.com/fredvs/uos/
+
* https://github.com/fredvs/uos/tree/main
 +
 
 +
= Forum =
 +
 
 +
*  http://uos-forum.108.s1.nabble.com
 +
 
 +
= uoslib =
 +
 
 +
Pascal users should use uos instead.
 +
 
 +
'''uoslib''' is the Universal Library version of '''uos''' unit and is accessible from Pascal and all other languages (C, Java, ...).
  
== Forum (You are welcome.) ==
+
Some methods of uos are not accessible.
* http://uos.2369694.n4.nabble.com
 
  
== uoslib ==
+
Included in the package:  Examples and binary libraries for Linux 32/64, Windows 32/64, macOS 32/64 and FreeBSD 32/64.  
'''uoslib''' is the Universal Library version of '''uos''' unit and is accessible from Pascal and all other languages (C, Java, ...)
 
  
Included in the package:  Examples and binary libraries for Linux 32/64, Windows 32/64, Mac OSX 32 and FreeBSD 32/64.
 
 
* http://fredvs.github.io/uoslib/
 
* http://fredvs.github.io/uoslib/
 
* http://github.com/fredvs/uoslib/
 
* http://github.com/fredvs/uoslib/
  
== Install ==
+
= Install =
The best way to show how uos works is to look at the examples in uos/uoslib packages.
+
 
 +
The best way to show how uos works is to look at the examples in /uos/examples package.
 
All is included, you only have to compile the demos and run it...
 
All is included, you only have to compile the demos and run it...
  
 
Here some examples how to use uos :
 
Here some examples how to use uos :
 +
 
* Copy all the files in /uos/src/ into the directory of your project.
 
* Copy all the files in /uos/src/ into the directory of your project.
 
* add ''uos_flat'' or ''uos'' in your uses section. (for uoslib add ''uoslib_h'')
 
* add ''uos_flat'' or ''uos'' in your uses section. (for uoslib add ''uoslib_h'')
 
** ''uos_flat'' => All is done by the unit. The procedures are more "universal", same syntax as uoslib.
 
** ''uos_flat'' => All is done by the unit. The procedures are more "universal", same syntax as uoslib.
 
** ''uos''  => The application must declare uos class and variables. The procedures can be used as oop way.
 
** ''uos''  => The application must declare uos class and variables. The procedures can be used as oop way.
* All the examples in uos packages uses ''uos_flat''. There is a example using ''uos'' => SimplePlayer_noflat
+
* All the examples in uos packages use ''uos_flat''. There is a example using only ''uos'' => SimplePlayer_noflat
  
 
Those libraries can be used by uos:
 
Those libraries can be used by uos:
 +
 
* PortAudio for dealing with audio devices of sound card,
 
* PortAudio for dealing with audio devices of sound card,
 
* SndFile for decoding wav, flac, org audio files,
 
* SndFile for decoding wav, flac, org audio files,
Line 49: Line 63:
  
 
You may load those libraries with:
 
You may load those libraries with:
 +
 
  uos_LoadLib( pchar(PortAudioFileName), pchar(SndFileFileName), pchar(Mpg123FileName),  pchar(Mp4ffFileName), pchar(FaadFileName), pchar(OpusFileFileName) );
 
  uos_LoadLib( pchar(PortAudioFileName), pchar(SndFileFileName), pchar(Mpg123FileName),  pchar(Mp4ffFileName), pchar(FaadFileName), pchar(OpusFileFileName) );
  
 
If some libraries are not needed, just replace the filename with "nil".
 
If some libraries are not needed, just replace the filename with "nil".
 +
 +
If you replace the filename with pchar('system'), the library of the system will be used (if exists).
 +
 +
WARNING: Do not forget to call '''uos_free()''' when application terminates.
 
   
 
   
Play a file 'MySong.mp3'
+
Play a file 'MySong.mp3':
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
begin
 
begin
 
   uos_LoadLib( PortAudioFileName, nil, Mpg123FileName,  nil, nil, nil); // only PortAudio and Mpg123 are needed.  
 
   uos_LoadLib( PortAudioFileName, nil, Mpg123FileName,  nil, nil, nil); // only PortAudio and Mpg123 are needed.  
Line 63: Line 83:
 
   uos_Play(0);                        // Play the song...
 
   uos_Play(0);                        // Play the song...
 
end;
 
end;
 +
...
 +
uos_free;                            // Call this at end of application. 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Play a sound file with some dsp effects (only for uos, in future for uoslib too):
 
Play a sound file with some dsp effects (only for uos, in future for uoslib too):
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
begin
 
begin
 
   uos_LoadLib( pchar(PortAudioFileName), nil, pchar(Mpg123FileName), nil, nil, nil); // only PortAudio and Mpg123 are needed.
 
   uos_LoadLib( pchar(PortAudioFileName), nil, pchar(Mpg123FileName), nil, nil, nil); // only PortAudio and Mpg123 are needed.
Line 72: Line 95:
 
   uos_AddIntoDevOut( 0 );            // Add Output with default parameters     
 
   uos_AddIntoDevOut( 0 );            // Add Output with default parameters     
 
   uos_AddFromFile( 0, 'MySong.mp3' ); // Input from audio file  
 
   uos_AddFromFile( 0, 'MySong.mp3' ); // Input from audio file  
   uos_AddDSPIn( 0, 1 );              // Add as many dsp effects you want
+
   uos_InputAddDSP( 0, 1 );              // Add as many dsp effects you want
   uos_AddDSPIn( 0, 2 );
+
   uos_InputAddDSP( 0, 2 );
 
   uos_Play( 0 );                      // Play the song with DSP effect...
 
   uos_Play( 0 );                      // Play the song with DSP effect...
 
end;
 
end;
 +
...
 +
uos_free;                            // Call this at end of application. 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Listen to your mic into your loudspeakers (for uoslib too) :
 
Listen to your mic into your loudspeakers (for uoslib too) :
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
begin
 
begin
 
   uos_LoadLib( pchar(PortAudioFileName), nil, nil, nil, nil, nil); // only PortAudio is needed.
 
   uos_LoadLib( pchar(PortAudioFileName), nil, nil, nil, nil, nil); // only PortAudio is needed.
Line 87: Line 113:
 
   uos_Play( 0 );          // Listen to your mic in your loudspeakers...
 
   uos_Play( 0 );          // Listen to your mic in your loudspeakers...
 
end;
 
end;
 +
...
 +
uos_free;                            // Call this at end of application. 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now, ear your mic, listen to a mp3, apply some effects and record the mic into wav file at same time:
+
Now, listen to your mic, listen to a mp3, apply some effects and record the mic into wav file at same time:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
begin
 
begin
 
   uos_LoadLib( pchar(PortAudioFileName), pchar(SndFileFileName), pchar(Mpg123FileName), nil, nil, nil);
 
   uos_LoadLib( pchar(PortAudioFileName), pchar(SndFileFileName), pchar(Mpg123FileName), nil, nil, nil);
 
   uos_CreatePlayer( 0 );
 
   uos_CreatePlayer( 0 );
 
   uos_AddIntoDevOut( 0 ) ;              // Output into OUT Device
 
   uos_AddIntoDevOut( 0 ) ;              // Output into OUT Device
   uos_AddIntoFile( 0, 'Myrecord.wav' ); // Output into OUT Device
+
   uos_AddIntoFile( 0, 'Myrecord.wav' ); // Output into wav file
 
   uos_AddFromDevIn( 0 );                // Input from IN Device
 
   uos_AddFromDevIn( 0 );                // Input from IN Device
   uos_AddDSPIn( 0, 1 );                 // Add as many dsp's you want
+
   uos_InputAddDSP( 0, 1 );             // Add as many dsp's you want
   uos_AddDSPIn( 0, 2 );
+
   uos_InputAddDSP( 0, 2 );
 
   uos_CreatePlayer( 1 );
 
   uos_CreatePlayer( 1 );
   uos_AddFromFile( 1, 'MySong.mp3' ); // the background audio file
+
   uos_AddFromFile( 1, 'MySong.mp3' );   // the background audio file
   uos_AddIntoDevOut( 1 ) ;             // Output into OUT1 Device;
+
   uos_AddIntoDevOut( 1 ) ;             // Output into OUT1 Device;
  
   uos_Play(0);                         // Listen your mic with DSP effects and record it ...
+
   uos_Play(0);                         // Listen your mic with DSP effects and record it ...
   uos_Play(1);                         // Listen to mp3 while recording
+
   uos_Play(1);                         // Listen to mp3 while recording
 
end;
 
end;
 +
...
 +
uos_free;                              // Call this at end of application. 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Syntax ==
+
= Syntax =
Here are the basic uos procedures. Each procedure has its equivalent with arguments for custom parameters.
+
 
 +
Here are the basic uos methods. Each method has its equivalent with arguments for custom parameters.
 +
 
 +
Initialization methods:
  
Initialization Procedures:
 
 
  uos_LoadLib( );              // Load dynamic libraries for uos   
 
  uos_LoadLib( );              // Load dynamic libraries for uos   
 
  uos_LoadLibs( );            // Load dynamic libraries for uoslibs
 
  uos_LoadLibs( );            // Load dynamic libraries for uoslibs
 
  uos_UnLoadLib();            // To unload libraries.
 
  uos_UnLoadLib();            // To unload libraries.
 
  uos_Free;                    // To use when application terminate.
 
  uos_Free;                    // To use when application terminate.
 +
 
Output
 
Output
 +
 
  uos_AddIntoDevOut();        // Output into OUT Device
 
  uos_AddIntoDevOut();        // Output into OUT Device
 
  uos_AddIntoFile();          // Output into Wav File
 
  uos_AddIntoFile();          // Output into Wav File
 +
uos_AddIntoMemoryBuffer()    // Add a Output into memory buffer
 +
uos_AddIntoMemoryStream()    // Add a Output into memory stream
 +
uos_AddIntoIceServer()      // Add a Output into a IceCast server
 +
uos_AddIntoFileFromMem()    // Add a Output into audio wav file from TMemoryStream
 +
 
Input
 
Input
 +
 
  uos_AddFromDevIn();          // Input from IN device
 
  uos_AddFromDevIn();          // Input from IN device
 
  uos_AddFromFile();          // Input from Audio File
 
  uos_AddFromFile();          // Input from Audio File
 +
uos_AddFromMemoryBuffer();  // Input from decoded pcm buffer
 +
uos_AddFromMemoryStream();  // Input from a TMemoryStream of Audio File
 +
uos_AddFromFileIntoMemory(); // Input from audio file and stored into memory buffer
 
  uos_AddFromURL();            // Input from internet URL mp3/opus files
 
  uos_AddFromURL();            // Input from internet URL mp3/opus files
  uos_AddFromSynth(;          // Input form built-in Synthetizer
+
  uos_AddFromSynth(;          // Input form built-in Synthesizer
  uos_InputLength();          // Lenght of Input in samples
+
  uos_InputLength();          // Length of Input in samples
 
  uos_InputPosition();        // Get position
 
  uos_InputPosition();        // Get position
  uos_Seek();                 // Change position
+
  uos_InputSeek();             // Change position in byte
 +
uos_InputSeekTime();        // Change position in time
 +
uos_InputSeekSeconds();      // Change position in second
 +
 
 
Player
 
Player
 +
 
  uos_Play();                  // Start playing
 
  uos_Play();                  // Start playing
 +
uos_PlayPaused();            // Start playing paused.
 
  uos_PlayNoFree();            // Start playing but do not free the player after stop.
 
  uos_PlayNoFree();            // Start playing but do not free the player after stop.
  uos_FreePlayer();           // Free the player. Works only when PlayNoFree() was used.
+
  uos_PlayPausedNoFree();     // Start playing paused but do not free the player after stop.
 
  uos_RePlay();                // Resume playing after pause
 
  uos_RePlay();                // Resume playing after pause
 
  uos_Stop();                  // Stop playing and free thread
 
  uos_Stop();                  // Stop playing and free thread
 
  uos_Pause();                // Pause playing
 
  uos_Pause();                // Pause playing
 +
uos_FreePlayer();            // Free the player. Works only when PlayNoFree() was used.
 +
 
DSP
 
DSP
  uos_AddDSPIn()               // DSP procedure for input
+
 
  uos_AddDSPOut()             // DSP procedure for output
+
  uos_InputAddDSP()           // DSP procedure for input
  uos_SetDSPin()               // Set DSP In
+
  uos_OutputAddDSP()           // DSP procedure for output
  uos_SetDSPout()             // Set DSP out
+
  uos_InputSetDSP()           // Set DSP In
  uos_SetDSPVolumeIn(...)     // Set Volume
+
  uos_OutputSetDSP()           // Set DSP out
  uos_AddFilterIn(...)         // Add filer
+
  uos_InputSetDSPVolume(...)   // Set Volume
 +
  uos_InputAddFilter(...)     // Add filer
 
  uos_AddPlugin(...)          // Add pluggin
 
  uos_AddPlugin(...)          // Add pluggin
 +
 
And much more other procedures/functions (see in uos.pas...)
 
And much more other procedures/functions (see in uos.pas...)
  
 +
[[Category:Lazarus]]
 
[[Category:Libraries]]   
 
[[Category:Libraries]]   
 
[[Category:Audio]]
 
[[Category:Audio]]

Latest revision as of 02:29, 8 August 2021

uoslogo.png

uos (United OpenLib of Sound) is a multi-platform package of audio handling routines that unifies the best open-source audio libraries.

Features

  • play .mp3, .ogg, .wav, .flac, .m4a, .opus and cdrom audio files.
  • 16, 32 or float 32 bit resolution
  • record all types of input into file, in 16 or 32 bit resolution, mono or stereo.
  • add DSP effects and filters, however many you want and record it.
  • play multiple inputs and outputs simultaneously
  • internet audio streaming of mp3 and opus files.
  • produce sound by the build-in synthesizer.

Uos can use the SoundTouch, PortAudio, SndFile, Mpg123, Faad, OpusFile and Mp4ff audio libraries.

Included in the package: Examples and binary libraries for Linux 32/64, arm aarch64 Raspberry Pi, Windows 32/64, macOS 32/64 and FreeBSD 32/64.

Download

Forum

uoslib

Pascal users should use uos instead.

uoslib is the Universal Library version of uos unit and is accessible from Pascal and all other languages (C, Java, ...).

Some methods of uos are not accessible.

Included in the package: Examples and binary libraries for Linux 32/64, Windows 32/64, macOS 32/64 and FreeBSD 32/64.

Install

The best way to show how uos works is to look at the examples in /uos/examples package. All is included, you only have to compile the demos and run it...

Here some examples how to use uos :

  • Copy all the files in /uos/src/ into the directory of your project.
  • add uos_flat or uos in your uses section. (for uoslib add uoslib_h)
    • uos_flat => All is done by the unit. The procedures are more "universal", same syntax as uoslib.
    • uos => The application must declare uos class and variables. The procedures can be used as oop way.
  • All the examples in uos packages use uos_flat. There is a example using only uos => SimplePlayer_noflat

Those libraries can be used by uos:

  • PortAudio for dealing with audio devices of sound card,
  • SndFile for decoding wav, flac, org audio files,
  • Mpg123 for decoding mp3 audio files,
  • Faad and Mp4ff for decoding m4a audio files,
  • OpusFile for decoding opus audio files,
  • SoundTouch plugin for changing tempo of any type of audio files,
  • bs2b plugin to apply stereo to binaural effect.

You may load those libraries with:

uos_LoadLib( pchar(PortAudioFileName), pchar(SndFileFileName), pchar(Mpg123FileName),  pchar(Mp4ffFileName), pchar(FaadFileName), pchar(OpusFileFileName) );

If some libraries are not needed, just replace the filename with "nil".

If you replace the filename with pchar('system'), the library of the system will be used (if exists).

WARNING: Do not forget to call uos_free() when application terminates.

Play a file 'MySong.mp3':

begin
  uos_LoadLib( PortAudioFileName, nil, Mpg123FileName,  nil, nil, nil); // only PortAudio and Mpg123 are needed. 
  uos_CreatePlayer( 0 );              // you may create how many players you want, from 0 to to what you computer can do...
  uos_AddIntoDevOut( 0 );             // Add Output with default parameters     
  uos_AddFromFile( 0, 'MySong.mp3' ); // Input from audio file 
    // And let's play it...
  uos_Play(0);                        // Play the song...
end;
...
uos_free;                             // Call this at end of application.

Play a sound file with some dsp effects (only for uos, in future for uoslib too):

begin
  uos_LoadLib( pchar(PortAudioFileName), nil, pchar(Mpg123FileName), nil, nil, nil); // only PortAudio and Mpg123 are needed.
  uos_CreatePlayer( 0 );              // First create the player:
  uos_AddIntoDevOut( 0 );             // Add Output with default parameters     
  uos_AddFromFile( 0, 'MySong.mp3' ); // Input from audio file 
  uos_InputAddDSP( 0, 1 );               // Add as many dsp effects you want
  uos_InputAddDSP( 0, 2 );
  uos_Play( 0 );                      // Play the song with DSP effect...
end;
...
uos_free;                             // Call this at end of application.

Listen to your mic into your loudspeakers (for uoslib too) :

begin
  uos_LoadLib( pchar(PortAudioFileName), nil, nil, nil, nil, nil); // only PortAudio is needed.
  uos_CreatePlayer( 0 );     
  uos_AddIntoDevOut( 0 );   
  uos_AddFromDevIn( 0 );   // Input from IN Device
  uos_Play( 0 );           // Listen to your mic in your loudspeakers...
end;
...
uos_free;                             // Call this at end of application.

Now, listen to your mic, listen to a mp3, apply some effects and record the mic into wav file at same time:

begin
  uos_LoadLib( pchar(PortAudioFileName), pchar(SndFileFileName), pchar(Mpg123FileName), nil, nil, nil);
  uos_CreatePlayer( 0 );
  uos_AddIntoDevOut( 0 ) ;              // Output into OUT Device
  uos_AddIntoFile( 0, 'Myrecord.wav' ); // Output into wav file
  uos_AddFromDevIn( 0 );                // Input from IN Device
  uos_InputAddDSP( 0, 1 );              // Add as many dsp's you want
  uos_InputAddDSP( 0, 2 );
  uos_CreatePlayer( 1 );
  uos_AddFromFile( 1, 'MySong.mp3' );   // the background audio file
  uos_AddIntoDevOut( 1 ) ;              // Output into OUT1 Device;

  uos_Play(0);                          // Listen your mic with DSP effects and record it ...
  uos_Play(1);                          // Listen to mp3 while recording
end;
...
uos_free;                               // Call this at end of application.

Syntax

Here are the basic uos methods. Each method has its equivalent with arguments for custom parameters.

Initialization methods:

uos_LoadLib( );              // Load dynamic libraries for uos  
uos_LoadLibs( );             // Load dynamic libraries for uoslibs
uos_UnLoadLib();             // To unload libraries.
uos_Free;                    // To use when application terminate.

Output

uos_AddIntoDevOut();         // Output into OUT Device
uos_AddIntoFile();           // Output into Wav File
uos_AddIntoMemoryBuffer()    // Add a Output into memory buffer
uos_AddIntoMemoryStream()    // Add a Output into memory stream
uos_AddIntoIceServer()       // Add a Output into a IceCast server
uos_AddIntoFileFromMem()     // Add a Output into audio wav file from TMemoryStream

Input

uos_AddFromDevIn();          // Input from IN device
uos_AddFromFile();           // Input from Audio File
uos_AddFromMemoryBuffer();   // Input from decoded pcm buffer
uos_AddFromMemoryStream();   // Input from a TMemoryStream of Audio File
uos_AddFromFileIntoMemory(); // Input from audio file and stored into memory buffer
uos_AddFromURL();            // Input from internet URL mp3/opus files
uos_AddFromSynth(;           // Input form built-in Synthesizer
uos_InputLength();           // Length of Input in samples
uos_InputPosition();         // Get position
uos_InputSeek();             // Change position in byte
uos_InputSeekTime();         // Change position in time
uos_InputSeekSeconds();      // Change position in second

Player

uos_Play();                  // Start playing
uos_PlayPaused();            // Start playing paused.
uos_PlayNoFree();            // Start playing but do not free the player after stop.
uos_PlayPausedNoFree();      // Start playing paused but do not free the player after stop.
uos_RePlay();                // Resume playing after pause
uos_Stop();                  // Stop playing and free thread
uos_Pause();                 // Pause playing
uos_FreePlayer();            // Free the player. Works only when PlayNoFree() was used.

DSP

uos_InputAddDSP()            // DSP procedure for input
uos_OutputAddDSP()           // DSP procedure for output
uos_InputSetDSP()            // Set DSP In
uos_OutputSetDSP()           // Set DSP out
uos_InputSetDSPVolume(...)   // Set Volume
uos_InputAddFilter(...)      // Add filer
uos_AddPlugin(...)           // Add pluggin

And much more other procedures/functions (see in uos.pas...)