Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAL vs AVAudioPlayer vs other techniques for playing sounds

I know that OpenAL is fast library but it doesn't support any compressed audio format and it's not so easy to use...

AVAudioPlayer is not so fast, but supports wide range file formats, as well as compressed formats like mp3.

Also there is an SKAction class which can play a sound, as well as SystemSoundID...

I have few questions:

  1. What would be a preferred way/player/technique to play :

    • sound effects(multiple at the time)?
    • sound effects which can be sometimes repeated after small time delay
    • background music that loops
  2. Also, is it smart move to use uncompressed audio for sound effects? I suppose this is ok, because those files have small size anyway?

like image 954
Whirlwind Avatar asked Jan 09 '23 23:01

Whirlwind


1 Answers

I'm personally using ObjectAL. It's good because it utilizes OpenAL and AVAudioPlayer but abstracts a lot of the complicated parts away from you. My game has background music, tons of sounds playing simultaneously, and loopable sounds that increase in volume, pitch etc based on a sprites speed. ObjectAL can do all of that.

ObjectAL can be used for playing simple sounds and music loops using it's OALSimpleAudio class. Or you can get deeper into it and do more complex things.

I've created a simple wrapper around ObjectAL specifically for my game so it's further abstracted away from me.

From what I've read, uncompressed audio is better. You just need to make sure you preload the sounds so that your game isnt trying to pull the file each time it's playing a sound.

like image 92
hamobi Avatar answered Jan 12 '23 07:01

hamobi