veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

mix feature: "subchunks" #483

Closed Lundis closed 2 years ago

Lundis commented 3 years ago

Hey!

I discovered by accident yesterday that repetitive sound effects (such as lasers) sound much more natural if you vary the starting position a little every time you play them, but I didn't find any support for accomplishing this easily in mix. I imagine that this is something that many game developers would want to use for sound effects, instead of creating multiple sound tracks.

I forked the project and created a new function to create "subchunks" based on an existing chunk. It works similar to go's subslices - no new audio buffer allocation, just changing the starting pointer and length. Is this something you would be interested in getting into your branch, or does it stray too much from the underlying C library?

https://github.com/Lundis/go-sdl2/commit/dc59965d1c2f096b717ed9feb3539463a15627b9

Disclaimer: I haven't had the time to test it in my game yet, so there may still be bugs or issues with my code.

veeableful commented 3 years ago

Hi @Lundis, thanks for the interest in adding feature into the project! I wonder if it is something that you could incorporate into the underlying SDL2_mixer library? I think It would be useful for wider audience and we would able to also implement the binding to it here!

Lundis commented 3 years ago

Thanks for a quick reply. I will check with the SDL2_mixer developers if they like it. A quick look tells me that it could be implemented identically there, but it could also be implemented as a variant of Mix_PlayChannel. In any case I'll get back to you later.

Lundis commented 2 years ago

My solution did not work out. However, I was able to accomplish the same effect to great success by introducing random-length fade-ins to my sound effects.