Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio with compress mode set to RAM always plays from the beginning #18878

Open
Tracked by #76797
YeldhamDev opened this issue May 15, 2018 · 8 comments
Open
Tracked by #76797

Audio with compress mode set to RAM always plays from the beginning #18878

YeldhamDev opened this issue May 15, 2018 · 8 comments

Comments

@YeldhamDev
Copy link
Member

Godot version:
47d4a01

Issue description:
I don't know if this is just a limitation or not, but if a audio file has its compress mode set to RAM (Ima-ADPCM), it will ignore the from_position argument in the play method.

@AlexRixhardson
Copy link
Contributor

This is still the case in the latest 3.2 RC. Does anyone know if this is by design, or is this something that will get fixed?

@KoBeWi
Copy link
Member

KoBeWi commented Dec 19, 2020

Still valid in 3.2.4 beta4

@ellenhp
Copy link
Contributor

ellenhp commented Feb 16, 2021

Seems to be by design. I'm not sure how hard it would be to add this feature though.

https://github.com/godotengine/godot/blob/master/scene/resources/audio_stream_sample.cpp#L38
https://github.com/godotengine/godot/blob/master/scene/resources/audio_stream_sample.cpp#L76

Intuitively, looping involves a seek so I was curious how that's done, but it looks like godot does some clever caching to store the state of the decoder at the loop point. In general it seems like a seek involves a linear search for this compression type.

https://github.com/godotengine/godot/blob/master/scene/resources/audio_stream_sample.cpp#L162-L166

@Calinou
Copy link
Member

Calinou commented Feb 16, 2021

Out of curiosity, is IMA-ADPCM compression still relevant now that we have MP3 support? MP3 decoding should be cheap enough on the CPU for IMA-ADPCM to be irrelevant today.

Of course, we'll have to leave it in 3.2.x but we could consider removing IMA-ADPCM in Godot 4.0.

@darksylinc
Copy link
Contributor

darksylinc commented Sep 14, 2023

Intuitively, looping involves a seek so I was curious how that's done, but it looks like godot does some clever caching to store the state of the decoder at the loop point. In general it seems like a seek involves a linear search for this compression type.

I posted a snippet of our sample code.

Seeking ADPCM is O(1) because all blocks are fixed in size, except for the last block (all block sizes are power of 2).

@wareya
Copy link
Contributor

wareya commented Oct 19, 2023

Godot's implementation of IMA ADPCM doesn't use blocks, at least at the moment.

@darksylinc
Copy link
Contributor

ADPCM is in blocks. Otherwise it's not ADPCM.

You should be able to divide the raw bitstream by bytesPerBlock (accounting that the last block doesn't have the same block size) and start feeding Godot's decoder from the beginning of that block as if it's the beginning of the file and it should work.

@wareya
Copy link
Contributor

wareya commented Oct 19, 2023

I've looked at the implementation*, there are definitely no blocks. It's doing everything that IMA ADPCM does other than the blocks, though, including the shaping and adaptive quantization, so I feel like calling it "not ADPCM" is a bit of a stretch. (Side note: there's a variable for quantization error tracking but it's not actually used. Seems like a bug?)

EDIT: To make it clear, this function is applied to the entire sample buffer at once, not on a per-block basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants