Add an AudioStreamGeneratorPlayback.get_frames_buffered()
method
#11180
Labels
AudioStreamGeneratorPlayback.get_frames_buffered()
method
#11180
Describe the project you are working on
I'm working on the libsm64-godot addon, and in this project, the C library I use (libsm64) generates PCM audio data every "tick" (1/30 of a second). In order to play this audio, I use a
AudioStreamGenerator
resource as a audio buffer. This way, I don't have to worry about the timing between Godot's process delta and the libsm64 delta, since the audio gets "queued" by theAudioStreamGeneratorPlayback.push_buffer()
method.Describe the problem or limitation you are having in your project
There is no (easy and direct way) of getting the amount of currently buffered audio frames in a
AudioStreamGeneratorPlayback
object. This feature is needed for my project, since my code has to check every "libsm64 tick" if there is too many audio frames already queued, and if so, throw away the current tick instead of queuing it. This is necessary in order to avoid the played audio from de-syncing, since the length of the audio generated doesn't perfectly line up with the tick length every time. There is anAudioStreamGeneratorPlayback.get_frames_available()
method already, but no way to get the currently buffered frames (and no method to get the total size of the buffer, so no direct way of calculating it).Describe the feature / enhancement and how it helps to overcome the problem or limitation
Pretty self explanatory, simply adding an
AudioStreamGeneratorPlayback.get_frames_buffered()
method would solve this issue. Maybe there could be anAudioStreamGeneratorPlayback.get_frames_buffer_size()
method as well, for the sake of thoroughness.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
It would be as simple as:
It would perfectly mirror the already available
AudioStreamGeneratorPlayback.get_frames_available()
method.If this enhancement will not be used often, can it be worked around with a few lines of script?
Calling
AudioStreamGeneratorPlayback.get_frames_available()
with the buffer empty does technically return the size of the buffer, but it is not always possible to know when the buffered will be completely empty (or even if the buffer is actually empty).If you know how the
AudioStreamGenerator
object that generated theAudioStreamGeneratorPlayback
object allocates the buffer (by mutiplying the buffer seconds length by the sample rate and finding the next power of two), you can replicate the math in order to find out the total buffer length. However this requires internal engine logic knowledge to figure out and would be subject to change without warning.Is there a reason why this should be core and not an add-on in the asset library?
The internal buffer object in
AudioStreamGeneratorPlayback
is private (as it should be), and therefore there's no way to implement this feature outside of directly adding such a method in the engine's core code.The text was updated successfully, but these errors were encountered: