Cleaning up audio_decoder_test.cc and adding ResampleInputAudioFile
This CL contains some cleaning up and refactoring of audio_decoder_test.cc. A new class ResampleInputAudioFile is created and used in the tests. BUG=3926 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/31779004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7528 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
bool ResampleInputAudioFile::Read(size_t samples,
|
||||
int output_rate_hz,
|
||||
int16_t* destination) {
|
||||
const size_t samples_to_read = samples * file_rate_hz_ / output_rate_hz;
|
||||
CHECK_EQ(samples_to_read * output_rate_hz, samples * file_rate_hz_)
|
||||
<< "Frame size and sample rates don't add up to an integer.";
|
||||
scoped_ptr<int16_t[]> temp_destination(new int16_t[samples_to_read]);
|
||||
if (!InputAudioFile::Read(samples_to_read, temp_destination.get()))
|
||||
return false;
|
||||
resampler_.ResetIfNeeded(
|
||||
file_rate_hz_, output_rate_hz, kResamplerSynchronous);
|
||||
int output_length = 0;
|
||||
CHECK_EQ(resampler_.Push(temp_destination.get(),
|
||||
static_cast<int>(samples_to_read),
|
||||
destination,
|
||||
static_cast<int>(samples),
|
||||
output_length),
|
||||
0);
|
||||
CHECK_EQ(static_cast<int>(samples), output_length);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RESAMPLE_INPUT_AUDIO_FILE_H_
|
||||
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RESAMPLE_INPUT_AUDIO_FILE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/common_audio/resampler/include/resampler.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// Class for handling a looping input audio file with resampling.
|
||||
class ResampleInputAudioFile : public InputAudioFile {
|
||||
public:
|
||||
ResampleInputAudioFile(const std::string file_name, int file_rate_hz)
|
||||
: InputAudioFile(file_name), file_rate_hz_(file_rate_hz) {}
|
||||
|
||||
bool Read(size_t samples, int output_rate_hz, int16_t* destination);
|
||||
|
||||
private:
|
||||
const int file_rate_hz_;
|
||||
Resampler resampler_;
|
||||
DISALLOW_COPY_AND_ASSIGN(ResampleInputAudioFile);
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RESAMPLE_INPUT_AUDIO_FILE_H_
|
||||
Reference in New Issue
Block a user