Bug 1408504 - Implement WriteSamples in tests for big endian platforms; r=dminor
authorDan Horák <dan@danny.cz>
Tue, 17 Oct 2017 10:27:12 +0000
changeset 386988 813590fb620c6c66aa241afeccb7ee92c5553fa0
parent 386987 01cdc4cd898b6590ba5de7bf12b6b3670d571405
child 386989 1f4e31d3962603e532f0d3935047925e517f34c4
push id32705
push userryanvm@gmail.com
push dateThu, 19 Oct 2017 01:01:49 +0000
treeherdermozilla-central@a21099ce055f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor
bugs1408504
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1408504 - Implement WriteSamples in tests for big endian platforms; r=dminor Webrtc code supports big endian platforms, but a method in tests lacks a big endian variant. Add it based on WavReader/WavWriter code. MozReview-Commit-ID: A4OTnYlGgvU
media/webrtc/trunk/webrtc/modules/audio_processing/test/test_utils.cc
--- a/media/webrtc/trunk/webrtc/modules/audio_processing/test/test_utils.cc
+++ b/media/webrtc/trunk/webrtc/modules/audio_processing/test/test_utils.cc
@@ -19,17 +19,21 @@ RawFile::RawFile(const std::string& file
     : file_handle_(fopen(filename.c_str(), "wb")) {}
 
 RawFile::~RawFile() {
   fclose(file_handle_);
 }
 
 void RawFile::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 PCM file"
+  //convert to big-endian
+  int16_t* s = (int16_t*)samples;
+  for(size_t idx = 0; idx < num_samples; idx++) {
+    s[idx] = (samples[idx]<<8) | (samples[idx]>>8);
+  }
 #endif
   fwrite(samples, sizeof(*samples), num_samples, file_handle_);
 }
 
 void RawFile::WriteSamples(const float* samples, size_t num_samples) {
   fwrite(samples, sizeof(*samples), num_samples, file_handle_);
 }