Skip to content

Commit

Permalink
Merge pull request #10001 from MarshallMiller/support-40byte-wave-for…
Browse files Browse the repository at this point in the history
…mat-chunk

support wave files with 40 byte format chunk
  • Loading branch information
tannewt authored Jan 27, 2025
2 parents 65556b4 + 606f56a commit a4e20e0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions shared-module/audiocore/WaveFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ struct wave_format_chunk {
uint32_t byte_rate;
uint16_t block_align;
uint16_t bits_per_sample;
uint16_t extra_params; // Assumed to be zero below.
uint16_t extra_params;
uint16_t valid_bits_per_sample;
uint32_t channel_mask;
uint16_t extended_audio_format;
uint8_t extended_guid[14];
};

void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t *self,
Expand Down Expand Up @@ -56,11 +60,14 @@ void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t *self,
if (bytes_read != format_size) {
}

if (format.audio_format != 1 ||
if ((format_size != 40 && format.audio_format != 1) ||
format.num_channels > 2 ||
format.bits_per_sample > 16 ||
(format_size == 18 &&
format.extra_params != 0)) {
(format_size == 18 && format.extra_params != 0) ||
(format_size == 40 &&
(format.audio_format != 0xfffe ||
format.extended_audio_format != 1 ||
format.valid_bits_per_sample != format.bits_per_sample))) {
mp_raise_ValueError(MP_ERROR_TEXT("Unsupported format"));
}
// Get the sample_rate
Expand Down

0 comments on commit a4e20e0

Please sign in to comment.