Skip to content

Commit

Permalink
save_to_wav: Improve error and remove unhandled format code
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeJayLSP committed Dec 18, 2024
1 parent 6395450 commit ec023b7
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions scene/resources/audio_stream_wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,16 +597,15 @@ Vector<uint8_t> AudioStreamWAV::get_data() const {

Error AudioStreamWAV::save_to_wav(const String &p_path) {
if (format == AudioStreamWAV::FORMAT_IMA_ADPCM || format == AudioStreamWAV::FORMAT_QOA) {
WARN_PRINT("Saving IMA_ADPCM and QOA samples is not supported yet");
return ERR_UNAVAILABLE;
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Saving IMA ADPCM or Quite OK Audio samples is not supported. Quite OK Audio data can still be saved as a .qoa file using FileAccess.");
}

int sub_chunk_2_size = data_bytes; //Subchunk2Size = Size of data in bytes

// Format code
// 1:PCM format (for 8 or 16 bit)
// 3:IEEE float format
int format_code = (format == FORMAT_IMA_ADPCM) ? 3 : 1;
// 1: PCM format (for 8 or 16 bit)
// 17: IMA ADPCM format, unhandled since Godot's IMA ADPCM compression is too messy to be saved.
int format_code = 1;

int n_channels = stereo ? 2 : 1;

Expand All @@ -618,11 +617,9 @@ Error AudioStreamWAV::save_to_wav(const String &p_path) {
byte_pr_sample = 1;
break;
case AudioStreamWAV::FORMAT_16_BITS:
case AudioStreamWAV::FORMAT_QOA:
byte_pr_sample = 2;
break;
case AudioStreamWAV::FORMAT_IMA_ADPCM:
byte_pr_sample = 4;
default:
break;
}

Expand Down Expand Up @@ -661,14 +658,13 @@ Error AudioStreamWAV::save_to_wav(const String &p_path) {
}
break;
case AudioStreamWAV::FORMAT_16_BITS:
case AudioStreamWAV::FORMAT_QOA:
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
default:
// Unsupported.
break;
}

Expand Down

0 comments on commit ec023b7

Please sign in to comment.