Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
What is the best sound format? — Gideros Forum

What is the best sound format?

MikeHartMikeHart Guru
edited January 2012 in General questions
Hi folks,

depending on the sound my game plays, I get a drop in the framerate when I play them quickly after each other. Let's say 5-7 sounds (shots) which are around 5 seconds long.

My question is, is there a best practise for the format of sounds I should use? I mean what bitrate, khz value. What are the best formats for less lagging?

Cheers
Michael

Likes: fxone

Tagged:
+1 -1 (+1 / -0 )Share on Facebook
«1

Comments

  • I did more testing and even with sounds that are just 0.5 seconds long, it is very present. On my IPod touch 2nd gen it is very bad. On my Android HTC desire it is ok now with these short sounds and on the IPad 2 it is fine.
  • GregBUGGregBUG Guru
    edited January 2012
    i'm adding now sfx in my game... using some sample (in mp3)
    no problem for now... (tested on android only)...

    do you know how to do an infinite loop sound ?

    Sound:play(startTime, loops)
    loops =1 or 0 play loop only one time.. :(
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • yes, do this:

    yoursound:play(0, math.huge)
  • GregBUGGregBUG Guru
    edited January 2012
    Oh, thanks MikeHart! I did not know of the existence of math.huge. ;;)

    Which audio format did you use? Samplerate etc?

    Thanks again
    Gianluca
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • MP3 128 kps, 22050 khz, 16 bit.

    I just played more with it lower settings and on my IPod Touch 2nd gen there is no difference. Still craps the FPS.
  • atilimatilim Maintainer
    edited January 2012
    Hi all,

    You should use .wav files for sound effects and .mp3 for background music. Here are the advantages and disadvantages of these:

    -wav files: Entire sound is loaded into memory. Has very low latency to play. Consumes little CPU while playing. Suitable for simultaneously played sound effects.
    -mp3 files: Sound is played by reading small chunks therefore consumes little memory. Consumes more CPU compared to .wav files. Suitable for background music/speech. According to my tests, playing a single mp3 consumes about %20 of the CPU on iPod touch 2nd gen.

    Mike, can you convert your .mp3 files to .wav and try again?
    +1 -1 (+3 / -0 )Share on Facebook
  • Thanks Atilim,

    see you never stop learning. Of course I will test. And will add this info to the guide.
  • Ok, much much better. I used Audacity to convert them. Problem here is that I can only export to 16bit PCM. I think Gideros uses 22050 khz and 24 bit, right?
  • Ok, deep inside the export options, under uncompressed soudn formats, there is seems I can export to 24 bits too.

    Atilim, if I use 16 bit pcm, does that have an effect of the performance?
  • atilimatilim Maintainer
    On Android, the output frequency is 22050 khz, and on iOS it's 44100 khz and on both output bit depth is 16 bit. I usually prefer 22050 khz and 16 bit for game sound effects.
  • atilimatilim Maintainer
    I think, I would only use 44100 khz wav files, If I develop a music application on iOS.
  • Sure, but for games, imho 22050 suite you just fine.
  • GregBUGGregBUG Guru
    edited January 2012
    hey!
    thanks for suggestions, now i'm also using 22050 wav for sfx...

    but play(0, math.huge)
    (math.huge is a constant. It represents +infinity.)

    don't loop sound.... :(

    i'm missing something ?
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    Than it's my bad. I've confused Mike :)

    Let me check it. While I'm checking it you can use a very large number (e.g. 1000000) to loop for a long time.


  • @atilim

    Let me check it. While I'm checking it you can use a very large number (e.g. 1000000) to loop for a long time.
    yes i'm using a large number for now but i think is not a good way... ;)

    but why not implement in "play" function -1 to loop to infinite ?

    thanks.
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    edited January 2012
    Yes, -1 is a suggested value to specify infinite loop.

    All Timer, Sound and GTween classes use repeat counts. I'll implement a common way to specify infinite loop (it can be -1 or math.huge) with these classes.

  • thanks atilim,
    efficent as always...

    (and if I can ... I vote for -1) ;;)

    Likes: MikeHart

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Hi all,

    You should use .wav files for sound effects and .mp3 for background music. Here are the advantages and disadvantages of these:

    -wav files: Entire sound is loaded into memory. Has very low latency to play. Consumes little CPU while playing. Suitable for simultaneously played sound effects.
    -mp3 files: Sound is played by reading small chunks therefore consumes little memory. Consumes more CPU compared to .wav files. Suitable for background music/speech. According to my tests, playing a single mp3 consumes about %20 of the CPU on iPod touch 2nd gen.

    Mike, can you convert your .mp3 files to .wav and try again?
    hi atilim

    Is there any way that mp3 files could also be loaded into memory if required? In Corona I used loadSound to load mp3 files into memory and loadStream to read them a bit at a time. I've converted my mp3s to wav files (using 22050 khz and 16 bit) which works fine, but the size of the app has grown enourmously and would be a lot smaller if I could use mp3 files.

    I wondered if it would be possible to allow the choice of how mp3 files are handled and, if it was, if you would consider including it? There may be a good reason that I don't understand why it isn't possible!

    Thanks
    Pete
  • atilimatilim Maintainer
    Hi Pete,

    Unfortunately no way. To implement this, I need to embed a mp3 decoder (e.g. mpg123) and this means increasing of the executable. Currently we're always using device capabilities to play mp3's. It's a tricky issue on our side.

    I think you want to use low latency sounds while not increasing the application size, right? Do you encounter problems while using mp3s?
  • Hi Atalim

    I wondered if there was a reason for it and now I see there is!

    You're right that I want to use low latency sounds whilst keeping the size down. I have tried it with mp3s and have problems with that (worse on some devices than others - particularly bad on an Archos 70 tablet that a tester uses). I am often tweening things at the same time as the sound is called and have found that mp3s cause the tween movement to stutter and become very jumpy, especially when several are going at once. All becomes OK once I replace the mp3s with wav files.

    Looks like I'll be having larger application size. What is the lowest quality wav file that will play? Does it have to be at 22050 khz or can it be lower? I could use lower for some of the sounds without the reduced quality mattering too much.

    Thanks, Pete
  • atilimatilim Maintainer
    Hi Pete,

    I understand now. You can use very low quality wav files (e.g. 11025 or 8000) without a problem. I wish I can present a solution.
  • Hi Atilim
    That's OK - I'll reduce the ones that don't matter too much and just keep the larger ones for voiced bits and so on.
    Thanks, Pete
  • evsevs Member
    Here's my infinite loop kludge:-
    local sound = Sound.new("whatever.mp3")
    local length = sound:getLength()
    local channel = sound:play()
    Then in enter frame or other loop:-
    if channel:getPosition() == length then channel = sound:play() end
    Cheers

    evs
  • Hi!...@atilim in Gideros player and device real i get "...folder/archive.wav: Sound format is not supported." ...what is the problem?
  • with mp3 files I have no problems...Thanks for your answers
  • SinisterSoftSinisterSoft Maintainer
    edited April 2013
    @evs I've had that fail and the sound stop, you should check the position for equal to or greater than the sound length.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • @SinisterSoft

    you can also use

    SoundChannel:setLooping(looping)

    Sets the looping state of the channel.
    Parameters:

    looping: (boolean) looping state to set
  • @atilim, for MP3 files, which bitrates are supported by Gideros AND Android AND iOS ?

    The app I'm working on requires a lot of sound tracks to be stored, but only one played at time.
    I'm trying to balance file size with sound quality. Using Audacity, I narrowed the range of kbps that are acceptable from 40 to 64. (using "Bit Rate Mode" = "Constant")

    Is there support for "Variable" and "Average" ?

    I'm going to set up a test project to build for both Android and iOS, but if you have done tests already, then I'm interested in your findings.
  • atilimatilim Maintainer
    edited November 2013
    @chipster123, I've looked at Android and iOS documentation

    http://developer.android.com/reference/android/media/MediaPlayer.html

    https://developer.apple.com/library/ios/DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

    but couldn't find any information about it. mp3 files are played using OS capabilities and I think there shouldn't be any limitations.
Sign In or Register to comment.