Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-06

Bug?

33 messages · 15 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roger Bailey

Can someone explain this?

Show quoted text 21 lines
program WhatsGoingOnHere ; type FunctionType = function : INTEGER ; function NamedFunction : INTEGER ; begin NamedFunction := 12345 ; end ; function TestFunction ( ActualParameter : FunctionType ) : INTEGER ; begin TestFunction := ActualParameter ( ) ; { compiles and runs o.k. } TestFunction := ActualParameter ; { gives "incompatible type" error, but ... } TestFunction := NamedFunction ; { ... compiles and runs o.k. } end ; begin WRITELN ( TestFunction ( NamedFunction ) ) ; end .
Michael Van Canneyt
to Roger Bailey
Roger Bailey wrote 16 lines
Can someone explain this? > program WhatsGoingOnHere ; > > type > > FunctionType = function : INTEGER ; > > function NamedFunction : INTEGER ; > begin > NamedFunction := 12345 ; > end ; > > function TestFunction ( ActualParameter : FunctionType ) : INTEGER ; > begin > TestFunction := ActualParameter ( ) ; { compiles and runs o.k. }

The addition of () actually calls the function.

> TestFunction := ActualParameter ; { gives "incompatible type" error, but ... }

Here you try to assign the ActualParameter (a function pointer) to the result (an integer). This of course gives a type error.

> TestFunction := NamedFunction ; { ... compiles and runs o.k. }

This is simply a regular function call.

Michael.

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?

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/
Henry Vermaak
to Graeme Geldenhuys
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?

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

Henry

Alexander Grau
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…
Show quoted text 8 lines
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;
Graeme Geldenhuys
to Alexander Grau
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/
Henry Vermaak
to Graeme Geldenhuys
Graeme Geldenhuys wrote 9 lines
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.

Schindler Karl-Michael
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…

Hi Graeme

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?

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.

dmitry boyarintsev
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…
Graeme Geldenhuys 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

Ingemar Ragnemalm

dmitry boyarintsev wrote:

Graeme Geldenhuys wrote 8 lines
> 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

Roland Schaefer
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…

[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

Graeme Geldenhuys wrote 7 lines
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?
Marco van de Voort
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 5 lines
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

Roger Bailey

Sorry, I committed the cardinal sin of getting the subject line wrong. Corrected now :-)

Michael Van Canneyt wrote 20 lines
On Mon, 14 Jun 2010, Roger Bailey wrote: > On 12 Jun 2010, at 11:00, Michael Van Canneyt wrote: > >>>> TestFunction := ActualParameter ( ) ; { compiles and runs o.k. } > >> [MVC:] The addition of () actually calls the function. >> >>>> TestFunction := ActualParameter ; { gives "incompatible type" error, but ... } >> >> [MVC:] Here you try to assign the ActualParameter (a function pointer) to the >> result (an integer). This of course gives a type error. >> >>>> TestFunction := NamedFunction ; { ... compiles and runs o.k. } > >> [MVC:] This is simply a regular function call. > > Sorry, but this simply wrong. The LRG (page 95) does not require an "actual parameter list" for a syntactically correct function call. [MVC:] What is simply wrong ? My explanation or the behaviour of the compiler ?
Sorry. I guess your explanation states what the compiler is doing, so in that sense your reply isn't "simply" wrong. However, the program fragment "TestFunction := ActualParameter" is a syntactically correct function call as as defined by the LRG, so the statement "Here you try to assign the ActualParameter (a function pointer) to the result (an integer)" is wrong. In fact I now notice you you give an almost identical example in the LRG (page 96)
Show quoted text 15 lines
Type FuncType = Function: Integer; Var A : Integer; Function AddOne : Integer; begin A := A+1; AddOne := A; end; Var F : FuncType; N : Integer; begin A := 0; F := AddOne; { Assign AddOne to F, Don’t call AddOne} N := AddOne; { N := 1 !!} end.

It's clear from this that the meaning of "Addone" depends on the context, here the type of the variable on LHS of the assigment. On this basis I think that the error message I received is either a compiler bug, or FPC implements a slightly perverse dialect of Pascal (so the LRG is wrong).

Hope this helps,
Roger Bailey

Graeme Geldenhuys
to Henry Vermaak: Note that the fpc libsndfile example is outdated (it uses oss). There is an example in…

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/
Graeme Geldenhuys
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…

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/
dmitry boyarintsev
to Graeme Geldenhuys
Graeme Geldenhuys 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

Alexander Grau
to Graeme Geldenhuys: Thanks for that. A quick test removing the SND_ASYNC option plays multiple sound files in…
Show quoted text 16 lines
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

dmitry boyarintsev
to Alexander Grau
Alexander Grau 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

Alexander Grau
to dmitry boyarintsev
Show quoted text 9 lines
On Tue, Jun 15, 2010 at 11:37 AM, Alexander Grau 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 :-)

Show quoted text 7 lines
thanks, dmitry _______________________________________________ fpc-pascal maillist - 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:
Henry Vermaak
to Graeme Geldenhuys: Op 2010-06-14 15:37, Graeme Geldenhuys het geskryf: Thanks for everybody's responses.…
Graeme Geldenhuys wrote 8 lines
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

Henry Vermaak
to Alexander Grau: For Linux, I think it can be simple as opening a file and writing the raw audio data to…
Alexander Grau 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

Marco van de Voort
to Henry Vermaak

In our previous episode, Henry Vermaak said:

Show quoted text 6 lines
> 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.

Vit Kavan
to Henry Vermaak: Note that OSS is deprecated, so this solution won't last very long. If you want you…
Henry Vermaak wrote 10 lines
On 15 June 2010 08:37, Alexander Grau 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.

True. I've written my last OSS-only application a year ago and it didn't work on over 50% of computers I've tried it on.

