Difference between revisions of "Multimedia Programming"

From Lazarus wiki
Jump to navigationJump to search
(→‎Using the OpenAL Library: Updated, expanded; fixed wiki markup)
(Re-organised into native and cross-platform; updated and expanded)
Line 5: Line 5:
 
Several [[Video_Playback_Libraries|Libraries]] exist for embedding video playback into applications.
 
Several [[Video_Playback_Libraries|Libraries]] exist for embedding video playback into applications.
  
==MPlayer for Linux gtk2/X and Windows==
+
==MPlayer==
 +
 
 +
'''mplayer''' is an open source and free movie player. It is available for Linux gtk2/X, FreeBSD, macOS and Windows.
 +
 
 +
As part of Lazarus-CCR, there is an LCL control [[TMPlayerControl]] embedding the mplayer, so you can build your own movie players or just play a video in your application. You can download the source here:
  
'''mplayer''' is an open source and free movie player. As part of Lazarus-CCR, there is a LCL control [[TMPlayerControl]] embedding the mplayer, so you can built your own movie players or just play a video in your application. You can download the source here:
 
 
<pre>
 
<pre>
svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/mplayer mplayer
+
svn checkout svn://svn.code.sf.net/p/lazarus-ccr/svn/components/mplayer mplayer
 
</pre>
 
</pre>
  
=Playing Sounds=
+
=Playing Sound=
 +
 
 +
==Native solutions==
  
==Native macOS solutions==
+
===macOS===
  
 
* [[macOS_Play_Alert_Sound|System Sound Services]] For up to 30 second sound clips, alerts etc.  
 
* [[macOS_Play_Alert_Sound|System Sound Services]] For up to 30 second sound clips, alerts etc.  
 
* [[macOS Audio Player|AVAudioPlayer]] For longer audio files with volume control, pause, stop, resume, loop control, background music etc.
 
* [[macOS Audio Player|AVAudioPlayer]] For longer audio files with volume control, pause, stop, resume, loop control, background music etc.
 +
* [[#OpenAL_Library|OpenAL]] comes pre-installed on macOS.
 +
 +
===Windows===
  
==Windows only: using the Windows API==
+
====Windows API====
  
 
You can use the Windows API to play e.g. wav files:
 
You can use the Windows API to play e.g. wav files:
Line 35: Line 43:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Obviously, this is not cross-platform
+
====Audiere Library====
 +
 
 +
Has bindings for Delphi, but they do not work with FPC:
 +
 
 +
* http://code.google.com/p/audiere-bind-delphi/
 +
 
 +
====Squall sound====
 +
 
 +
Squall sound works fine with FPC. It has 3D audio and EAX effects, but just supports MP3, OGG and WAV formats. Open sourced in 2009 and appears dead. Windows only.
 +
 
 +
https://github.com/xtreme3d/squall
  
==Using the Audio Component Suite==
 
  
For more information, read the article about the [[ACS|Audio Component Suite]]
+
==Cross Platform==
  
==Using the OpenAL Library==
+
===Audio Component Suite===
  
{{Note|The OpenAL Library Framework is pre-installed on all Apple computers running macOS -- see /System/Library/Frameworks/OpenAL.framework}}
+
For more information, read the article about the [[ACS|Audio Component Suite]]
  
A tutorial for Delphi can be found [http://www.noeska.com/doal/tutorials.aspx here].
+
===Audorra Library===
  
Free Pascal comes with a unit for accessing OpenAL located in fpc/packages/openal as well as [http://svn.freepascal.org/svn/fpc/trunk/packages/openal/examples usage examples].
+
This library works well with Lazarus:  
  
There is an alternative OpenAL sound manager unit to play wav files by [https://forum.lazarus.freepascal.org/index.php?action=profile;u=59515 Lulu] [https://github.com/Lulu04/OALSoundManager here]. Tested on macOS Mojave 10.14.
+
http://sourceforge.net/projects/audorra/
  
==BASS==
+
===BASS===
  
 
The BASS library can be downloaded from: http://www.un4seen.com/ and http://www.un4seen.com/forum/?topic=8682.0
 
The BASS library can be downloaded from: http://www.un4seen.com/ and http://www.un4seen.com/forum/?topic=8682.0
Line 58: Line 75:
 
https://sites.google.com/site/fiensprototyping/
 
https://sites.google.com/site/fiensprototyping/
  
==Audiere Library==
+
===FMOD===
  
Has bindings for Delphi, but they do not work with FPC:
+
[https://www.fmod.com/core FMOD Core] comes with an elegant API compatible with C, C++, C#, and Javascript, and runs on all major platforms. It is a closed source solution. It is free for use for non-comercial software, but requires the payment of license fees for commercial software.
  
* http://www.casteng.com/whypascal.shtml
+
===FPSound===
* http://www.afterwarp.net/resources/soundlib
 
* http://code.google.com/p/audiere-bind-delphi/
 
  
==Audorra Library==
+
FPSound is a new library being developed in the mold of fpspreadsheet and fpvectorial: it has independent modules to read, write and play sound files and also an intermediary representation for editing. See [[FPSound]]. Uses OpenAL. Appears dead and non-working.
 
 
This library works well with Lazarus:  
 
 
 
http://sourceforge.net/projects/audorra/
 
  
==OMEGA Engine==
+
===OMEGA Engine===
  
The OMEGA Engine is a full game engine in single Omega.dll file which is just 50kb. It can successfully play FLAC, OGG, MP3, MP2, AMR and WMA files. It searches and uses installed audio codecs from the system.
+
The OMEGA Engine is a full game engine in single Omega.dll file which is just 50kb. It can successfully play FLAC, OGG, MP3, MP2, AMR and WMA files. It searches and uses installed audio codecs from the system. Windows and Linux only.
  
 
http://sourceforge.net/projects/omega-engine/files/
 
http://sourceforge.net/projects/omega-engine/files/
Line 84: Line 95:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==PortAudio==
+
===OpenAL Library===
 +
 
 +
{{Note|The OpenAL Library Framework is pre-installed on all Apple computers running macOS -- see /System/Library/Frameworks/OpenAL.framework}}
 +
 
 +
OpenAL is a cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications.
 +
 
 +
The library models a collection of audio sources moving in a 3D space that are heard by a single listener somewhere in that space. The basic OpenAL objects are a Listener, a Source, and a Buffer. There can be a large number of Buffers, which contain audio data. Each buffer can be attached to one or more Sources, which represent points in 3D space which are emitting audio. There is always one Listener object (per audio context), which represents the position where the sources are heard -- rendering is done from the perspective of the Listener.
 +
 
 +
* See the [https://www.openal.org OpenAL website] for documentation, downloads etc.
 +
 
 +
* A tutorial for Delphi can be found [http://www.noeska.com/doal/tutorials.aspx here].
 +
 
 +
* Free Pascal comes with a unit for accessing OpenAL located in fpc/packages/openal as well as [http://svn.freepascal.org/svn/fpc/trunk/packages/openal/examples usage examples].
 +
 
 +
* There is an alternative OpenAL sound manager unit to play wav files by [https://forum.lazarus.freepascal.org/index.php?action=profile;u=59515 Lulu] [https://github.com/Lulu04/OALSoundManager here]. Tested on macOS Mojave 10.14.
 +
 
 +
===Play Sound Package===
 +
 
 +
The [[Play Sound Multiplatform|Play Sound Package]] take a different route to paying sound cross-platform. It searches the system for programs which will play sound and executes those asynchronously or synchronously via [[TProcess]] or [[TSsyncProcess]].
 +
 
 +
===PortAudio===
  
 
Various bindings for [http://www.portaudio.com/ PortAudio], a cross-platform, open source library for audio playback and recording are available.
 
Various bindings for [http://www.portaudio.com/ PortAudio], a cross-platform, open source library for audio playback and recording are available.
 +
 
See [[http://wiki.lazarus.freepascal.org/Multimedia_Programming#Playing_Sounds]] for some versions.
 
See [[http://wiki.lazarus.freepascal.org/Multimedia_Programming#Playing_Sounds]] for some versions.
 +
 
Forum user FredvS has written a Pascal unit that dynamically loads PortAudio: [http://lazarus.freepascal.org/index.php/topic,17521.0.html]
 
Forum user FredvS has written a Pascal unit that dynamically loads PortAudio: [http://lazarus.freepascal.org/index.php/topic,17521.0.html]
 +
 
Some examples can be found here: [http://breakoutbox.de/pascal/pascal.html#PortAudio]
 
Some examples can be found here: [http://breakoutbox.de/pascal/pascal.html#PortAudio]
  
==SDL + SDL_mixer==
+
===SDL + SDL_mixer===
  
 
The basic SDL library comes with a very simple sound system. On top of that, SDL mixer adds more sound APIs which build a more flexible solution.
 
The basic SDL library comes with a very simple sound system. On top of that, SDL mixer adds more sound APIs which build a more flexible solution.
Line 97: Line 131:
 
Units for accessing SDL libraries are located in fpc/packages/sdl.  
 
Units for accessing SDL libraries are located in fpc/packages/sdl.  
  
==FMOD==
+
===SFML/CSFML for FPC===
  
Is a closed source solution. It is free for use for non-comercial software, but requires the payment of license fees for commercial software.
+
[https://www.sfml-dev.org/ Simple and Fast Multimedia Library] aka SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. It is composed of five modules: system, window, graphics, audio and network.  With SFML, your application can compile and run out of the box on the most common operating systems: Windows, Linux, macOS and soon Android & iOS.
  
==Squall sound==
+
Pre-compiled SDKs for your favorite OS are available on the [https://www.sfml-dev.org/download.php download page].
  
Squall sound works fine with FPC. It has 3D audio and EAX effects, but just supports MP3, OGG and WAV formats.
+
CSFML headers binding for FPC can be found at https://github.com/DJMaster/csfml-fpc
  
http://www.afterwarp.net/resources/soundlib
+
===uos (United OpenLib of Sound)===
 
 
==FPSound==
 
 
 
FPSound is a new library being developed in the mold of fpspreadsheet and fpvectorial: it has independent modules to read, write and play sound files and also an intermediary representation for editing. See [[FPSound]]
 
 
 
==uos (United OpenLib of Sound)==
 
  
 
'''uos''': United OpenLib of Sound. '''uos''' unifies the best open-source audio libraries.
 
'''uos''': United OpenLib of Sound. '''uos''' unifies the best open-source audio libraries.
Line 133: Line 161:
  
 
http://github.com/fredvs/uos/
 
http://github.com/fredvs/uos/
 
==SFML/CSFML for FPC==
 
 
Simple and Fast Multimedia Library aka SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. It is composed of five modules: system, window, graphics, audio and network.
 
 
CSFML headers binding for FPC can be found at https://github.com/DJMaster/csfml-fpc
 
  
 
= Text-To-Speech =
 
= Text-To-Speech =
Line 150: Line 172:
  
 
[[Category:Multimedia]]
 
[[Category:Multimedia]]
 +
[[Category:Audio]]
 +
[[Category:Video]]

Revision as of 11:14, 28 December 2019

Deutsch (de) English (en) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

Playing Videos

Several Libraries exist for embedding video playback into applications.

MPlayer

mplayer is an open source and free movie player. It is available for Linux gtk2/X, FreeBSD, macOS and Windows.

As part of Lazarus-CCR, there is an LCL control TMPlayerControl embedding the mplayer, so you can build your own movie players or just play a video in your application. You can download the source here:

svn checkout svn://svn.code.sf.net/p/lazarus-ccr/svn/components/mplayer mplayer

Playing Sound

Native solutions

macOS

  • System Sound Services For up to 30 second sound clips, alerts etc.
  • AVAudioPlayer For longer audio files with volume control, pause, stop, resume, loop control, background music etc.
  • OpenAL comes pre-installed on macOS.

Windows

Windows API

You can use the Windows API to play e.g. wav files:

...
uses MMSystem;
...
sndPlaySound('C:\sounds\test.wav', snd_Async or snd_NoDefault);

The fail-safe way, which will allow appending paths and nonlatin file names is:

sndPlaySound(pchar(UTF8ToSys('C:\sounds\test.wav')), snd_Async or snd_NoDefault);

Audiere Library

Has bindings for Delphi, but they do not work with FPC:

Squall sound

Squall sound works fine with FPC. It has 3D audio and EAX effects, but just supports MP3, OGG and WAV formats. Open sourced in 2009 and appears dead. Windows only.

https://github.com/xtreme3d/squall


Cross Platform

Audio Component Suite

For more information, read the article about the Audio Component Suite

Audorra Library

This library works well with Lazarus:

http://sourceforge.net/projects/audorra/

BASS

The BASS library can be downloaded from: http://www.un4seen.com/ and http://www.un4seen.com/forum/?topic=8682.0

There is a DJ application, for Windows, Linux and macOS, written with Lazarus and using Bass lib: https://sites.google.com/site/fiensprototyping/

FMOD

FMOD Core comes with an elegant API compatible with C, C++, C#, and Javascript, and runs on all major platforms. It is a closed source solution. It is free for use for non-comercial software, but requires the payment of license fees for commercial software.

FPSound

FPSound is a new library being developed in the mold of fpspreadsheet and fpvectorial: it has independent modules to read, write and play sound files and also an intermediary representation for editing. See FPSound. Uses OpenAL. Appears dead and non-working.

OMEGA Engine

The OMEGA Engine is a full game engine in single Omega.dll file which is just 50kb. It can successfully play FLAC, OGG, MP3, MP2, AMR and WMA files. It searches and uses installed audio codecs from the system. Windows and Linux only.

http://sourceforge.net/projects/omega-engine/files/

The project is dead, but it is very easy to use:

Media_Play('Music.mp3', TRUE);

OpenAL Library

Light bulb  Note: The OpenAL Library Framework is pre-installed on all Apple computers running macOS -- see /System/Library/Frameworks/OpenAL.framework

OpenAL is a cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications.

The library models a collection of audio sources moving in a 3D space that are heard by a single listener somewhere in that space. The basic OpenAL objects are a Listener, a Source, and a Buffer. There can be a large number of Buffers, which contain audio data. Each buffer can be attached to one or more Sources, which represent points in 3D space which are emitting audio. There is always one Listener object (per audio context), which represents the position where the sources are heard -- rendering is done from the perspective of the Listener.

  • A tutorial for Delphi can be found here.
  • Free Pascal comes with a unit for accessing OpenAL located in fpc/packages/openal as well as usage examples.
  • There is an alternative OpenAL sound manager unit to play wav files by Lulu here. Tested on macOS Mojave 10.14.

Play Sound Package

The Play Sound Package take a different route to paying sound cross-platform. It searches the system for programs which will play sound and executes those asynchronously or synchronously via TProcess or TSsyncProcess.

PortAudio

Various bindings for PortAudio, a cross-platform, open source library for audio playback and recording are available.

See [[1]] for some versions.

Forum user FredvS has written a Pascal unit that dynamically loads PortAudio: [2]

Some examples can be found here: [3]

SDL + SDL_mixer

The basic SDL library comes with a very simple sound system. On top of that, SDL mixer adds more sound APIs which build a more flexible solution.

Units for accessing SDL libraries are located in fpc/packages/sdl.

SFML/CSFML for FPC

Simple and Fast Multimedia Library aka SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. It is composed of five modules: system, window, graphics, audio and network. With SFML, your application can compile and run out of the box on the most common operating systems: Windows, Linux, macOS and soon Android & iOS.

Pre-compiled SDKs for your favorite OS are available on the download page.

CSFML headers binding for FPC can be found at https://github.com/DJMaster/csfml-fpc

uos (United OpenLib of Sound)

uos: United OpenLib of Sound. uos unifies the best open-source audio libraries.

With uos you can:

  • Listen to mp3, ogg, wav, flac, m4a, opus, cd audio, ... audio files.
  • With 16, 32 or float 32 bit resolution.
  • Record all types of input into file.
  • Add DSP effects and filters, however many you want and record it.
  • Do web audio-streaming (listen to web-radio and apply filters).
  • Listen to multiple inputs and outputs.
  • Produce sound with built-in synthesizer.

uos can use the PortAudio, SndFile, Mpg123, Faad, Mp4ff, OpusFile audio libraries and SoundTouch, Bs2b plug-in library.

Included in the package:

  • examples.
  • binary libraries for Linux 32/64, Windows 32/64, macOS 32/64, FreeBSD 32/64 and ARM Rpi.

It can play mp3, ogg, wav, flac, m4a, opus, cda files.

http://github.com/fredvs/uos/

Text-To-Speech

See Speech Synthesis for native and cross-platform solutions.

See also