OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 virtual size_t Read(void* buf, size_t num_bytes) { | 32 virtual size_t Read(void* buf, size_t num_bytes) { |
33 return fread(buf, 1, num_bytes, file_); | 33 return fread(buf, 1, num_bytes, file_); |
34 } | 34 } |
35 | 35 |
36 private: | 36 private: |
37 FILE* file_; | 37 FILE* file_; |
38 }; | 38 }; |
39 | 39 |
40 WavReader::WavReader(const std::string& filename) | 40 WavReader::WavReader(const std::string& filename) |
41 : file_handle_(fopen(filename.c_str(), "rb")) { | 41 : file_handle_(fopen(filename.c_str(), "rb")) { |
42 RTC_CHECK(file_handle_ && "Could not open wav file for reading."); | 42 RTC_CHECK(file_handle_) << "Could not open wav file for reading."; |
43 | 43 |
44 ReadableWavFile readable(file_handle_); | 44 ReadableWavFile readable(file_handle_); |
45 WavFormat format; | 45 WavFormat format; |
46 int bytes_per_sample; | 46 int bytes_per_sample; |
47 RTC_CHECK(ReadWavHeader(&readable, &num_channels_, &sample_rate_, &format, | 47 RTC_CHECK(ReadWavHeader(&readable, &num_channels_, &sample_rate_, &format, |
48 &bytes_per_sample, &num_samples_)); | 48 &bytes_per_sample, &num_samples_)); |
49 num_samples_remaining_ = num_samples_; | 49 num_samples_remaining_ = num_samples_; |
50 RTC_CHECK_EQ(kWavFormat, format); | 50 RTC_CHECK_EQ(kWavFormat, format); |
51 RTC_CHECK_EQ(kBytesPerSample, bytes_per_sample); | 51 RTC_CHECK_EQ(kBytesPerSample, bytes_per_sample); |
52 } | 52 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 RTC_CHECK_EQ(0, fclose(file_handle_)); | 89 RTC_CHECK_EQ(0, fclose(file_handle_)); |
90 file_handle_ = NULL; | 90 file_handle_ = NULL; |
91 } | 91 } |
92 | 92 |
93 WavWriter::WavWriter(const std::string& filename, int sample_rate, | 93 WavWriter::WavWriter(const std::string& filename, int sample_rate, |
94 int num_channels) | 94 int num_channels) |
95 : sample_rate_(sample_rate), | 95 : sample_rate_(sample_rate), |
96 num_channels_(num_channels), | 96 num_channels_(num_channels), |
97 num_samples_(0), | 97 num_samples_(0), |
98 file_handle_(fopen(filename.c_str(), "wb")) { | 98 file_handle_(fopen(filename.c_str(), "wb")) { |
99 RTC_CHECK(file_handle_ && "Could not open wav file for writing."); | 99 RTC_CHECK(file_handle_) << "Could not open wav file for writing."; |
100 RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat, | 100 RTC_CHECK(CheckWavParameters(num_channels_, sample_rate_, kWavFormat, |
101 kBytesPerSample, num_samples_)); | 101 kBytesPerSample, num_samples_)); |
102 | 102 |
103 // Write a blank placeholder header, since we need to know the total number | 103 // Write a blank placeholder header, since we need to know the total number |
104 // of samples before we can fill in the real data. | 104 // of samples before we can fill in the real data. |
105 static const uint8_t blank_header[kWavHeaderSize] = {0}; | 105 static const uint8_t blank_header[kWavHeaderSize] = {0}; |
106 RTC_CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_)); | 106 RTC_CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_)); |
107 } | 107 } |
108 | 108 |
109 WavWriter::~WavWriter() { | 109 WavWriter::~WavWriter() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); | 165 return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); |
166 } | 166 } |
167 | 167 |
168 int rtc_WavNumChannels(const rtc_WavWriter* wf) { | 168 int rtc_WavNumChannels(const rtc_WavWriter* wf) { |
169 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); | 169 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); |
170 } | 170 } |
171 | 171 |
172 uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) { | 172 uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf) { |
173 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); | 173 return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_samples(); |
174 } | 174 } |
OLD | NEW |