Merge pull request #10015 from marcelofg55/master

Implement 32 bit IEEE float WAVE format
This commit is contained in:
Thomas Herzog 2017-08-07 23:11:35 +02:00 committed by GitHub
commit 0188ce5c80
1 changed files with 28 additions and 24 deletions

View File

@ -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++) {
// 8 bit samples are UNSIGNED
for (int c = 0; c < format_channels; c++) { 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
if (format_bits == 8) { data[i] = file->get_float();
// 8 bit samples are UNSIGNED }
} else if (format_bits == 16) {
for (int i = 0; i < frames * format_channels; i++) {
//16 bit SIGNED
uint8_t s = file->get_8(); data[i] = int16_t(file->get_16()) / 32768.f;
s -= 128; }
int8_t *sp = (int8_t *)&s; } else {
for (int i = 0; i < frames * format_channels; i++) {
//16+ bits samples are SIGNED
// if sample is > 16 bits, just read extra bytes
data[i * format_channels + c] = float(*sp) / 128.0; uint32_t s = 0;
for (int b = 0; b < (format_bits >> 3); b++) {
} else { s |= ((uint32_t)file->get_8()) << (b * 8);
//16+ bits samples are SIGNED
// if sample is > 16 bits, just read extra bytes
uint32_t s = 0;
for (int b = 0; b < (format_bits >> 3); b++) {
s |= ((uint32_t)file->get_8()) << (b * 8);
}
s <<= (32 - format_bits);
int32_t ss = s;
data[i * format_channels + c] = (ss >> 16) / 32768.0;
} }
s <<= (32 - format_bits);
data[i] = (int32_t(s) >> 16) / 32768.f;
} }
} }