Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Romans_I_XVI
Level 7

Optimal bitrate for roAudioResource

So after spending a few days now trying to make my game optimized and running as smoothly as possible I was somewhat discouraged that after all of my work I was still having times of the entire game freezing up for a split second. This was always occurring around the time I would say destroy a few ships and absorb a few bullets at the same time. I thought there could possibly be too many collisions happening and data being processed and that was slowing it down. But after optimizing my game extensively and investigating this thoroughly I determined it was the Roku hanging while calling the roAudioResource SomeSound.Trigger() . But if that's the case I'm supposedly out of luck right? Wrong! I just went here http://audio.online-convert.com/convert-to-wav . Uploaded the .wav files I had and (re)converted them to .wav with the bitrate set to 16Bit . Now the problem is solved!

Any thoughts on this? Is this a known issue?
0 Kudos
22 Replies
renojim
Level 8

Re: Optimal bitrate for roAudioResource

"Romans_I_XVI" wrote:
converted them to .wav with the bitrate set to 16Bit . Now the problem is solved!

The bitrate set to 16-bit? I'm guessing you mean sample size (or bit resolution as that link refers to it as).

Out of curiosity, what sample size and sample rate were your original WAV files? The only issues I'm aware of is that some combinations of sample size and sample rate didn't work at all and sometimes very short WAV files wouldn't play, but it's been a long time since I've experimented and those issues may have been eliminated.

-JT
0 Kudos
Romans_I_XVI
Level 7

Re: Optimal bitrate for roAudioResource

Yeah if "bit resolution" is sample size than that's it. I don't know anything about working with audio and can hardly get through making simple changes with audacity. I don't know what my originals were but I do know that I've tried quite a few different sample rates when I was trying to reduce the size. All with the same results. I'm just glad it's working right this time. The Roku seems touchy with audio. First I had to change my background music to .WMA so it would playback smoother, and now this.
0 Kudos
EnTerr
Level 8

Re: Optimal bitrate for roAudioResource

I don't have first-hand experience but here viewtopic.php?f=34&t=78670&p=468951#p468951 BradC recommends sticking to 44k mono audio samples for some of the players. Probably somebody Roku* can clarify?
0 Kudos
BradC
Level 7

Re: Optimal bitrate for roAudioResource

this may seem like a silly question, but are you loading the sounds in realtime or pre-loading them and calling them as needed?

I haven't done any tests on this, but I have always just assumed that reading audio files at runtime would cause behavior like you described.




I've always had bad luck getting sounds to work well across all players, so I'm very interested in anything you may find out. (I've really only ever run into audio quality issues, not performance problems, though)
♦MiniGolf♦HangMan♦Brain Puck♦Retro Tennis♦BORK♦FLIP♦Pathogen♦Pathogen 2♦Shut the Box♦Birdie♦Logic♦Dots♦Pool♦küglo♦Bubble Wrap♦Trivia Channel♦Mancala♦Air Hockey♦Weather♦CAMERA♦Your Photos Screensaver♦Desert Beauty Screensaver♦Wild Lakes Screensaver♦
0 Kudos
Romans_I_XVI
Level 7

Re: Optimal bitrate for roAudioResource

I am pre-loading them. Actually I used to create the roAudioResource object each time a round started along with the creation of all the other variables. But now I create the object only once when the entire game is started instead of in the function that runs the gameplay. I did that just because I knew the sound was causing issues, but that didn't seem to make any difference. Again what fixed everything was when I used that website to change the bit resolution/sample size (whatever it's called) to 16bit. I had used Audacity to change the sample rate before this (mainly in an attempt to reduce the file size) but those all behaved the same. Well actually not 100%, I did get some instances of sound effects only playing half of the sound or none at all, but it was sparatic and inconclusive. Just picked whichever sample rate seemed the best at the time. After using https://tinypng.com/ to reduce my sprite sizes I was much less concerned about the size of the .wav files and so I was ok with using the ones that http://audio.online-convert.com/convert-to-wav spit out. Which for whatever reason are much larger ?

I believe what I currently have implimented is sample rate 8000hz, sample size 16-bit, and mono. Please note I still have the behavior where it sometimes only plays 50% of the sound effect or not at all of multiple activate in a short period of time. But I prefer this 1000% over having it slow down my entire game!

Not sure if any of that helps at all, but that's essentially my entire story. I think I'm in the same boat as you, Roku is quirky when it comes to audio, and there is a lot of fiddling around to try to find what works best.
0 Kudos
Roku Employee
Roku Employee

Re: Optimal bitrate for roAudioResource

I've personally settled on using 16 bit 44.1 mono files in my work with roAudioResource as I get the best results with those, there were some bugs with various other lower rates and i'm not sure if those were ever resolved.

Your .wav files need to be small, generally 250k or less work for me. (the limitation is officially 5 seconds in length).

One thing you can do if sounds are being cut off is to alternate channels when playing audio files - there are two channels available on most non-legacy players. Look in the beep example in your SDK for these (currently) not-really-documented features, here they are in a nutshell:


sound1=createobject("roAudioResource","pkg:/sounds/boom.wav")
sound2=createobject("roAudioResource","pkg:/sounds/laser.wav")
numchannels=sound1.maxSimulStreams()
volume=100
if numchannels < 2 then
print "Two channels not supported"
stop
else
print numchannels;" are supported"
end if
channel=0
sound1.trigger(volume,channel)
channel=1
sound2.trigger(volume,channel)



Note that you are still likely to experience retriggering glitches even if you alternate channels, but this should improve things significantly.

- Joel
0 Kudos
Romans_I_XVI
Level 7

Re: Optimal bitrate for roAudioResource

Wow. Thanks for the tip on multiple channels. Based on your code you are just showing us how to check if 2 channels are available, but you don't have the code verifying that it's available when calling trigger. So I'm guessing if it's not available it will just be ignored and not cause an error?
0 Kudos
Roku Employee
Roku Employee

Re: Optimal bitrate for roAudioResource

"Romans_I_XVI" wrote:
So I'm guessing if it's not available it will just be ignored and not cause an error?


Not sure. Definitely will cause an error on Legacy. I'm not 100% sure what will happen on every other platform. Seems to support two channels on every non-legacy device I've tested so far including RokuTV, but I'm not sure I've tested all variants yet. Best bet would be to disable the second channel usage if the maxSimulStreams() call reports only one channel.

- Joel
0 Kudos
Romans_I_XVI
Level 7

Re: Optimal bitrate for roAudioResource

I don't think I will use it anyway. It's a nice idea, but I just tried it out and it makes it so that the audio plays quite sometimes... IDK why, it wasn't with each swap of channels, it was just randomly.
0 Kudos