Playing sounds with standard components

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

Playing sounds with standard components

Luciano de Souza
Hello all,

Bass is a very good library for sound playing and recording. However,
it's not included as an standard feature of Freepascal. For whom wich
wants to work with standard components, are there other options: (1)
to play sounds and (2) to record sounds?

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

Re: Playing sounds with standard components

Jorge Aldo G. de F. Junior
You can use OpenAL or SDL...

2012/6/9 luciano de souza <[hidden email]>:

> Hello all,
>
> Bass is a very good library for sound playing and recording. However,
> it's not included as an standard feature of Freepascal. For whom wich
> wants to work with standard components, are there other options: (1)
> to play sounds and (2) to record sounds?
>
> Regards,
> Luciano
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Playing sounds with standard components

Graeme Geldenhuys-2
In reply to this post by Luciano de Souza
Our company uses SDL with good results in our cross-platform projects.

--
Regards,
  - Graeme -


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

Re: Playing sounds with standard components

Luciano de Souza
In reply to this post by Luciano de Souza
I took a look in Openal examples. I need to confess that I expected
something easier. Perhaps, something like:

PlaySound('file.wav', 0)

In MMSystem, we have something like that, but it's not cross platform.

The examples present hundreds of lines. It's something frightful!

Regarding the complexity, probably is's possible to do much more than
simply play a sound. In spite of that, it would be intersting to have
something easier.

The examples work with complex and for me, abstract structures. Which
kind of content, do I need to study to understand Openal or SDL?




2012/6/9, luciano de souza <[hidden email]>:

> Hello all,
>
> Bass is a very good library for sound playing and recording. However,
> it's not included as an standard feature of Freepascal. For whom wich
> wants to work with standard components, are there other options: (1)
> to play sounds and (2) to record sounds?
>
> Regards,
> Luciano
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : [fpc-pascal] Re: Playing sounds with standard components

Ludo Brands
> I took a look in Openal examples. I need to confess that I
> expected something easier. Perhaps, something like:
>
> PlaySound('file.wav', 0)
>
> In MMSystem, we have something like that, but it's not cross platform.
>
> The examples present hundreds of lines. It's something frightful!
>
> Regarding the complexity, probably is's possible to do much
> more than simply play a sound. In spite of that, it would be
> intersting to have something easier.
>
> The examples work with complex and for me, abstract
> structures. Which kind of content, do I need to study to
> understand Openal or SDL?
>

On the lazarus forum, kpjcomp made a wrapper for Openal. Haven't tested it
but his example code is as simple as:

  openAl := TLazOpenAL.Create;

  wav1 := TLazOpenALWavFileSource.Create('drumloop.wav');
  wav1.looping := true;
  openal.SourceList.Add(wav1);

  wav2 := TLazOpenALWavFileSource.Create('chimes.wav');
  openal.SourceList.Add(wav2);

  wav1.play;
  wav2.play;

Perhaps worth looking at.

Ludo

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

RE : RE : [fpc-pascal] Re: Playing sounds with standard components

Ludo Brands
> On the lazarus forum, kpjcomp made a wrapper for Openal.

Forgot the link:
http://www.lazarus.freepascal.org/index.php/topic,17164.msg94588.html#msg945
88

Ludo

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

Re: Playing sounds with standard components

Michalis Kamburelis-3
In reply to this post by Luciano de Souza
luciano de souza wrote:
> I took a look in Openal examples. I need to confess that I expected
> something easier. Perhaps, something like:
>
> PlaySound('file.wav', 0)
>

You need to wrap OpenAL a little to get something so simple.

In my Castle Game Engine (http://castle-engine.sourceforge.net/), I have
SoundEngine wrapper, with which you can play sound like

   Buffer := SoundEngine.LoadBuffer(FileName);
   SoundEngine.PlaySound(Buffer, false, ...);

See working example in SVN on
http://svn.code.sf.net/p/castle-engine/code/trunk/castle_game_engine/examples/audio/alplay.lpr

You may want to look at the source (LGPL) to see how it's done :)

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

Re: Playing sounds with standard components

silvioprog
In reply to this post by Luciano de Souza
Hello,

Please see this demo too:

https://github.com/silvioprog/lazsolutions/tree/master/Demos/LSPlayWAV

It is a cross function to play wav files.

--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : [fpc-pascal] Re: Playing sounds with standard components

silvioprog
In reply to this post by Ludo Brands
2012/6/11 Ludo Brands <[hidden email]>:
[...]

> On the lazarus forum, kpjcomp made a wrapper for Openal. Haven't tested it
> but his example code is as simple as:
>
>  openAl := TLazOpenAL.Create;
>
>  wav1 := TLazOpenALWavFileSource.Create('drumloop.wav');
>  wav1.looping := true;
>  openal.SourceList.Add(wav1);
>
>  wav2 := TLazOpenALWavFileSource.Create('chimes.wav');
>  openal.SourceList.Add(wav2);
>
>  wav1.play;
>  wav2.play;
>
> Perhaps worth looking at.
>
> Ludo

Hello Ludo. :)

