summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandrew@webrtc.org <andrew@webrtc.org>2014-11-03 18:20:06 +0000
committerandrew@webrtc.org <andrew@webrtc.org>2014-11-03 18:20:06 +0000
commit1c755a6308e054fd1c81cea8082515b3ff8639a2 (patch)
treeac915ca344ca75e07683b262007936fb3f5bd712
parent7e2ad876db743f9c20671750b948cac3aa1c524b (diff)
downloadwebrtc-1c755a6308e054fd1c81cea8082515b3ff8639a2.tar.gz
Restore the void return type on WriteWavHeader.
Karl pointed out that the user can check the validity of the input parameters with CheckWavParameters prior to calling. TBR=kwiberg Review URL: https://webrtc-codereview.appspot.com/23339004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7597 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r--common_audio/wav_file.cc4
-rw-r--r--common_audio/wav_header.cc8
-rw-r--r--common_audio/wav_header.h4
-rw-r--r--common_audio/wav_header_unittest.cc8
4 files changed, 11 insertions, 13 deletions
diff --git a/common_audio/wav_file.cc b/common_audio/wav_file.cc
index 685f3537..880e1ec4 100644
--- a/common_audio/wav_file.cc
+++ b/common_audio/wav_file.cc
@@ -127,8 +127,8 @@ void WavWriter::WriteSamples(const float* samples, size_t num_samples) {
void WavWriter::Close() {
CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET));
uint8_t header[kWavHeaderSize];
- CHECK(WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat,
- kBytesPerSample, num_samples_));
+ WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat,
+ kBytesPerSample, num_samples_);
CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_));
CHECK_EQ(0, fclose(file_handle_));
file_handle_ = NULL;
diff --git a/common_audio/wav_header.cc b/common_audio/wav_header.cc
index 3182b1ff..8c781fb4 100644
--- a/common_audio/wav_header.cc
+++ b/common_audio/wav_header.cc
@@ -144,15 +144,14 @@ static inline uint16_t BlockAlign(int num_channels, int bytes_per_sample) {
return num_channels * bytes_per_sample;
}
-bool WriteWavHeader(uint8_t* buf,
+void WriteWavHeader(uint8_t* buf,
int num_channels,
int sample_rate,
WavFormat format,
int bytes_per_sample,
uint32_t num_samples) {
- if (!CheckWavParameters(num_channels, sample_rate, format,
- bytes_per_sample, num_samples))
- return false;
+ CHECK(CheckWavParameters(num_channels, sample_rate, format,
+ bytes_per_sample, num_samples));
WavHeader header;
const uint32_t bytes_in_payload = bytes_per_sample * num_samples;
@@ -177,7 +176,6 @@ bool WriteWavHeader(uint8_t* buf,
// Do an extra copy rather than writing everything to buf directly, since buf
// might not be correctly aligned.
memcpy(buf, &header, kWavHeaderSize);
- return true;
}
bool ReadWavHeader(const uint8_t* buf,
diff --git a/common_audio/wav_header.h b/common_audio/wav_header.h
index 0901f970..37f78a6f 100644
--- a/common_audio/wav_header.h
+++ b/common_audio/wav_header.h
@@ -34,8 +34,8 @@ bool CheckWavParameters(int num_channels,
// Write a kWavHeaderSize bytes long WAV header to buf. The payload that
// follows the header is supposed to have the specified number of interleaved
// channels and contain the specified total number of samples of the specified
-// type. Returns false if any of the input parameters are invalid.
-bool WriteWavHeader(uint8_t* buf,
+// type. CHECKs the input parameters for validity.
+void WriteWavHeader(uint8_t* buf,
int num_channels,
int sample_rate,
WavFormat format,
diff --git a/common_audio/wav_header_unittest.cc b/common_audio/wav_header_unittest.cc
index ac79cc16..677affa5 100644
--- a/common_audio/wav_header_unittest.cc
+++ b/common_audio/wav_header_unittest.cc
@@ -48,7 +48,7 @@ TEST(WavHeaderTest, CheckWavParameters) {
webrtc::CheckWavParameters(3, 8000, webrtc::kWavFormatPcm, 1, 5));
}
-TEST(WavHeaderTest, ReadWavHeader) {
+TEST(WavHeaderTest, ReadWavHeaderWithErrors) {
int num_channels = 0;
int sample_rate = 0;
webrtc::WavFormat format = webrtc::kWavFormatPcm;
@@ -120,13 +120,13 @@ TEST(WavHeaderTest, ReadWavHeader) {
&format, &bytes_per_sample, &num_samples));
}
-// Try writing a WAV header and make sure it looks OK.
+// Try writing and reading a valid WAV header and make sure it looks OK.
TEST(WavHeaderTest, WriteAndReadWavHeader) {
static const int kSize = 4 + webrtc::kWavHeaderSize + 4;
uint8_t buf[kSize];
memset(buf, 0xa4, sizeof(buf));
- EXPECT_TRUE(webrtc::WriteWavHeader(
- buf + 4, 17, 12345, webrtc::kWavFormatALaw, 1, 123457689));
+ webrtc::WriteWavHeader(
+ buf + 4, 17, 12345, webrtc::kWavFormatALaw, 1, 123457689);
static const uint8_t kExpectedBuf[] = {
0xa4, 0xa4, 0xa4, 0xa4, // untouched bytes before header
'R', 'I', 'F', 'F',