0 votes

Is anyone familiar with the AudioStreamPlayer? I'm trying to extract audio amplitude from wav files and found that I can access the raw audio data in AudioStreamPlayer.stream.data, but it's stored in a PoolByteArray. I need to convert this into a format where I can read the sample values (probably float?)...maybe PoolRealArray, but that doesn't seem to be exposed to GDScript. StreamPeerBuffer is supposed to provide array conversion, but I don't understand how to use it. I wrote a successful mock-up of this concept in RayLib, but the audio samples there are already provided as a float array. I can calculate a play head position with sufficient accuracy if I can figure out how to convert the byte data to actual samples.

in Engine by (46 points)

1 Answer

0 votes

Hi, you can use StreamPeerBuffer. Just feed it with the data you have in AudioStreamPlayer.stream.data:

var buf = StreamPeerBuffer.new()
buf.data_array = AudioStreamPlayer.stream.data

and then get the values in any way you want: buf.get_float(), buf.get_u32(), etc.

by (21 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.