Where do I find the openal_nt unit?

unit1.pas(9,3) Fatal: Can not find unit openal_nt used by Unit1.

--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Playing sounds with standard components

silvioprog
In reply to this post by Michalis Kamburelis-3
2012/6/11 Michalis Kamburelis <[hidden email]>:

> luciano de souza wrote:
>>
>> I took a look in Openal examples. I need to confess that I expected
>> something easier. Perhaps, something like:
>>
>> PlaySound('file.wav', 0)
>>
>
> You need to wrap OpenAL a little to get something so simple.
>
> In my Castle Game Engine (http://castle-engine.sourceforge.net/), I have
> SoundEngine wrapper, with which you can play sound like
>
>  Buffer := SoundEngine.LoadBuffer(FileName);
>  SoundEngine.PlaySound(Buffer, false, ...);
>
> See working example in SVN on
> http://svn.code.sf.net/p/castle-engine/code/trunk/castle_game_engine/examples/audio/alplay.lpr
>
> You may want to look at the source (LGPL) to see how it's done :)
>
> Michalis

Nice project. :)

castle_game_engine-3.0.0-src.zip = +-70MB.

Hm... you could send only the files to play audio? :/

--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Playing sounds with standard components

Michalis Kamburelis-3
silvioprog wrote:
> Nice project. :)
>
> castle_game_engine-3.0.0-src.zip = +-70MB.
>

Most of the size comes from the examples, they contain also example 3D
data files (models, animations etc.). I prefer to give people full
package :) For those who want to get parts, they can always check out
appropriate directories from SVN.

> Hm... you could send only the files to play audio? :/

The directories src/base/ and src/audio/ from the engine source code
should be all you need. And examples inside examples/audio/, and
examples/3d_sound_game/ (only in SVN), are probably useful :) Note that
if you only get a subset of src/ directories, you will need to prepare
also special Lazarus package to compile them (as the default package
inside packages/castle_base.lpk includes other units, to deal with 3D,
images, scripting and such), or compile only with ./xxx_compile.sh
scripts (Unix or Cygwin required). It will be easier to just get the
full zip/tar.gz archive, and simply ignore (don't look inside :)
directories that don't interest you :)

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

Re: Playing sounds with standard components

silvioprog
2012/6/11 Michalis Kamburelis <[hidden email]>:

> silvioprog wrote:
>>
>> Nice project. :)
>>
>> castle_game_engine-3.0.0-src.zip = +-70MB.
>>
>
> Most of the size comes from the examples, they contain also example 3D data
> files (models, animations etc.). I prefer to give people full package :) For
> those who want to get parts, they can always check out appropriate
> directories from SVN.
>
>> Hm... you could send only the files to play audio? :/
>
>
> The directories src/base/ and src/audio/ from the engine source code should
> be all you need. And examples inside examples/audio/, and
> examples/3d_sound_game/ (only in SVN), are probably useful :) Note that if
> you only get a subset of src/ directories, you will need to prepare also
> special Lazarus package to compile them (as the default package inside
> packages/castle_base.lpk includes other units, to deal with 3D, images,
> scripting and such), or compile only with ./xxx_compile.sh scripts (Unix or
> Cygwin required). It will be easier to just get the full zip/tar.gz archive,
> and simply ignore (don't look inside :) directories that don't interest you
> :)
>
> Michalis

Does not seem very easy to use hehehe.., but I will try test it later. :)

Thx Michalis! ^^

--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : [fpc-pascal] Re: Playing sounds with standard components

Ludo Brands
In reply to this post by silvioprog
> Where do I find the openal_nt unit?
>
> unit1.pas(9,3) Fatal: Can not find unit openal_nt used by Unit1.
>

At the bottom of the forum page is a link to a complete demo project
openaltest.zip that includes the units laz_openal and OpenAL_NT.

Ludo

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

Re: Playing sounds with standard components

Reinier Olislagers
In reply to this post by Jorge Aldo G. de F. Junior
On 9-6-2012 23:18, Jorge Aldo G. de F. Junior wrote:
> You can use OpenAL or SDL...

Found a framework that apparently uses SDL. Says it plays OGG and WAV.

Haven't tried it..

https://github.com/freezedev/elysion

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

Re: Playing sounds with standard components

michael.vancanneyt


On Tue, 12 Jun 2012, Reinier Olislagers wrote:

> On 9-6-2012 23:18, Jorge Aldo G. de F. Junior wrote:
>> You can use OpenAL or SDL...
>
> Found a framework that apparently uses SDL. Says it plays OGG and WAV.
>
> Haven't tried it..
>
> https://github.com/freezedev/elysion

SDL is so easy, it's hardly necessary to create a wrapper.

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

Re: Playing sounds with standard components

Graeme Geldenhuys-2
On 12 June 2012 09:49,  <[hidden email]> wrote:
>
>
> SDL is so easy, it's hardly necessary to create a wrapper.


+1

And because SDL is a cross platform framework, there is nothing
special to do in your code to get it to work on multiple platforms.



--
Regards,
  - Graeme -


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

Re: Playing sounds with standard components

silvioprog
2012/6/12 Graeme Geldenhuys <[hidden email]>:

> On 12 June 2012 09:49,  <[hidden email]> wrote:
>>
>>
>> SDL is so easy, it's hardly necessary to create a wrapper.
>
>
> +1
>
> And because SDL is a cross platform framework, there is nothing
> special to do in your code to get it to work on multiple platforms.
>
> --
> Regards,
>   - Graeme -

So, how to play audio (wav/mp3) with only SDL framework in Free Pascal?

--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Playing sounds with standard components

Graeme Geldenhuys-2
On 12 June 2012 16:17, silvioprog <[hidden email]> wrote:
>
> So, how to play audio (wav/mp3) with only SDL framework in Free Pascal?


Simply reading a SDL tutorial or two, will quickly let you understand
the following code. TSoundEngine is just an convenience class we
created to add extra sound events and possibly swap out sound library
frameworks in future - without needing to change our application code.
Simple design pattern practices to simply your application code and
hide complexity.

This is not the complete code, but is the gist of it.


uses
  sdl_mixer,
  sdl;

const
  // Global default extension for sound files. Set up as needed.
  SoundExt           = '.wav';

type

  PSoundBlock = {$IFDEF UseMusic}PMIX_Music{$ELSE}PMIX_Chunk{$ENDIF};


  ...
 { in our project, this code is in a TSoundPlayer class. Result is of
type PSoundBlock }
    Result := {$IFDEF
UseMusic}Mix_LoadMUS{$ELSE}Mix_LoadWAV{$ENDIF}(PChar(aFilename));
    if not Assigned(Result) then
      SoundEngine.MixError;
  ...



constructor TSoundEngine.Create;
begin
  if SDL_Init(SDL_INIT_AUDIO or SDL_INIT_TIMER) = -1 then
    SDLError;
  if Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
MIX_DEFAULT_CHANNELS, 1024) = -1 then
    MixError;
  {$IFDEF UseMusic}Mix_HookMusicFinished{$ELSE}Mix_ChannelFinished{$ENDIF}(@MusicFinished);
end;

destructor TSoundEngine.Destroy;
begin
  PlayingStop;
  MIX_CloseAudio;
  SDL_Quit;
  inherited Destroy;
end;

procedure TSoundEngine.PlayingStop;
begin
  {$IFDEF UseMusic}
  Mix_HaltMusic;
  {$ELSE}
  Mix_HaltChannel(1);
  {$ENDIF}
end;

procedure TSoundEngine.PlayingStart(aMusic: PSoundBlock);
begin
  {$IFDEF UseMusic}
  if Mix_PlayMusic(aMusic, 0) <> 0 then
    MixError;
  {$ELSE}
  Mix_PlayChannel(1,aMusic, 0)
  {$ENDIF}
end;

procedure TSoundEngine.PlayingPause;
begin
  {$IFDEF UseMusic}
  Mix_PauseMusic;
  {$ELSE}
  Mix_Pause (1);
  {$ENDIF}
end;

