Blame SOURCES/webrtc-audio-processing-0.2-big-endian.patch

14ed36
diff -up webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc.than webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc
14ed36
--- webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc.than	2016-05-24 08:28:45.749940095 -0400
14ed36
+++ webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc	2016-05-24 08:50:30.361020010 -0400
14ed36
@@ -64,9 +64,6 @@ WavReader::~WavReader() {
14ed36
 }
14ed36
 
14ed36
 size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) {
14ed36
-#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
14ed36
-#error "Need to convert samples to big-endian when reading from WAV file"
14ed36
-#endif
14ed36
   // There could be metadata after the audio; ensure we don't read it.
14ed36
   num_samples = std::min(rtc::checked_cast<uint32_t>(num_samples),
14ed36
                          num_samples_remaining_);
14ed36
@@ -76,6 +73,12 @@ size_t WavReader::ReadSamples(size_t num
14ed36
   RTC_CHECK(read == num_samples || feof(file_handle_));
14ed36
   RTC_CHECK_LE(read, num_samples_remaining_);
14ed36
   num_samples_remaining_ -= rtc::checked_cast<uint32_t>(read);
14ed36
+#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
14ed36
+  //convert to big-endian
14ed36
+  for(size_t idx = 0; idx < num_samples; idx++) {
14ed36
+    samples[idx] = (samples[idx]<<8) | (samples[idx]>>8);
14ed36
+  }
14ed36
+#endif
14ed36
   return read;
14ed36
 }
14ed36
 
14ed36
@@ -120,10 +123,17 @@ WavWriter::~WavWriter() {
14ed36
 
14ed36
 void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) {
14ed36
 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN
14ed36
-#error "Need to convert samples to little-endian when writing to WAV file"
14ed36
-#endif
14ed36
+  int16_t * le_samples = new int16_t[num_samples];
14ed36
+  for(size_t idx = 0; idx < num_samples; idx++) {
14ed36
+    le_samples[idx] = (samples[idx]<<8) | (samples[idx]>>8);
14ed36
+  }
14ed36
+  const size_t written =
14ed36
+      fwrite(le_samples, sizeof(*le_samples), num_samples, file_handle_);
14ed36
+  delete []le_samples;
14ed36
+#else
14ed36
   const size_t written =
14ed36
       fwrite(samples, sizeof(*samples), num_samples, file_handle_);
14ed36
+#endif
14ed36
   RTC_CHECK_EQ(num_samples, written);
14ed36
   num_samples_ += static_cast<uint32_t>(written);
14ed36
   RTC_CHECK(written <= std::numeric_limits<uint32_t>::max() ||
14ed36
diff -up webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc.than webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc
14ed36
--- webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc.than	2016-05-24 08:50:52.591379263 -0400
14ed36
+++ webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc	2016-05-24 08:52:08.552606848 -0400
14ed36
@@ -129,7 +129,39 @@ static inline std::string ReadFourCC(uin
14ed36
   return std::string(reinterpret_cast<char*>(&x), 4);
14ed36
 }
14ed36
 #else
14ed36
-#error "Write be-to-le conversion functions"
14ed36
+static inline void WriteLE16(uint16_t* f, uint16_t x) {
14ed36
+  *f = ((x << 8) & 0xff00)  | ( ( x >> 8) & 0x00ff);
14ed36
+}
14ed36
+
14ed36
+static inline void WriteLE32(uint32_t* f, uint32_t x) {
14ed36
+    *f = ( (x & 0x000000ff) << 24 )
14ed36
+      | ((x & 0x0000ff00) << 8)
14ed36
+      | ((x & 0x00ff0000) >> 8)
14ed36
+      | ((x & 0xff000000) >> 24 );
14ed36
+}
14ed36
+
14ed36
+static inline void WriteFourCC(uint32_t* f, char a, char b, char c, char d) {
14ed36
+    *f = (static_cast<uint32_t>(a) << 24 )
14ed36
+      |  (static_cast<uint32_t>(b) << 16)
14ed36
+      |  (static_cast<uint32_t>(c) << 8)
14ed36
+      |  (static_cast<uint32_t>(d) );
14ed36
+}
14ed36
+
14ed36
+static inline uint16_t ReadLE16(uint16_t x) {
14ed36
+  return  (( x & 0x00ff) << 8 )| ((x & 0xff00)>>8);
14ed36
+}
14ed36
+
14ed36
+static inline uint32_t ReadLE32(uint32_t x) {
14ed36
+  return   ( (x & 0x000000ff) << 24 )
14ed36
+         | ( (x & 0x0000ff00) << 8 )
14ed36
+         | ( (x & 0x00ff0000) >> 8)
14ed36
+         | ( (x & 0xff000000) >> 24 );
14ed36
+}
14ed36
+
14ed36
+static inline std::string ReadFourCC(uint32_t x) {
14ed36
+  x = ReadLE32(x);
14ed36
+  return std::string(reinterpret_cast<char*>(&x), 4);
14ed36
+}
14ed36
 #endif
14ed36
 
14ed36
 static inline uint32_t RiffChunkSize(uint32_t bytes_in_payload) {