playing sound files (linux and windows)

classic Classic list List threaded Threaded
29 messages Options
12
Reply | Threaded
Open this post in threaded view
|

playing sound files (linux and windows)

Graeme Geldenhuys-2
Hi,

Has anybody managed to play sound files under both Linux and Windows?
Does FPC have a cross-platform API or FCL class for this?

If so, what sound format's are supported?  ogg, wav, mp3?

--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Henry Vermaak
On 14 June 2010 14:37, Graeme Geldenhuys <[hidden email]> wrote:
> Hi,
>
> Has anybody managed to play sound files under both Linux and Windows?
> Does FPC have a cross-platform API or FCL class for this?

fpc has bindings for libsndfile, which according to the website can
read/write wav and ogg, among others.

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Alexander Grau-2
In reply to this post by Graeme Geldenhuys-2
Graeme Geldenhuys schrieb:
> Hi,
>
> Has anybody managed to play sound files under both Linux and Windows?
> Does FPC have a cross-platform API or FCL class for this?
>
> If so, what sound format's are supported?  ogg, wav, mp3?
>
>  
We have developed some kind of API to play a .wav file on both Windows
and Mac.  The Windows version is easy (below), the Mac version is long
(400 lines).

If someone would like to add a PlaySoundFile API to LCL/FPC, drop me a
note and we will donate the Mac code for it :-) ...

Regards,
Alexander


uses windows, mmsystem;

procedure PlaySoundFile(filename: string);
begin
  PlaySound(pchar(filename), 0, SND_FILENAME + SND_ASYNC);
end;


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Graeme Geldenhuys-2
On 14/06/2010, Alexander Grau wrote:
>
> If someone would like to add a PlaySoundFile API to LCL/FPC, drop me a
> note and we will donate the Mac code for it :-) ...

Thanks for that. A quick test removing the SND_ASYNC option plays
multiple sound files in quick succession - just what I wanted.  I'll
experiment with libsndfile tomorrow, to see if I can accomplish the
same under Linux.

As long as I can find out the various options for each platform, I can
very easily put together my own sound playing API/Class, so that is
not much of a problem.

--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Henry Vermaak
On 14 June 2010 15:59, Graeme Geldenhuys <[hidden email]> wrote:
> On 14/06/2010, Alexander Grau wrote:
>>
>> If someone would like to add a PlaySoundFile API to LCL/FPC, drop me a
>> note and we will donate the Mac code for it :-) ...
>
> Thanks for that. A quick test removing the SND_ASYNC option plays
> multiple sound files in quick succession - just what I wanted.  I'll
> experiment with libsndfile tomorrow, to see if I can accomplish the
> same under Linux.

Note that the fpc libsndfile example is outdated (it uses oss).  There
is an example in the libsndfile source for how to play this with alsa.
 If you're not worried about gpl, then I'd probably use libao.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Schindler Karl-Michael
In reply to this post by Graeme Geldenhuys-2
Hi Graeme

Am 14.06.2010 um 15:37 schrieb Graeme Geldenhuys:

> Hi,
>
> Has anybody managed to play sound files under both Linux and Windows?
> Does FPC have a cross-platform API or FCL class for this?

UltraStarDeluxe uses ffmpeg for decoding and portaudio, a C library, for playback of the stream. Corresponding headers are here:

http://ultrastardx.svn.sourceforge.net/viewvc/ultrastardx/trunk/src/lib/

> If so, what sound format's are supported?  ogg, wav, mp3?

yes, and probably even more.

> Regards,
>  - Graeme -

Greetings - Michael.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Vladimir Zhirov-2
In reply to this post by Graeme Geldenhuys-2
> Has anybody managed to play sound files under both Linux and Windows?

One more option I know of is Audorra (http://audorra.sourceforge.net/).
I have not used it though, so no idea about its advantages/drawbacks.

--
Regards,
Vladimir Zhirov
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

dmitry boyarintsev
In reply to this post by Graeme Geldenhuys-2
On Mon, Jun 14, 2010 at 5:37 PM, Graeme Geldenhuys
<[hidden email]> wrote:
> Has anybody managed to play sound files under both Linux and Windows?
> Does FPC have a cross-platform API or FCL class for this?
I'd offer using OpenAL, however it requires proper libraries to be
installed on Linux (afaik installed by default in all modern desktop
distribs), and proper .dlls available for Windows.

There's proper example in FCL how to use OpenAL to play .wav, .ogg .mp3 files.

thanks,
dmitry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Ingemar Ragnemalm
In reply to this post by Graeme Geldenhuys-2
dmitry boyarintsev <[hidden email]> wrote:

On Mon, Jun 14, 2010 at 5:37 PM, Graeme Geldenhuys
<[hidden email]> wrote:

>> Has anybody managed to play sound files under both Linux and Windows?
>> Does FPC have a cross-platform API or FCL class for this?

>I'd offer using OpenAL, however it requires proper libraries to be
>installed on Linux (afaik installed by default in all modern desktop
>distribs), and proper .dlls available for Windows.

>There's proper example in FCL how to use OpenAL to play .wav, .ogg .mp3 files.

I second that, AL is worth considering. It was very easy for me to use, at least once I found a decent WAV loader.

I have a little "OpenAL kit" for the Mac here:

http://www.ragnemalm.se/lightweight/openal_fpc.zip

On the Mac it it great: always installed, much better API than Core Audio, and portable. Havn't tried it on Linux och Windows though. And there is one problem that AL doesn't help me with (apart from loading WAV) and that is to play music. Uncompressed sound isn't useful for music. I can play that with Quicktime, but I'd like to use something cross-platform.


/Ingemar


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Roland Schäfer
In reply to this post by Graeme Geldenhuys-2
[I don't know if a previous email of similar content got through. Sorry
if this is a double post.]

As libsndfile has already been recommended, I would just add that the
simplest and most fool-proof way of playing back audio (once you have
figured out how to load it) is PortAudio. It abstracts away from WDM,
ASIO, ALSA, Jack, CoreAudio and what not. It is in my view much easier
to use than OpenAL.

Up-to-date PortAudio 1.9 bindings for FPC can be obtained here (not
tested on MacOS):
http://sourceforge.net/projects/humus/files/

Note that UltraStarDeluxe (mentioned in another reply) seems to have
bindings for PA 1.7, which is outdated. It also does not provide the
platform-specific extensions.

Cheers!
Roland

On 6/14/2010 3:37 PM, Graeme Geldenhuys wrote:
> Hi,
>
> Has anybody managed to play sound files under both Linux and Windows?
> Does FPC have a cross-platform API or FCL class for this?
>
> If so, what sound format's are supported?  ogg, wav, mp3?
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Marco van de Voort
In reply to this post by Graeme Geldenhuys-2
In our previous episode, Graeme Geldenhuys said:
>
> Has anybody managed to play sound files under both Linux and Windows?
> Does FPC have a cross-platform API or FCL class for this?
>
> If so, what sound format's are supported?  ogg, wav, mp3?

KDE's phonon also has OS X and Windows packages:

http://doc.trolltech.com/4.4/phonon-overview.html#windows
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Graeme Geldenhuys-2
In reply to this post by Henry Vermaak
Op 2010-06-14 17:31, Henry Vermaak het geskryf:
>
> Note that the fpc libsndfile example is outdated (it uses oss).  There

Outdated is correct. The version in FPC 2.4.1 doesn't currently compile,
and references data structures not defined in the libsndfile unit.

I have a ESD (Esound daemon) header conversion that plays a single file
perfect on multiple linux distro's, but when I try and play multiple files
in succession, it plays all of them at the same time and doesn't wait for
one to complete before starting the next. There doesn't seem much help on
libesd either, but I'll take another look today. :-(

>  If you're not worried about gpl, then I'd probably use libao.

As long as it is very simple to deploy, or better, included with most linux
distros, then it's better.

My sound requirements is not very high. As long as I can play wav, ogg or
mp3 (any format will do really, but mp3 is not standard with Linux) and
play one file after the other without delays. I have random sound clips
that together make up a English or Afrikaans sentence.


Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Graeme Geldenhuys-2
In reply to this post by Graeme Geldenhuys-2
Op 2010-06-14 15:37, Graeme Geldenhuys het geskryf:
>
> Has anybody managed to play sound files under both Linux and Windows?

Thanks for everybody's responses. I'll work my way through all of them
today. Now I understand all the comments on the net about the state of
audio (and gaming) on Linux. It's a damn mess with 1000's of options and
each one in a different state of development or functionality.

Has anybody tried SDL (Simple-Direct-Media)?  I know SDL Graphics works
well with Free Pascal, but not sure about the Audio part.


Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

dmitry boyarintsev
On Tue, Jun 15, 2010 at 10:44 AM, Graeme Geldenhuys
<[hidden email]> wrote:
> Op 2010-06-14 15:37, Graeme Geldenhuys het geskryf:
> Has anybody tried SDL (Simple-Direct-Media)?  I know SDL Graphics works
> well with Free Pascal, but not sure about the Audio part.

Audio works just fine. You can use SDL_Mixer library (though it has
its own glitches).

thanks,
dmitry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Alexander Grau-2
In reply to this post by Graeme Geldenhuys-2
Graeme Geldenhuys schrieb:

> On 14/06/2010, Alexander Grau wrote:
>  
>> If someone would like to add a PlaySoundFile API to LCL/FPC, drop me a
>> note and we will donate the Mac code for it :-) ...
>>    
>
> Thanks for that. A quick test removing the SND_ASYNC option plays
> multiple sound files in quick succession - just what I wanted.  I'll
> experiment with libsndfile tomorrow, to see if I can accomplish the
> same under Linux.
>
> As long as I can find out the various options for each platform, I can
> very easily put together my own sound playing API/Class, so that is
> not much of a problem.
>
>  
For Linux, I think it can be simple as opening a file and writing the
raw audio data to it - using a simple WAV header reader or even an MP3
decoder for FPC, it should be possible to directly use the sound device  
(/dev/dsp):

http://www.opensound.com/pguide/audio.html

This is not the most elegant (or easiest) solution, however it has no
dependencies to any libraries :)

I think for getting a simple playSoundFile() API to FPC/LCL on all
platforms, dependencies to 3rd-party libs can be avoided.

Regards,
Alexander

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

dmitry boyarintsev
On Tue, Jun 15, 2010 at 11:37 AM, Alexander Grau <[hidden email]> wrote:
> This is not the most elegant (or easiest) solution, however it has no
> dependencies to any libraries :)

The solution still depends upon decompression libraries. However, they
can be statically linked.

thanks,
dmitry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Alexander Grau-2
dmitry boyarintsev schrieb:
> On Tue, Jun 15, 2010 at 11:37 AM, Alexander Grau <[hidden email]> wrote:
>  
>> This is not the most elegant (or easiest) solution, however it has no
>> dependencies to any libraries :)
>>    
>
> The solution still depends upon decompression libraries. However, they
> can be statically linked.
>  
Yes, correct - I was assuming that uncompressed WAV files are being used
- For compressed audio data, there might exist decompressors and
decoders for FPC already ... or at least Delphi code for it :-)

> thanks,
> dmitry
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>  


--

Mit freundlichen Grüßen/Best regards
Alexander Grau

Grau GbR
Hardware & Software Solutions
Eschenweg 12
32609 Huellhorst
Germany

www.grauonline.de
Tel: +49 (0) 5741 2301259
Fax: +49 (0) 5741 235530
E-Mail: [hidden email]

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Henry Vermaak
In reply to this post by Graeme Geldenhuys-2
On 15 June 2010 07:44, Graeme Geldenhuys <[hidden email]> wrote:
> Op 2010-06-14 15:37, Graeme Geldenhuys het geskryf:
>>
>> Has anybody managed to play sound files under both Linux and Windows?
>
> Thanks for everybody's responses. I'll work my way through all of them
> today. Now I understand all the comments on the net about the state of
> audio (and gaming) on Linux. It's a damn mess with 1000's of options and
> each one in a different state of development or functionality.

You'll probably find that there's 1000's of sound libraries for
windows, too.  There are different concepts here:  sound architecture
in the kernel (alsa, oss (deprecated)), sound daemons (pulseaudio,
jack, arts, esd), file format reading/writing and decoding of codecs
(mp3, ogg, etc).  On top of these you get the libraries that try and
make this cross platform.

You can do _very_ cool things with audio on linux.  I've got a friend
that runs a recording studio on ubuntu :)

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Henry Vermaak
In reply to this post by Alexander Grau-2
On 15 June 2010 08:37, Alexander Grau <[hidden email]> wrote:
>
> For Linux, I think it can be simple as opening a file and writing the raw
> audio data to it - using a simple WAV header reader or even an MP3 decoder
> for FPC, it should be possible to directly use the sound device  (/dev/dsp):

Note that OSS is deprecated, so this solution won't last very long.

> I think for getting a simple playSoundFile() API to FPC/LCL on all
> platforms, dependencies to 3rd-party libs can be avoided.

If you want you program to be a good desktop citizen, you should talk
directly to the sound daemon (pulse on gnome, phonon on kde?).

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: playing sound files (linux and windows)

Marco van de Voort
In our previous episode, Henry Vermaak said:
>
> > I think for getting a simple playSoundFile() API to FPC/LCL on all
> > platforms, dependencies to 3rd-party libs can be avoided.
>
> If you want you program to be a good desktop citizen, you should talk
> directly to the sound daemon (pulse on gnome, phonon on kde?).

The fact that they are different is the main problem there.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12