An AudioBuffer
has a data
member of type UInt8Array
holding the audio data. What format is this data, and how can I do signal processing on it?
I’ve tried around a bit with loading a stereo .ogg file, and it seems that each sample is 16 bits, so 2 bytes in the array. Is this always the case or does it depend on the source file? Can I read the samples into, say, a Vector<Float>
, using readShort
, readFloat
or something similar?
I would appreciate any help! I’m using OpenFL 3.6.1.
Nevermind, I figured it out For anyone else having this question: Look at OGG.cpp and the documentation of ov_read
. You can see that it’s always 16-bit, so readShort
is correct. Depending on whether Lime was compiled with HXCPP_BIG_ENDIAN
defined, you have to set the same endianness on your BytesArray
. The missing piece for me was to set it to little endian. Just try the two and see which one works for you.
This works with OGG and 16-bit WAV files. You get values between -32767
and 32768
which you can convert to a -1…+1
range, and back later before writing them to the byte array again.
24- and 32- bit WAV are different, but I’m not interested in these right now.
2 Likes