Now I use Alsa or Jack. Jack is very simple to use and very powerfull, but not available everywhere. Alsa is everywhere.

Henry Vermaak
to Marco van de Voort: In our previous episode, Henry Vermaak said: The fact that they are different is the main…
Marco van de Voort wrote 9 lines
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.

Yes, it makes it harder. Just like gtk vs qt.

Graeme Geldenhuys
to Vladimir Zhirov: One more option I know of is Audorra (http://audorra.sourceforge.net/). I have not used…

Op 2010-06-14 18:26, Vladimir Zhirov het geskryf:

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.

Some feedback for general FPC users thinking of using Audorra. It's 32-bit only and after some hacking (removing libc unit and cinerella dependencies) I got it compiled under 64-bit Linux. Unfortunately being able to compile it doesn't mean much. The LCL demo out-of-the-box experience is not very nice. I'll try and create a "audio-only" console demo to see how that goes.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Graeme Geldenhuys
to Graeme Geldenhuys: Has anybody managed to play sound files under both Linux and Windows? Does FPC have a…

Some more feedback. I found ACS in Lazarus wiki sight and in Lazarus-CCR subversion repository. This is very old and outdated. It requires libc (kylix compatibility) unit and is x86 and 32-bit only. It has some ASM code in there (yuck!). So this was a non-starter for me.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Graeme Geldenhuys
to dmitry boyarintsev: On Mon, Jun 14, 2010 at 5:37 PM, Graeme Geldenhuys I'd offer using OpenAL, however it…

Op 2010-06-14 18:28, dmitry boyarintsev het geskryf:

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

I can't find an example for loading a .wav file. I managed to extract the initialization and finalization code for OpenAL from the FCL examples, but now the main part is the call alSourcePlay(buffer) , but I don't know how to populate the buffer with a WAV file.

Any hints or sample code. The sample included in FCL 2.4.1 loads MAD, A52, OGG and ModPlug only. Google revealed a tutorial using AlutLoadWavFile(), but that is in the "unofficial utilities library", it's not part of the standard OpenAL 1.1 spec, and not included in Linux.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Unknown author
to Graeme Geldenhuys

If you can wait a few days, I'll extract a working windows/linux demo from my sourcode for you. Right now I'm really busy.

----- PŮVODNÍ ZPRÁVA -----
Od: "Graeme Geldenhuys"
Komu: "FPC-Pascal users discussions"
Předmět: Re: [fpc-pascal] playing sound files (linux and windows) Datum: 15.6.2010 - 13:29:43

Show quoted text 33 lines
Op 2010-06-14 18:28, dmitry boyarintsev het geskryf: > > There's proper example in FCL how to use OpenAL to > play .wav, .ogg .mp3 files. > I can't find an example for loading a .wav file. I managed to extract the initialization and finalization code for OpenAL from the FCL examples, but now the main part is the call alSourcePlay(buffer) , but I don't know how to populate the buffer with a WAV file. Any hints or sample code. The sample included in FCL 2.4.1 loads MAD, A52, OGG and ModPlug only. Google revealed a tutorial using AlutLoadWavFile(), but that is in the "unofficial utilities library", it's not part of the standard OpenAL 1.1 spec, and not included in Linux. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Kaspersky Internet Security 2010 + Kaspersky Mobile Security jen za 1199,-Kč. Ochraňte svůj počítač i mobil před zneužitím či ztrátou dat. Kupte si 2 produkty za cenu jednoho. www.kaspersky.cz
Graeme Geldenhuys
to Unknown author

Op 2010-06-15 13:30, het geskryf:

If you can wait a few days, I'll extract a working windows/linux demo from my sourcode for you. Right now I'm really busy.

That would be great thanks. I can wait... the sound support is for a new project that has no official starting date yet. I'm just gathering features and what FPC supports for that project.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
dmitry boyarintsev
to Graeme Geldenhuys: Op 2010-06-14 18:28, dmitry boyarintsev het geskryf: I can't find an example for loading…
Graeme Geldenhuys wrote
I can't find an example for loading a .wav file. I managed to extract the initialization and finalization code for OpenAL from the FCL examples, but now the main part is the call  alSourcePlay(buffer) , but I don't know how to populate the buffer with a WAV file.

You can download the sample from here: http://havefunsoft.com/fpc/wavetest.zip The test has been modified to support .wav files.

Be warned, waveutils.pas is able to read uncompressed wav PCM files only. If .wav file uses anykind of the compression it would impossible to read it. Most of sound-processing applications allow to convert .wav to uncompressed form.

thanks,
dmitry

Michalis Kamburelis
to Graeme Geldenhuys: Op 2010-06-14 18:28, dmitry boyarintsev het geskryf: I can't find an example for loading…
Graeme Geldenhuys wrote
I can't find an example for loading a .wav file.

[...]

Show quoted text 6 lines
Any hints or sample code. The sample included in FCL 2.4.1 loads MAD, A52, OGG and ModPlug only. Google revealed a tutorial using AlutLoadWavFile(), but that is in the "unofficial utilities library", it's not part of the standard OpenAL 1.1 spec, and not included in Linux.

ALUT is included in Linux, although usually in a separate package (libalut*). ALUT is "somewhat" official, that is it's development is coordinated on the same mailing list and, although separate to openal, I don't think it will die so soon :) ALUT spec is on http://connect.creativelabs.com/openal/Documentation/The%20OpenAL%20Utility%20Toolkit.htm

That said, loading uncompressed WAV files is quite easy, you can see my code on
https://vrmlengine.svn.sourceforge.net/svnroot/vrmlengine/trunk/kambi_vrml_game_engine/src/audio/soundfile.pas Look for TSoundWAV.CreateFromStream method.

Michalis