godot
godot copied to clipboard
AudioStream(Playback)WAV: Use Vectors instead of pointers
Changes the types of (AudioStreamPlaybackWAV::qoa.dec and AudioStreamWAV::data) to use Vectors instead of pointers. This was done with AudioStreamMP3's data between versions 3.x and 4.x of Godot.
Only private variables and function structures were modified, without altering return type, therefore does not break compatibility.
Alongside #95463, this PR makes the AudioStreamWAV and AudioStreamPlaybackWAV classes free of direct memalloc/free calls, and consequently the only memalloc/free calls within the /scene directory.
Does anyone know if using Vector instead of pointers causes audio corruption?
I don't understand why AudioStreamMP3 doesn't match AudioStreamWAV and AudioStreamPlaybackWAV.
Does anyone know if using Vector instead of pointers causes audio corruption?
Most of audio playback works in two ways.
In case of uncompressed (WAV 8/16 bit) it simply copies samples from the data, converts into 32 bit float, then goes into the audio buffer. And with compressed (MP3, QOA, IMA ADPCM) the data goes through a decode process before being sent to the buffer. All access uses some kind of uint8_t pointer.
The only change with this PR is how data is stored in memory. Everything is passed to buffer/decoders using the Vector's pointer anyway, with the advantage of not having explicit memalloc/memfree calls within the class.
Shouldn't cause corruption at all.
One thing I noticed: p_src in do_resample() is essentially the same as base->data + AudioStreamWAV::DATA_PAD, so I changed the code to use it directly.
Rebased on top of master following #95463 merge.
One last force push. Forgot to set all values in the vector to 0 when setting data, this was causing an audible pop when looping a 16-bit stream.
Thanks!