Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Current time position and total length of SampleInstance
- - By jbe Date 2012-09-19 11:32 Edited 2012-09-19 12:06

First of all, thanks for making Gosu available. It's been a lot faster and easier to get around than ruby-sdl-ffi, and i love the idea of being able to write an entire game in just Ruby; it's kind of fun. And the API is very easy to use too (never mind the fact that the window scales itself down to show the taskbar when it isn't fullscreen, i somehow found out what was going on eventually :P).

I've been experimenting with extending the base classes to add a few bits and bobs, but i'm wondering about one thing in particular. I'm planning to use some ambient looping samples along with the music in the project i'm working on, so I am writing a simple SampleLoop class that retriggers a sample a few seconds before it ends, as a sort of primitive crossfade. -- Actually, the fade could be automated in Ruby as well for that matter. However, as far as i know, there is no way to detect the sample length and playback position in the Gosu Ruby API. Or did i overlook something?

If not, is there any chance of this showing up a future release?

As a clumpy workaround, i could read the system time when a sample starts, compare now and then, and have the sample lengths stored somewhere (afaik, there are no suitable gems to check it). I can live with the first part, but i don't like hardcoding sample lengths..

What do you guys think about this?
Parent - By jlnr (dev) Date 2012-09-19 13:50
Hey - thanks for posting. Gosu uses OpenAL on all platforms now, I think it shouldn't be too hard to implement both features. Would you mind to open a ticket on github? I cannot guarantee much, but at least it won't get lost as easily as on this board. :)
Parent - - By jlnr (dev) Date 2012-09-19 13:51
Also, as the clumsiest workaround ever, you can use SampleInstance#playing? to determine whether a sample is over, and auto-generate the length table in a super slow rake task! :)
Parent - - By Spooner Date 2012-09-19 14:26
Although that is a lovely way to do it, I found that reading from the file header with the ruby-ogginfo gem was a little bit more efficient!

This is still terribly approximate, so having access to the length and time remaining in Gosu would be grand.
Parent - - By jlnr (dev) Date 2012-09-20 03:09
What do you mean, my solution is not efficient? You can just play it back with speed set to 10 and then multiply the result by 10 (slight loss of accuracy)!!!! ;)
Parent - By Spooner Date 2012-09-20 03:11
I give up :D
Parent - By erisdiscord Date 2012-09-21 03:35
something something O(n) blah blah. 8D
Parent - By jbe Date 2012-09-19 15:41
Haha, that is brilliant, why didn't i think of that! Maybe not the most straightforward solution but it does have that cosy duct tape vibe. And come to think of it, i could just hook in some code that gets them while the game runs (meaning while i test and debug); and it would kind of sort itself out. Weird enough, but should work as a workaround.

I'll add a ticket then. I'd try writing a patch too if i had any experience with c++ or openAL, but that's probably above me for now. Thanks again, and yeah, certainly no need to hurry, but i'll put the ticket there in case.
Up Topic Gosu / Gosu Exchange / Current time position and total length of SampleInstance

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill