Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
destruk
Streaming Star

Is it possible to prefill the input buffer?

I'm looking for a way to automatically generate the remote control sound effects while using roImageCanvas. When I press FF or REW the roku plays sound, when I just press the arrow buttons it doesn't play a sound.
Using roAudioPlayer to manually play mp3 files incurs a delay and slows down the graphic update of the script, which would mean the audioplayer isn't running in a separate thread, or if it is, using two threads slows down the app.
The script for initializing the audio player appears to be straightforward and works

'set up audio
AudioPlayer = CreateObject("roAudioPlayer")
AudioPlayer.setcontentlist([{ url: "file://pkg:/images/Click2.mp3" }])
AudioPlayer.setloop(false)

And when I want the sound to play, I have AudioPlayer.Play() and it does play a sound. However, it slows everything down by doing so.

Since it is possible to send remote control input using the methods in "external control guide.pdf", and it's possible to even remote control a roku through telnet, would it also be a possibility to send a command through the running script?
for example

msg.PutMessage( "8" )

to insert the REW button press into the message buffer to get the underlying shell to play the sound for me? I notice of all the methods, there aren't many that you can actually populate yourself.
0 Kudos
10 REPLIES 10
jbrave
Channel Surfer

Re: Is it possible to prefill the input buffer?

Well, you can preload the audio player with all the sounds you want to play and use setnext to pick which sound to play, don't know how fast it will respond for a locally stored sound, but should be pretty fast.
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
destruk
Streaming Star

Re: Is it possible to prefill the input buffer?

For a custom menu system, there is about a seond delay in processing while the audioplayer starts playing. If the sound is streamed, it's not cached, and that adds an extra second delay to actually play it (for a 16KB mp3). I went through and optimized all the drawing routines and layers and without sound I can run through items 8 per second, so the sound playing 16 times slower than I need it to, just isn't going to be fast enough. I'd really like access to the default system sounds as there isn't any visible performance hit when those play with FF or REW. I only require a single sound, for any button press, so I don't think SetNext is going to be necessary?
0 Kudos
kbenson
Visitor

Re: Is it possible to prefill the input buffer?

There isn't currently a way to play quick short sounds in a manner suitable for immediate audio feedback. Roku has stated they are looking into providing better components for this, but there isn't anything yet.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
destruk
Streaming Star

Re: Is it possible to prefill the input buffer?

Thanks kbenson. I also thought I'd try duplicating the source sound into a much larger file and using pause and resume to play single sections to try to get around the startup delay but that won't work because you can't have a timer call a routine after a set timeframe. Also, when a sample is set to loop, when it goes back to the beginning you get the same delay again. 😞 WAV file format wouldn't exhibit any buffer delay for a local pkg sample - hopefully they add support for wav, or to a quick call into the default sound set.
0 Kudos
retrotom
Visitor

Re: Is it possible to prefill the input buffer?

I know this might sound stupid/crazy/inefficient/ineffective....but....what if you tried to do the opposite of what you're doing? You trying to play a sound in response to user interaction. What if you continually tried to play the sound and "cancelled" it every second -- but on user interaction, you disable the "cancel" and let the sound play all the way through? Like I said...that's pretty hacky...just to get a click sound when someone presses a button...but you could try it.
0 Kudos
destruk
Streaming Star

Re: Is it possible to prefill the input buffer?

"retrotom" wrote:
I know this might sound stupid/crazy/inefficient/ineffective....but....what if you tried to do the opposite of what you're doing? You trying to play a sound in response to user interaction. What if you continually tried to play the sound and "cancelled" it every second -- but on user interaction, you disable the "cancel" and let the sound play all the way through? Like I said...that's pretty hacky...just to get a click sound when someone presses a button...but you could try it.


The progress meter for video playback counts every second - but how could you poll the time that it has been playing at set intervals without a user having to press a button? And then how could you handle it for an 1/8th second or 125 ms? I think that's what I'd need to get it to work, or wav support, or their upcoming sound effects sdk patch.
0 Kudos
retrotom
Visitor

Re: Is it possible to prefill the input buffer?

The wait() function does exactly what you're talking about on a message port. In our channels we use it to display subtitles on 100ms boundaries. You call wait(100, port). When wait returns without user feedback, the message will be invalid -- so you know that it's been 100ms. To help, we also use a timer and call timer.Mark() just to be sure. In fact, you could use a timer and wait in order to have a near-consistent wait time by waiting a dynamic number of milliseconds between user feedback. Make sense?
0 Kudos
destruk
Streaming Star

Re: Is it possible to prefill the input buffer?

So what I could do then is tell it to play a sound, wait 1ms, pause the sound, then resume it again when the user presses a button on the remote, and pause it again after 125ms and see if that would eliminate the startup delay?
0 Kudos
retrotom
Visitor

Re: Is it possible to prefill the input buffer?

You could try it. Whatever you do is going to be "fuzzy" and probably require tweaking/testing to get right -- or as close to it as possible. I don't know if waiting for the "startup progress" messages to get to a certain point makes sense. I know that we did a lot testing with subtitles to get the timing right. The biggest key (I think) is adjusting appropriately for the time it takes to execute whatever logic runs in between your expected "dead time".
0 Kudos