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@7597 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
b81e304ac0
commit
f866b2d9f9
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user