Recent

Author Topic: OpenALSoundManager  (Read 10251 times)

Lulu

  • Full Member
  • ***
  • Posts: 226
OpenALSoundManager
« on: August 11, 2017, 06:36:42 pm »
Hello,
OpenAlSoundManager is a library to play sounds throught OpenAL. It play only WAV files and use velocity curve to control the volume and pitch. I make it when I wrote a game ( Educ'Race ).
May be it can interest someone.

USAGE:
Code: Pascal  [Select][+][-]
  1. uses OpenAlSoundManager,
  2.         VelocityCurve;
  3. ...
  4. var
  5.  MySound: TOALSound;
  6. ...
  7. // load wav file
  8.  MySound := OALSoundManager.Add( 'Path/MyMusic.wav' );
  9. ...
  10. MySound.Play( AFromBegin: boolean );
  11. MySound.Pause;
  12. MySound.Stop;
  13.  
  14. // Get current volume of the sound
  15. MySound.Volume.Value // return single type value between 0 and 1000
  16.  
  17. // Slide the volume to new value in specified time, using velocity curve
  18. MySound.Volume.ChangeTo( ANewValue, ATimeSec: single; AVelocityCurve: word );
  19.  
  20. // You can also fade in and fade out the sound
  21.  
  22. // Set the volume to zero, play the sound then increase volume to maximum
  23. // Do it in specified time and with specified velocity curve
  24. MySound.FadeIn( ATimeSec: single; AVelocityCurve: word );
  25.  
  26. // Set the volume to zero, play the sound then increase volume to specified value
  27. // Do it in specified time and with specified velocity curve
  28. MySound.FadeIn( AVolume, ATimeSec: single; AVelocityCurve: word );
  29.  
  30. // Slide the volume to zero then stop the sound
  31. // Do it in specified time and with specified velocity curve
  32. MySound.FadeOut( ATimeSec: single; AVelocityCurve: word );
  33.  

Work on Windows 7 32bits and Windows 10 64bits
Could someone test it on Linux or Mac please ? Don't forget that you need OpenAL installed on your system
http://www.openal.org/
Thanks

EDIT: attached the last version working for Windows, Linux and Mac
« Last Edit: August 25, 2017, 02:10:24 pm by Lulu »
wishing you a nice life

Lulu

  • Full Member
  • ***
  • Posts: 226
Re: OpenALSoundManager
« Reply #1 on: August 11, 2017, 06:40:27 pm »
I forget  :D

Code: Pascal  [Select][+][-]
  1. // It's not necessary to delete the sound, OALSoundManager delete it when application terminate
  2. // but if you need, you can delete it with
  3. OALSoundManager.Delete( MySound );
  4.  
« Last Edit: August 11, 2017, 09:15:34 pm by Lulu »
wishing you a nice life

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: OpenALSoundManager
« Reply #2 on: August 11, 2017, 07:33:40 pm »
Good news, it works!  :D

If I remember correctly, OpenAL is installed by default on my Linux. But I can't compile your code. After some inspections, I found that I have to manually define:
- DYNLINK
- UseCThreads

To set the defines:
Lazarus main menu > Project > Project Options > Compiler Options > Custom Options > Defines > add both "DYNLINK" and "UseCThreads" > and don't forget to enable those checkboxes.

Tested using Lazarus 1.6.4 64-bit on Ubuntu Mate 16.10. All the effects: loop, pitch, fadings are working correctly.

Lulu

  • Full Member
  • ***
  • Posts: 226
Re: OpenALSoundManager
« Reply #3 on: August 11, 2017, 08:54:21 pm »
Thanks you Handoko to try it and for your help :)

I'm inexperimented in both Linux and Mac, but after inspected your answer and my code:

1) for DYNLINK: if I set this define according your answer, I think my code don't work if Darwin is defined.
    So, I add line 5, 6, 7 below in OpenALWrapper unit. What do you think ?
Code: Pascal  [Select][+][-]
  1. {$IFDEF WINDOWS}
  2.   {$DEFINE DYNLINK}
  3. {$ENDIF}
  4.  
  5. {$IFDEF UNIX}
  6.   {$DEFINE DYNLINK}
  7. {$ENDIF}
  8.  
  9. {$IF Defined(DYNLINK)}
  10. const
  11. {$IF Defined(WINDOWS)}
  12.   openallib = 'openal32.dll';
  13. {$ELSEIF Defined(UNIX)}
  14.   openallib = 'libopenal.so';
  15. {$ELSE}
  16.   {$MESSAGE ERROR 'DYNLINK not supported'}
  17. {$IFEND}
  18. {$ELSEIF Defined(Darwin)}
  19. {$linkframework OpenAL}
  20. {$ELSE}
  21.   {$LINKLIB openal}
  22. {$ENDIF}
  23.  


2) UseCThreads: I set this define as you explain to me

Could you test with those changes please ?
wishing you a nice life

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: OpenALSoundManager
« Reply #4 on: August 11, 2017, 10:12:48 pm »
Hello, I've tried it on an Apple MAc with macOS 10.12.6 installed. Like Handoko, I had to define DYNLINK and UseCThreads before I could get the app and library to build.

On running the app, I get the attached message, and indeed debugging shows that the OpenAL library is not being loaded.
I followed the instructions on http://macappstore.org/openal-soft/ to install the library, although some of the messages I've seen on the subject seem to suggest that the OpenAL should already be installed on macOS.

I've also tried tweaking the source of TOALCustomAudioManager to try to load openallib.dylib rather than openallib.so but the library still fails to load.

I'm way past the limits of my macOS/Unix knowledge here, so any help would be appreciated here.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: OpenALSoundManager
« Reply #5 on: August 11, 2017, 10:27:12 pm »
I followed the instructions on http://macappstore.org/openal-soft/ to install the library, although some of the messages I've seen on the subject seem to suggest that the OpenAL should already be installed on macOS.

Of course it's already installed:

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html

Or, even easier, just look in /System/Library/Frameworks.

Check to see what the compiled executable is linked against:

otool -L exefile


carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: OpenALSoundManager
« Reply #6 on: August 11, 2017, 11:01:43 pm »
OK, I'm convinced! OpenAL is definitely installed on my machine. The problem is that Lulu's code cannot find that installation.

I ran otool -L against the compiled executable but OpenAL was not among the listed frameworks.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: OpenALSoundManager
« Reply #7 on: August 12, 2017, 05:09:28 am »
Could you test with those changes please ?

Downloaded and tested. Now, it works on my computer without need to change anything and I can see you have defined the 'UseCThreads' on the custom options.

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: OpenALSoundManager
« Reply #8 on: August 12, 2017, 11:29:29 am »
Could you test with those changes please ?

I've just downloaded and tested again. The project builds successfully with no tweaks necessary. However, the Library still fails to load and I still get the error message, despite the OpenAL library definitely being present.

I've had a dig around the OpenAL.framework folder and in amongst various header files, there is what Finder describes as a Unix executable of 465Kb, so presumably, this is the actual library that needs to be loaded.

Looking at the source of OpenALWrapper.pas I can see that the intention is for the OpenAL framework to be linked in, by the:

Code: Pascal  [Select][+][-]
  1. {$ELSEIF Defined(Darwin)}
  2. {$linkframework OpenAL}
  3.  

...lines. But clearly, something is going wrong. I'll have a bit more of a play with it...
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Lulu

  • Full Member
  • ***
  • Posts: 226
Re: OpenALSoundManager
« Reply #9 on: August 12, 2017, 01:54:27 pm »
@Handoko
Thanks very much for testing and your help

@Carl_caulkett
After few researchs, I took example on library ZenGL because this library is cross platform and it use openal.
I took the define part from it
So in OpenALWrapper unit, I replace lines below
Code: Pascal  [Select][+][-]
  1. {$IFDEF WINDOWS}
  2.   {$DEFINE DYNLINK}
  3. {$ENDIF}
  4.  
  5. {$IF Defined(DYNLINK)}
  6. const
  7. {$IF Defined(WINDOWS)}
  8.   openallib = 'openal32.dll';
  9. {$ELSEIF Defined(UNIX)}
  10.   openallib = 'libopenal.so';
  11. {$ELSE}
  12.   {$MESSAGE ERROR 'DYNLINK not supported'}
  13. {$IFEND}
  14. {$ELSEIF Defined(Darwin)}
  15. {$linkframework OpenAL}
  16. {$ELSE}
  17.   {$LINKLIB openal}
  18. {$ENDIF}
  19.  
by
Code: Pascal  [Select][+][-]
  1. const
  2. {$IFDEF LINUX}
  3.   openallib = 'libopenal.so';
  4. {$ENDIF}
  5. {$IFDEF WINDOWS}
  6.   openallib = 'openal32.dll';
  7. {$ENDIF}
  8. {$IFDEF DARWIN}
  9.   openallib = '/System/Library/Frameworks/OpenAL.framework/OpenAL';
  10. {$ENDIF}
  11.  
May be this work for both Linux and Mac. Thanks you for your patience :-[

Here the modified project
wishing you a nice life

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: OpenALSoundManager
« Reply #10 on: August 12, 2017, 01:57:22 pm »
hi guys,
could you please tell me what is DYNLINK?
is this something specific to UNIX when using external libraries? i am asking as i am having some issues with loading portaudio on UNIX.

thank you
Lazarus 2.0.2 64b on Debian LXDE 10

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: OpenALSoundManager
« Reply #11 on: August 12, 2017, 02:05:32 pm »
That dynlink is an user defined directive. Read those green-colored code above carefully, then you may understand what it is for.

http://wiki.freepascal.org/Conditional_compilation

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: OpenALSoundManager
« Reply #12 on: August 12, 2017, 02:41:50 pm »
i am asking as i am having some issues with loading portaudio on UNIX.

Hello.

What kind of problems ?

Did you try to use Portaudio via uos ?

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: OpenALSoundManager
« Reply #13 on: August 12, 2017, 05:50:38 pm »
@Carl_caulkett
May be this work for both Linux and Mac. Thanks you for your patience :-[
Here the modified project
[/quote]

Hi Lulu, this has improved things in that I no longer get the error message, so I guess the library is loading correctly. However, I've been testing it with some small percussion sample wavs I had lying around, and I cannot get the application to produce any noise at all. One of the samples is attached...
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Lulu

  • Full Member
  • ***
  • Posts: 226
Re: OpenALSoundManager
« Reply #14 on: August 12, 2017, 08:06:11 pm »
With your wav file, no sound is playing for me too.
Could you test it with the attached wav please ?
wishing you a nice life

 

TinyPortal © 2005-2018