procedure TSoundEngine.PlayingContinue;
begin
  {$IFDEF UseMusic}
  Mix_ResumeMusic;
  {$ELSE}
  Mix_Resume (1);
  {$ENDIF}
end;



--
Regards,
  - Graeme -


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

Re: Playing sounds with standard components

silvioprog
2012/6/12 Graeme Geldenhuys <[hidden email]>:

> On 12 June 2012 16:17, silvioprog <[hidden email]> wrote:
>>
>> So, how to play audio (wav/mp3) with only SDL framework in Free Pascal?
>
>
> Simply reading a SDL tutorial or two, will quickly let you understand
> the following code. TSoundEngine is just an convenience class we
> created to add extra sound events and possibly swap out sound library
> frameworks in future - without needing to change our application code.
> Simple design pattern practices to simply your application code and
> hide complexity.
>
> This is not the complete code, but is the gist of it.
>
>
> uses
>  sdl_mixer,
>  sdl;
>
> const
>  // Global default extension for sound files. Set up as needed.
>  SoundExt           = '.wav';
>
> type
>
>  PSoundBlock = {$IFDEF UseMusic}PMIX_Music{$ELSE}PMIX_Chunk{$ENDIF};
>
>
>  ...
>  { in our project, this code is in a TSoundPlayer class. Result is of
> type PSoundBlock }
>    Result := {$IFDEF
> UseMusic}Mix_LoadMUS{$ELSE}Mix_LoadWAV{$ENDIF}(PChar(aFilename));
>    if not Assigned(Result) then
>      SoundEngine.MixError;
>  ...
>
>
>
> constructor TSoundEngine.Create;
> begin
>  if SDL_Init(SDL_INIT_AUDIO or SDL_INIT_TIMER) = -1 then
>    SDLError;
>  if Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
> MIX_DEFAULT_CHANNELS, 1024) = -1 then
>    MixError;
>  {$IFDEF UseMusic}Mix_HookMusicFinished{$ELSE}Mix_ChannelFinished{$ENDIF}(@MusicFinished);
> end;
>
> destructor TSoundEngine.Destroy;
> begin
>  PlayingStop;
>  MIX_CloseAudio;
>  SDL_Quit;
>  inherited Destroy;
> end;
>
> procedure TSoundEngine.PlayingStop;
> begin
>  {$IFDEF UseMusic}
>  Mix_HaltMusic;
>  {$ELSE}
>  Mix_HaltChannel(1);
>  {$ENDIF}
> end;
>
> procedure TSoundEngine.PlayingStart(aMusic: PSoundBlock);
> begin
>  {$IFDEF UseMusic}
>  if Mix_PlayMusic(aMusic, 0) <> 0 then
>    MixError;
>  {$ELSE}
>  Mix_PlayChannel(1,aMusic, 0)
>  {$ENDIF}
> end;
>
> procedure TSoundEngine.PlayingPause;
> begin
>  {$IFDEF UseMusic}
>  Mix_PauseMusic;
>  {$ELSE}
>  Mix_Pause (1);
>  {$ENDIF}
> end;
>
> procedure TSoundEngine.PlayingContinue;
> begin
>  {$IFDEF UseMusic}
>  Mix_ResumeMusic;
>  {$ELSE}
>  Mix_Resume (1);
>  {$ENDIF}
> end;
>
>
>
> --
> Regards,
>   - Graeme -

Hellow Graeme! :)

I'll try to test it tomorrow and return here with the results ...

Thank you in advance guy! :)

--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Playing sounds with standard components

silvioprog
In reply to this post by Graeme Geldenhuys-2
2012/6/12 Graeme Geldenhuys <[hidden email]>:

> On 12 June 2012 16:17, silvioprog <[hidden email]> wrote:
>> So, how to play audio (wav/mp3) with only SDL framework in Free Pascal?
> Simply reading a SDL tutorial or two, will quickly let you understand
> the following code. TSoundEngine is just an convenience class we
> created to add extra sound events and possibly swap out sound library
> frameworks in future - without needing to change our application code.
> Simple design pattern practices to simply your application code and
> hide complexity.
>
> This is not the complete code, but is the gist of it.
[...]

I tried playing a wav file with this demo in attached, no errors, but
no sound came out. :(

I downloaded all DLLs here:

http://www.libsdl.org/

http://www.libsdl.org/projects/SDL_mixer/

--
Silvio Clécio
My public projects - github.com/silvioprog

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

a.zip (10K) Download Attachment
12