[webrtc-audio-processing] 02/04: Add patch to support big endian archs

Felipe Sateler fsateler at moszumanska.debian.org
Tue Jun 7 03:27:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

fsateler pushed a commit to branch master
in repository webrtc-audio-processing.

commit fceccd7473cddf2b73341f45f031b6e5dd6f5fca
Author: Felipe Sateler <fsateler at debian.org>
Date:   Mon Jun 6 12:14:59 2016 -0400

    Add patch to support big endian archs
---
 debian/patches/0002-big-endian-support.patch | 102 +++++++++++++++++++++++++++
 debian/patches/series                        |   1 +
 2 files changed, 103 insertions(+)

diff --git a/debian/patches/0002-big-endian-support.patch b/debian/patches/0002-big-endian-support.patch
new file mode 100644
index 0000000..0493c45
--- /dev/null
+++ b/debian/patches/0002-big-endian-support.patch
@@ -0,0 +1,102 @@
+From: Than <than at redhat.com>
+Date: Mon, 6 Jun 2016 12:08:58 -0400
+Subject: big endian support
+
+https://bugs.freedesktop.org/show_bug.cgi?id=95738
+---
+ webrtc/common_audio/wav_file.cc   | 20 +++++++++++++++-----
+ webrtc/common_audio/wav_header.cc | 34 +++++++++++++++++++++++++++++++++-
+ 2 files changed, 48 insertions(+), 6 deletions(-)
+
+diff --git a/webrtc/common_audio/wav_file.cc b/webrtc/common_audio/wav_file.cc
+index b14b620..05fa052 100644
+--- a/webrtc/common_audio/wav_file.cc
++++ b/webrtc/common_audio/wav_file.cc
+@@ -64,9 +64,6 @@ WavReader::~WavReader() {
+ }
+ 
+ size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) {
+-#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
+-#error "Need to convert samples to big-endian when reading from WAV file"
+-#endif
+   // There could be metadata after the audio; ensure we don't read it.
+   num_samples = std::min(rtc::checked_cast<uint32_t>(num_samples),
+                          num_samples_remaining_);
+@@ -76,6 +73,12 @@ size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) {
+   RTC_CHECK(read == num_samples || feof(file_handle_));
+   RTC_CHECK_LE(read, num_samples_remaining_);
+   num_samples_remaining_ -= rtc::checked_cast<uint32_t>(read);
++#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
++  //convert to big-endian
++  for(size_t idx = 0; idx < num_samples; idx++) {
++    samples[idx] = (samples[idx]<<8) | (samples[idx]>>8);
++  }
++#endif
+   return read;
+ }
+ 
+@@ -120,10 +123,17 @@ WavWriter::~WavWriter() {
+ 
+ void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) {
+ #ifndef WEBRTC_ARCH_LITTLE_ENDIAN
+-#error "Need to convert samples to little-endian when writing to WAV file"
+-#endif
++  int16_t * le_samples = new int16_t[num_samples];
++  for(size_t idx = 0; idx < num_samples; idx++) {
++    le_samples[idx] = (samples[idx]<<8) | (samples[idx]>>8);
++  }
++  const size_t written =
++      fwrite(le_samples, sizeof(*le_samples), num_samples, file_handle_);
++  delete []le_samples;
++#else
+   const size_t written =
+       fwrite(samples, sizeof(*samples), num_samples, file_handle_);
++#endif
+   RTC_CHECK_EQ(num_samples, written);
+   num_samples_ += static_cast<uint32_t>(written);
+   RTC_CHECK(written <= std::numeric_limits<uint32_t>::max() ||
+diff --git a/webrtc/common_audio/wav_header.cc b/webrtc/common_audio/wav_header.cc
+index 61cfffe..53882ff 100644
+--- a/webrtc/common_audio/wav_header.cc
++++ b/webrtc/common_audio/wav_header.cc
+@@ -129,7 +129,39 @@ static inline std::string ReadFourCC(uint32_t x) {
+   return std::string(reinterpret_cast<char*>(&x), 4);
+ }
+ #else
+-#error "Write be-to-le conversion functions"
++static inline void WriteLE16(uint16_t* f, uint16_t x) {
++  *f = ((x << 8) & 0xff00)  | ( ( x >> 8) & 0x00ff);
++}
++
++static inline void WriteLE32(uint32_t* f, uint32_t x) {
++    *f = ( (x & 0x000000ff) << 24 )
++      | ((x & 0x0000ff00) << 8)
++      | ((x & 0x00ff0000) >> 8)
++      | ((x & 0xff000000) >> 24 );
++}
++
++static inline void WriteFourCC(uint32_t* f, char a, char b, char c, char d) {
++    *f = (static_cast<uint32_t>(a) << 24 )
++      |  (static_cast<uint32_t>(b) << 16)
++      |  (static_cast<uint32_t>(c) << 8)
++      |  (static_cast<uint32_t>(d) );
++}
++
++static inline uint16_t ReadLE16(uint16_t x) {
++  return  (( x & 0x00ff) << 8 )| ((x & 0xff00)>>8);
++}
++
++static inline uint32_t ReadLE32(uint32_t x) {
++  return   ( (x & 0x000000ff) << 24 )
++         | ( (x & 0x0000ff00) << 8 )
++         | ( (x & 0x00ff0000) >> 8)
++         | ( (x & 0xff000000) >> 24 );
++}
++
++static inline std::string ReadFourCC(uint32_t x) {
++  x = ReadLE32(x);
++  return std::string(reinterpret_cast<char*>(&x), 4);
++}
+ #endif
+ 
+ static inline uint32_t RiffChunkSize(uint32_t bytes_in_payload) {
diff --git a/debian/patches/series b/debian/patches/series
index d50b358..a5b0673 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-Don-t-error-or-set-options-for-unknown-architectures.patch
+0002-big-endian-support.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-pulseaudio/webrtc-audio-processing.git



More information about the pkg-pulseaudio-devel mailing list