|
|
|
@ -123,6 +123,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
|
|
|
|
int format_channels = 0;
|
|
|
|
int format_channels = 0;
|
|
|
|
|
|
|
|
|
|
|
|
AudioStreamSample::LoopMode loop = AudioStreamSample::LOOP_DISABLED;
|
|
|
|
AudioStreamSample::LoopMode loop = AudioStreamSample::LOOP_DISABLED;
|
|
|
|
|
|
|
|
uint16_t compression_code = 1;
|
|
|
|
bool format_found = false;
|
|
|
|
bool format_found = false;
|
|
|
|
bool data_found = false;
|
|
|
|
bool data_found = false;
|
|
|
|
int format_freq = 0;
|
|
|
|
int format_freq = 0;
|
|
|
|
@ -151,11 +152,10 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
|
|
|
|
if (chunkID[0] == 'f' && chunkID[1] == 'm' && chunkID[2] == 't' && chunkID[3] == ' ' && !format_found) {
|
|
|
|
if (chunkID[0] == 'f' && chunkID[1] == 'm' && chunkID[2] == 't' && chunkID[3] == ' ' && !format_found) {
|
|
|
|
/* IS FORMAT CHUNK */
|
|
|
|
/* IS FORMAT CHUNK */
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t compression_code = file->get_16();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Issue: #7755 : Not a bug - usage of other formats (format codes) are unsupported in current importer version.
|
|
|
|
//Issue: #7755 : Not a bug - usage of other formats (format codes) are unsupported in current importer version.
|
|
|
|
//Consider revision for engine version 3.0
|
|
|
|
//Consider revision for engine version 3.0
|
|
|
|
if (compression_code != 1) {
|
|
|
|
compression_code = file->get_16();
|
|
|
|
|
|
|
|
if (compression_code != 1 && compression_code != 3) {
|
|
|
|
ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
|
|
|
|
ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -210,33 +210,37 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
|
|
|
|
|
|
|
|
|
|
|
|
data.resize(frames * format_channels);
|
|
|
|
data.resize(frames * format_channels);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < frames; i++) {
|
|
|
|
if (format_bits == 8) {
|
|
|
|
|
|
|
|
for (int i = 0; i < frames * format_channels; i++) {
|
|
|
|
for (int c = 0; c < format_channels; c++) {
|
|
|
|
// 8 bit samples are UNSIGNED
|
|
|
|
|
|
|
|
|
|
|
|
if (format_bits == 8) {
|
|
|
|
|
|
|
|
// 8 bit samples are UNSIGNED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t s = file->get_8();
|
|
|
|
|
|
|
|
s -= 128;
|
|
|
|
|
|
|
|
int8_t *sp = (int8_t *)&s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data[i * format_channels + c] = float(*sp) / 128.0;
|
|
|
|
data[i] = int8_t(file->get_8() - 128) / 128.f;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (format_bits == 32 && compression_code == 3) {
|
|
|
|
|
|
|
|
for (int i = 0; i < frames * format_channels; i++) {
|
|
|
|
|
|
|
|
//32 bit IEEE Float
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data[i] = file->get_float();
|
|
|
|
//16+ bits samples are SIGNED
|
|
|
|
}
|
|
|
|
// if sample is > 16 bits, just read extra bytes
|
|
|
|
} else if (format_bits == 16) {
|
|
|
|
|
|
|
|
for (int i = 0; i < frames * format_channels; i++) {
|
|
|
|
|
|
|
|
//16 bit SIGNED
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t s = 0;
|
|
|
|
data[i] = int16_t(file->get_16()) / 32768.f;
|
|
|
|
for (int b = 0; b < (format_bits >> 3); b++) {
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (int i = 0; i < frames * format_channels; i++) {
|
|
|
|
|
|
|
|
//16+ bits samples are SIGNED
|
|
|
|
|
|
|
|
// if sample is > 16 bits, just read extra bytes
|
|
|
|
|
|
|
|
|
|
|
|
s |= ((uint32_t)file->get_8()) << (b * 8);
|
|
|
|
uint32_t s = 0;
|
|
|
|
}
|
|
|
|
for (int b = 0; b < (format_bits >> 3); b++) {
|
|
|
|
s <<= (32 - format_bits);
|
|
|
|
|
|
|
|
int32_t ss = s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data[i * format_channels + c] = (ss >> 16) / 32768.0;
|
|
|
|
s |= ((uint32_t)file->get_8()) << (b * 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s <<= (32 - format_bits);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data[i] = (int32_t(s) >> 16) / 32768.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|