-
-
Notifications
You must be signed in to change notification settings - Fork 20.8k
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
AudioStreamWAV locked to 8bit despite having a 16bit option #83912
Comments
PackedByteArray is an array of bytes (8-bit). I assume for things to work with the 16-bit mode, you would need to manually decompose your 16-bit numbers into two bytes (two PackedByteArray elements). Edit: Checked the code and confirmed: int byte_pr_sample = 0;
switch (format) {
case AudioStreamWAV::FORMAT_8_BITS:
byte_pr_sample = 1;
break;
case AudioStreamWAV::FORMAT_16_BITS:
byte_pr_sample = 2;
break;
case AudioStreamWAV::FORMAT_IMA_ADPCM:
byte_pr_sample = 4;
break;
} If so this would need better documentation. |
I'm not expert on audio or byte array stuff, but I believe you'd have to do something like this for your 16-bit samples: var size = 44100 * 10
arr2.resize(size * 2)
for each in size:
var sample = randi_range(-pow(2, 14), pow(2, 14))
arr2.encode_s16(each * 2, sample) Edit: It may need to be // Add data
Vector<uint8_t> stream_data = get_data();
const uint8_t *read_data = stream_data.ptr();
switch (format) {
case AudioStreamWAV::FORMAT_8_BITS:
for (unsigned int i = 0; i < data_bytes; i++) {
uint8_t data_point = (read_data[i] + 128);
file->store_8(data_point);
}
break;
case AudioStreamWAV::FORMAT_16_BITS:
for (unsigned int i = 0; i < data_bytes / 2; i++) {
uint16_t data_point = decode_uint16(&read_data[i * 2]);
file->store_16(data_point);
}
break;
case AudioStreamWAV::FORMAT_IMA_ADPCM:
//Unimplemented
break;
} |
It is indeed the solution to push the 16 bits long frames via encode_u16 as your script shows. The code
And the rec4 file is the 16bit file with the 16 bit sound, as it need to be. Should i close the issue or it need to stay opens to fix the docs? |
And if working with stereo audio, the channel works in a pair.
So it need to have that in the docs as well. All that is counterproductive, but its the nature of the object, but lacks the ease of usage of Vector2 in the AudioStreamGenerator in the pushframe(), that handles both the bitdepth and the stereo issue in a single pass well, just need better documentation in the AudioStreamWAV object. And, there is another more performant way to mescle the arrays? |
Godot version
4.1
System information
linux
Issue description
Yes, the data() Method indeed alerts you that it wants a signed 8 bit array (-128 to 127), but there is a format property that has the enum:
● FORMAT_8_BITS = 0
8-bit audio codec.
● FORMAT_16_BITS = 1
16-bit audio codec.
● FORMAT_IMA_ADPCM = 2
Audio is compressed using IMA ADPCM.
So, it should have suport for 16 bit audio in the data.
But, the alert indeed shows to be true, and even if setting the audio to be 16 bits, a random generator from -64 to 64, produces the same dinamic range, in either 8 or 16 bits.
And the lenght of the 16 bit file is half the lenght of the 8 bit one.
Thats odd.
So, the bitchange instead of changing the depth of volume, changes the lenght of execution.
High resolution audio is a need, and the lenght issue is a undefined behaviours, so that is pretty bugged.
Thats it.
Steps to reproduce
Run the project and see the files
(ajust the path)
Minimal reproduction project
The text was updated successfully, but these errors were encountered: