From d49a0855a33bb56cc1935642c0d4bf7a3f474fbd Mon Sep 17 00:00:00 2001 From: Manuel Virgilio Date: Thu, 23 Jul 2020 15:12:35 +0200 Subject: [PATCH] Added wav_header be-to-le conversion functions --- webrtc/common_audio/wav_header.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/webrtc/common_audio/wav_header.cc b/webrtc/common_audio/wav_header.cc index d3dca90..0d14e26 100644 --- a/webrtc/common_audio/wav_header.cc +++ b/webrtc/common_audio/wav_header.cc @@ -26,10 +26,6 @@ namespace webrtc { namespace { -#ifndef WEBRTC_ARCH_LITTLE_ENDIAN -#error "Code not working properly for big endian platforms." -#endif - #pragma pack(2) struct ChunkHeader { uint32_t ID; @@ -117,9 +113,22 @@ uint32_t PackFourCC(char a, char b, char c, char d) { return packed_value; } +#ifdef WEBRTC_ARCH_LITTLE_ENDIAN std::string ReadFourCC(uint32_t x) { return std::string(reinterpret_cast(&x), 4); } +#else +static inline uint32_t ReadLE32(uint32_t x) { + return ((x << 24) & 0xFF000000) + | ((x << 8) & 0x00FF0000) + | ((x >> 8) & 0x0000FF00) + | ((x >> 24) & 0x000000FF); +} +std::string ReadFourCC(uint32_t x) { + x = ReadLE32(x); + return std::string(reinterpret_cast(&x), 4); +} +#endif uint16_t MapWavFormatToHeaderField(WavFormat format) { switch (format) { -- GitLab