Refactoring one of the ACM tests: TestStereo, to follow the style guide.
(First patch: formatting the test file) TEST=audio_coding_module_test Review URL: https://webrtc-codereview.appspot.com/507001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2124 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
61331137b6
commit
a6ecd1ebb5
@ -21,282 +21,212 @@ namespace webrtc {
|
|||||||
|
|
||||||
#define MAX_FILE_NAME_LENGTH_BYTE 500
|
#define MAX_FILE_NAME_LENGTH_BYTE 500
|
||||||
|
|
||||||
PCMFile::PCMFile():
|
PCMFile::PCMFile()
|
||||||
_pcmFile(NULL),
|
: pcm_file_(NULL),
|
||||||
_nSamples10Ms(160),
|
samples_10ms_(160),
|
||||||
_frequency(16000),
|
frequency_(16000),
|
||||||
_endOfFile(false),
|
end_of_file_(false),
|
||||||
_autoRewind(false),
|
auto_rewind_(false),
|
||||||
_rewinded(false),
|
rewinded_(false),
|
||||||
_timestamp(0),
|
read_stereo_(false),
|
||||||
_readStereo(false),
|
save_stereo_(false) {
|
||||||
_saveStereo(false)
|
timestamp_ = (((WebRtc_UWord32)rand() & 0x0000FFFF) << 16) |
|
||||||
{
|
((WebRtc_UWord32)rand() & 0x0000FFFF);
|
||||||
_timestamp = (((WebRtc_UWord32)rand() & 0x0000FFFF) << 16) |
|
|
||||||
((WebRtc_UWord32)rand() & 0x0000FFFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
PCMFile::PCMFile(WebRtc_UWord32 timestamp)
|
||||||
PCMFile::~PCMFile()
|
: pcm_file_(NULL),
|
||||||
{
|
samples_10ms_(160),
|
||||||
if(_pcmFile != NULL)
|
frequency_(16000),
|
||||||
{
|
end_of_file_(false),
|
||||||
fclose(_pcmFile);
|
auto_rewind_(false),
|
||||||
_pcmFile = NULL;
|
rewinded_(false),
|
||||||
}
|
read_stereo_(false),
|
||||||
}
|
save_stereo_(false) {
|
||||||
*/
|
timestamp_ = timestamp;
|
||||||
|
|
||||||
WebRtc_Word16
|
|
||||||
PCMFile::ChooseFile(
|
|
||||||
char* fileName,
|
|
||||||
WebRtc_Word16 maxLen)
|
|
||||||
{
|
|
||||||
char tmpName[MAX_FILE_NAME_LENGTH_BYTE];
|
|
||||||
//strcpy(_fileName, "in.pcm");
|
|
||||||
//printf("\n\nPlease enter the input file: ");
|
|
||||||
EXPECT_TRUE(fgets(tmpName, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL);
|
|
||||||
tmpName[MAX_FILE_NAME_LENGTH_BYTE-1] = '\0';
|
|
||||||
WebRtc_Word16 n = 0;
|
|
||||||
|
|
||||||
// removing leading spaces
|
|
||||||
while((isspace(tmpName[n]) || iscntrl(tmpName[n])) &&
|
|
||||||
(tmpName[n] != 0) &&
|
|
||||||
(n < MAX_FILE_NAME_LENGTH_BYTE))
|
|
||||||
{
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
if(n > 0)
|
|
||||||
{
|
|
||||||
memmove(tmpName, &tmpName[n], MAX_FILE_NAME_LENGTH_BYTE - n);
|
|
||||||
}
|
|
||||||
|
|
||||||
//removing trailing spaces
|
|
||||||
n = (WebRtc_Word16)(strlen(tmpName) - 1);
|
|
||||||
if(n >= 0)
|
|
||||||
{
|
|
||||||
while((isspace(tmpName[n]) || iscntrl(tmpName[n])) &&
|
|
||||||
(n >= 0))
|
|
||||||
{
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(n >= 0)
|
|
||||||
{
|
|
||||||
tmpName[n + 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
WebRtc_Word16 len = (WebRtc_Word16)strlen(tmpName);
|
|
||||||
if(len > maxLen)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(len > 0)
|
|
||||||
{
|
|
||||||
strncpy(fileName, tmpName, len+1);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_Word16
|
WebRtc_Word16 PCMFile::ChooseFile(char* filename, WebRtc_Word16 max_len) {
|
||||||
PCMFile::ChooseFile(
|
char tmp_name[MAX_FILE_NAME_LENGTH_BYTE];
|
||||||
char* fileName,
|
|
||||||
WebRtc_Word16 maxLen,
|
|
||||||
WebRtc_UWord16* frequencyHz)
|
|
||||||
{
|
|
||||||
char tmpName[MAX_FILE_NAME_LENGTH_BYTE];
|
|
||||||
//strcpy(_fileName, "in.pcm");
|
|
||||||
//printf("\n\nPlease enter the input file: ");
|
|
||||||
EXPECT_TRUE(fgets(tmpName, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL);
|
|
||||||
tmpName[MAX_FILE_NAME_LENGTH_BYTE-1] = '\0';
|
|
||||||
WebRtc_Word16 n = 0;
|
|
||||||
|
|
||||||
// removing leading spaces
|
EXPECT_TRUE(fgets(tmp_name, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL);
|
||||||
while((isspace(tmpName[n]) || iscntrl(tmpName[n])) &&
|
tmp_name[MAX_FILE_NAME_LENGTH_BYTE - 1] = '\0';
|
||||||
(tmpName[n] != 0) &&
|
WebRtc_Word16 n = 0;
|
||||||
(n < MAX_FILE_NAME_LENGTH_BYTE))
|
|
||||||
{
|
// Removing leading spaces.
|
||||||
n++;
|
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0)
|
||||||
|
&& (n < MAX_FILE_NAME_LENGTH_BYTE)) {
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if (n > 0) {
|
||||||
|
memmove(tmp_name, &tmp_name[n], MAX_FILE_NAME_LENGTH_BYTE - n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removing trailing spaces.
|
||||||
|
n = (WebRtc_Word16)(strlen(tmp_name) - 1);
|
||||||
|
if (n >= 0) {
|
||||||
|
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (n >= 0)) {
|
||||||
|
n--;
|
||||||
}
|
}
|
||||||
if(n > 0)
|
}
|
||||||
{
|
if (n >= 0) {
|
||||||
memmove(tmpName, &tmpName[n], MAX_FILE_NAME_LENGTH_BYTE - n);
|
tmp_name[n + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtc_Word16 len = (WebRtc_Word16) strlen(tmp_name);
|
||||||
|
if (len > max_len) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (len > 0) {
|
||||||
|
strncpy(filename, tmp_name, len + 1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtc_Word16 PCMFile::ChooseFile(char* filename, WebRtc_Word16 max_len,
|
||||||
|
WebRtc_UWord16* frequency_hz) {
|
||||||
|
char tmp_name[MAX_FILE_NAME_LENGTH_BYTE];
|
||||||
|
|
||||||
|
EXPECT_TRUE(fgets(tmp_name, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL);
|
||||||
|
tmp_name[MAX_FILE_NAME_LENGTH_BYTE - 1] = '\0';
|
||||||
|
WebRtc_Word16 n = 0;
|
||||||
|
|
||||||
|
// Removing trailing spaces.
|
||||||
|
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0)
|
||||||
|
&& (n < MAX_FILE_NAME_LENGTH_BYTE)) {
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if (n > 0) {
|
||||||
|
memmove(tmp_name, &tmp_name[n], MAX_FILE_NAME_LENGTH_BYTE - n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removing trailing spaces.
|
||||||
|
n = (WebRtc_Word16)(strlen(tmp_name) - 1);
|
||||||
|
if (n >= 0) {
|
||||||
|
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (n >= 0)) {
|
||||||
|
n--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (n >= 0) {
|
||||||
|
tmp_name[n + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
//removing trailing spaces
|
WebRtc_Word16 len = (WebRtc_Word16) strlen(tmp_name);
|
||||||
n = (WebRtc_Word16)(strlen(tmpName) - 1);
|
if (len > max_len) {
|
||||||
if(n >= 0)
|
return -1;
|
||||||
{
|
}
|
||||||
while((isspace(tmpName[n]) || iscntrl(tmpName[n])) &&
|
if (len > 0) {
|
||||||
(n >= 0))
|
strncpy(filename, tmp_name, len + 1);
|
||||||
{
|
}
|
||||||
n--;
|
printf("Enter the sampling frequency (in Hz) of the above file [%u]: ",
|
||||||
}
|
*frequency_hz);
|
||||||
|
EXPECT_TRUE(fgets(tmp_name, 10, stdin) != NULL);
|
||||||
|
WebRtc_UWord16 tmp_frequency = (WebRtc_UWord16) atoi(tmp_name);
|
||||||
|
if (tmp_frequency > 0) {
|
||||||
|
*frequency_hz = tmp_frequency;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PCMFile::Open(const char* filename, WebRtc_UWord16 frequency,
|
||||||
|
const char* mode, bool auto_rewind) {
|
||||||
|
if ((pcm_file_ = fopen(filename, mode)) == NULL) {
|
||||||
|
printf("Cannot open file %s.\n", filename);
|
||||||
|
ADD_FAILURE() << "Unable to read file";
|
||||||
|
}
|
||||||
|
frequency_ = frequency;
|
||||||
|
samples_10ms_ = (WebRtc_UWord16)(frequency_ / 100);
|
||||||
|
auto_rewind_ = auto_rewind;
|
||||||
|
end_of_file_ = false;
|
||||||
|
rewinded_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtc_Word32 PCMFile::SamplingFrequency() const {
|
||||||
|
return frequency_;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtc_UWord16 PCMFile::PayloadLength10Ms() const {
|
||||||
|
return samples_10ms_;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtc_Word32 PCMFile::Read10MsData(AudioFrame& audio_frame) {
|
||||||
|
WebRtc_UWord16 channels = 1;
|
||||||
|
if (read_stereo_) {
|
||||||
|
channels = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtc_Word32 payload_size = (WebRtc_Word32) fread(audio_frame._payloadData,
|
||||||
|
sizeof(WebRtc_UWord16),
|
||||||
|
samples_10ms_ * channels,
|
||||||
|
pcm_file_);
|
||||||
|
if (payload_size < samples_10ms_ * channels) {
|
||||||
|
for (int k = payload_size; k < samples_10ms_ * channels; k++) {
|
||||||
|
audio_frame._payloadData[k] = 0;
|
||||||
}
|
}
|
||||||
if(n >= 0)
|
if (auto_rewind_) {
|
||||||
{
|
rewind(pcm_file_);
|
||||||
tmpName[n + 1] = '\0';
|
rewinded_ = true;
|
||||||
|
} else {
|
||||||
|
end_of_file_ = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
audio_frame._payloadDataLengthInSamples = samples_10ms_;
|
||||||
|
audio_frame._frequencyInHz = frequency_;
|
||||||
|
audio_frame._audioChannel = channels;
|
||||||
|
audio_frame._timeStamp = timestamp_;
|
||||||
|
timestamp_ += samples_10ms_;
|
||||||
|
return samples_10ms_;
|
||||||
|
}
|
||||||
|
|
||||||
WebRtc_Word16 len = (WebRtc_Word16)strlen(tmpName);
|
void PCMFile::Write10MsData(AudioFrame& audio_frame) {
|
||||||
if(len > maxLen)
|
if (audio_frame._audioChannel == 1) {
|
||||||
{
|
if (!save_stereo_) {
|
||||||
return -1;
|
fwrite(audio_frame._payloadData, sizeof(WebRtc_UWord16),
|
||||||
}
|
audio_frame._payloadDataLengthInSamples, pcm_file_);
|
||||||
if(len > 0)
|
} else {
|
||||||
{
|
WebRtc_Word16* stereo_audio =
|
||||||
strncpy(fileName, tmpName, len+1);
|
new WebRtc_Word16[2 * audio_frame._payloadDataLengthInSamples];
|
||||||
|
int k;
|
||||||
|
for (k = 0; k < audio_frame._payloadDataLengthInSamples; k++) {
|
||||||
|
stereo_audio[k << 1] = audio_frame._payloadData[k];
|
||||||
|
stereo_audio[(k << 1) + 1] = audio_frame._payloadData[k];
|
||||||
|
}
|
||||||
|
fwrite(stereo_audio, sizeof(WebRtc_Word16),
|
||||||
|
2 * audio_frame._payloadDataLengthInSamples, pcm_file_);
|
||||||
|
delete[] stereo_audio;
|
||||||
}
|
}
|
||||||
printf("Enter the sampling frequency (in Hz) of the above file [%u]: ", *frequencyHz);
|
} else {
|
||||||
EXPECT_TRUE(fgets(tmpName, 10, stdin) != NULL);
|
fwrite(audio_frame._payloadData, sizeof(WebRtc_Word16),
|
||||||
WebRtc_UWord16 tmpFreq = (WebRtc_UWord16)atoi(tmpName);
|
audio_frame._audioChannel * audio_frame._payloadDataLengthInSamples,
|
||||||
if(tmpFreq > 0)
|
pcm_file_);
|
||||||
{
|
}
|
||||||
*frequencyHz = tmpFreq;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PCMFile::Write10MsData(WebRtc_Word16* playout_buffer,
|
||||||
PCMFile::Open(
|
WebRtc_UWord16 length_smpls) {
|
||||||
const char* filename,
|
fwrite(playout_buffer, sizeof(WebRtc_UWord16), length_smpls, pcm_file_);
|
||||||
WebRtc_UWord16 frequency,
|
|
||||||
const char* mode,
|
|
||||||
bool autoRewind)
|
|
||||||
{
|
|
||||||
if ((_pcmFile = fopen(filename, mode)) == NULL)
|
|
||||||
{
|
|
||||||
printf("Cannot open file %s.\n", filename);
|
|
||||||
ADD_FAILURE() << "Unable to read file";
|
|
||||||
}
|
|
||||||
_frequency = frequency;
|
|
||||||
_nSamples10Ms = (WebRtc_UWord16)(_frequency / 100);
|
|
||||||
_autoRewind = autoRewind;
|
|
||||||
_endOfFile = false;
|
|
||||||
_rewinded = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_Word32
|
void PCMFile::Close() {
|
||||||
PCMFile::SamplingFrequency() const
|
fclose(pcm_file_);
|
||||||
{
|
pcm_file_ = NULL;
|
||||||
return _frequency;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_UWord16
|
void PCMFile::Rewind() {
|
||||||
PCMFile::PayloadLength10Ms() const
|
rewind(pcm_file_);
|
||||||
{
|
end_of_file_ = false;
|
||||||
return _nSamples10Ms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_Word32
|
bool PCMFile::Rewinded() {
|
||||||
PCMFile::Read10MsData(
|
return rewinded_;
|
||||||
AudioFrame& audioFrame)
|
|
||||||
{
|
|
||||||
WebRtc_UWord16 noChannels = 1;
|
|
||||||
if (_readStereo)
|
|
||||||
{
|
|
||||||
noChannels = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebRtc_Word32 payloadSize = (WebRtc_Word32)fread(audioFrame._payloadData, sizeof(WebRtc_UWord16), _nSamples10Ms*noChannels, _pcmFile);
|
|
||||||
if (payloadSize < _nSamples10Ms*noChannels) {
|
|
||||||
for (int k = payloadSize; k < _nSamples10Ms*noChannels; k++)
|
|
||||||
{
|
|
||||||
audioFrame._payloadData[k] = 0;
|
|
||||||
}
|
|
||||||
if(_autoRewind)
|
|
||||||
{
|
|
||||||
rewind(_pcmFile);
|
|
||||||
_rewinded = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_endOfFile = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
audioFrame._payloadDataLengthInSamples = _nSamples10Ms;
|
|
||||||
audioFrame._frequencyInHz = _frequency;
|
|
||||||
audioFrame._audioChannel = noChannels;
|
|
||||||
audioFrame._timeStamp = _timestamp;
|
|
||||||
_timestamp += _nSamples10Ms;
|
|
||||||
return _nSamples10Ms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PCMFile::SaveStereo(bool is_stereo) {
|
||||||
PCMFile::Write10MsData(
|
save_stereo_ = is_stereo;
|
||||||
AudioFrame& audioFrame)
|
|
||||||
{
|
|
||||||
if(audioFrame._audioChannel == 1)
|
|
||||||
{
|
|
||||||
if(!_saveStereo)
|
|
||||||
{
|
|
||||||
fwrite(audioFrame._payloadData, sizeof(WebRtc_UWord16),
|
|
||||||
audioFrame._payloadDataLengthInSamples, _pcmFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WebRtc_Word16* stereoAudio = new WebRtc_Word16[2 *
|
|
||||||
audioFrame._payloadDataLengthInSamples];
|
|
||||||
int k;
|
|
||||||
for(k = 0; k < audioFrame._payloadDataLengthInSamples; k++)
|
|
||||||
{
|
|
||||||
stereoAudio[k<<1] = audioFrame._payloadData[k];
|
|
||||||
stereoAudio[(k<<1) + 1] = audioFrame._payloadData[k];
|
|
||||||
}
|
|
||||||
fwrite(stereoAudio, sizeof(WebRtc_Word16), 2*audioFrame._payloadDataLengthInSamples,
|
|
||||||
_pcmFile);
|
|
||||||
delete [] stereoAudio;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fwrite(audioFrame._payloadData, sizeof(WebRtc_Word16),
|
|
||||||
audioFrame._audioChannel * audioFrame._payloadDataLengthInSamples, _pcmFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PCMFile::ReadStereo(bool is_stereo) {
|
||||||
void
|
read_stereo_ = is_stereo;
|
||||||
PCMFile::Write10MsData(
|
|
||||||
WebRtc_Word16* playoutBuffer,
|
|
||||||
WebRtc_UWord16 playoutLengthSmpls)
|
|
||||||
{
|
|
||||||
fwrite(playoutBuffer, sizeof(WebRtc_UWord16), playoutLengthSmpls, _pcmFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
void
|
|
||||||
PCMFile::Close()
|
|
||||||
{
|
|
||||||
fclose(_pcmFile);
|
|
||||||
_pcmFile = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PCMFile::Rewind()
|
|
||||||
{
|
|
||||||
rewind(_pcmFile);
|
|
||||||
_endOfFile = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
PCMFile::Rewinded()
|
|
||||||
{
|
|
||||||
return _rewinded;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PCMFile::SaveStereo(
|
|
||||||
bool saveStereo)
|
|
||||||
{
|
|
||||||
_saveStereo = saveStereo;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PCMFile::ReadStereo(
|
|
||||||
bool readStereo)
|
|
||||||
{
|
|
||||||
_readStereo = readStereo;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace webrtc
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license
|
* 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
|
* that can be found in the LICENSE file in the root of the source
|
||||||
@ -8,60 +8,60 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PCMFILE_H
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_
|
||||||
#define PCMFILE_H
|
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_
|
||||||
|
|
||||||
#include "typedefs.h"
|
|
||||||
#include "module_common_types.h"
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "module_common_types.h"
|
||||||
|
#include "typedefs.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class PCMFile
|
class PCMFile {
|
||||||
{
|
public:
|
||||||
public:
|
PCMFile();
|
||||||
PCMFile();
|
PCMFile(WebRtc_UWord32 timestamp);
|
||||||
~PCMFile()
|
~PCMFile() {
|
||||||
{
|
if (pcm_file_ != NULL) {
|
||||||
if(_pcmFile != NULL)
|
fclose(pcm_file_);
|
||||||
{
|
|
||||||
fclose(_pcmFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void Open(const char *filename, WebRtc_UWord16 frequency, const char *mode,
|
}
|
||||||
bool autoRewind = false);
|
void Open(const char *filename, WebRtc_UWord16 frequency, const char *mode,
|
||||||
|
bool auto_rewind = false);
|
||||||
WebRtc_Word32 Read10MsData(AudioFrame& audioFrame);
|
|
||||||
|
|
||||||
void Write10MsData(WebRtc_Word16 *playoutBuffer, WebRtc_UWord16 playoutLengthSmpls);
|
|
||||||
void Write10MsData(AudioFrame& audioFrame);
|
|
||||||
|
|
||||||
WebRtc_UWord16 PayloadLength10Ms() const;
|
WebRtc_Word32 Read10MsData(AudioFrame& audio_frame);
|
||||||
WebRtc_Word32 SamplingFrequency() const;
|
|
||||||
void Close();
|
void Write10MsData(WebRtc_Word16 *playout_buffer,
|
||||||
bool EndOfFile() const { return _endOfFile; }
|
WebRtc_UWord16 length_smpls);
|
||||||
void Rewind();
|
void Write10MsData(AudioFrame& audio_frame);
|
||||||
static WebRtc_Word16 ChooseFile(char* fileName, WebRtc_Word16 maxLen,
|
|
||||||
WebRtc_UWord16* frequencyHz);
|
WebRtc_UWord16 PayloadLength10Ms() const;
|
||||||
static WebRtc_Word16 ChooseFile(char* fileName, WebRtc_Word16 maxLen);
|
WebRtc_Word32 SamplingFrequency() const;
|
||||||
bool Rewinded();
|
void Close();
|
||||||
void SaveStereo(
|
bool EndOfFile() const {
|
||||||
bool saveStereo = true);
|
return end_of_file_;
|
||||||
void ReadStereo(
|
}
|
||||||
bool readStereo = true);
|
void Rewind();
|
||||||
private:
|
static WebRtc_Word16 ChooseFile(char* filename, WebRtc_Word16 max_len,
|
||||||
FILE* _pcmFile;
|
WebRtc_UWord16* frequency_hz);
|
||||||
WebRtc_UWord16 _nSamples10Ms;
|
static WebRtc_Word16 ChooseFile(char* filename, WebRtc_Word16 max_len);
|
||||||
WebRtc_Word32 _frequency;
|
bool Rewinded();
|
||||||
bool _endOfFile;
|
void SaveStereo(bool is_stereo = true);
|
||||||
bool _autoRewind;
|
void ReadStereo(bool is_stereo = true);
|
||||||
bool _rewinded;
|
private:
|
||||||
WebRtc_UWord32 _timestamp;
|
FILE* pcm_file_;
|
||||||
bool _readStereo;
|
WebRtc_UWord16 samples_10ms_;
|
||||||
bool _saveStereo;
|
WebRtc_Word32 frequency_;
|
||||||
|
bool end_of_file_;
|
||||||
|
bool auto_rewind_;
|
||||||
|
bool rewinded_;
|
||||||
|
WebRtc_UWord32 timestamp_;
|
||||||
|
bool read_stereo_;
|
||||||
|
bool save_stereo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif
|
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,8 +8,8 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TEST_STEREO_H
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TEST_STEREO_H_
|
||||||
#define TEST_STEREO_H
|
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TEST_STEREO_H_
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -20,106 +20,99 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
enum StereoMonoMode {
|
enum StereoMonoMode {
|
||||||
kNotSet,
|
kNotSet,
|
||||||
kMono,
|
kMono,
|
||||||
kStereo
|
kStereo
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestPackStereo : public AudioPacketizationCallback
|
class TestPackStereo : public AudioPacketizationCallback {
|
||||||
{
|
public:
|
||||||
public:
|
TestPackStereo();
|
||||||
TestPackStereo();
|
~TestPackStereo();
|
||||||
~TestPackStereo();
|
|
||||||
|
|
||||||
void RegisterReceiverACM(AudioCodingModule* acm);
|
|
||||||
|
|
||||||
virtual WebRtc_Word32 SendData(const FrameType frameType,
|
|
||||||
const WebRtc_UWord8 payloadType,
|
|
||||||
const WebRtc_UWord32 timeStamp,
|
|
||||||
const WebRtc_UWord8* payloadData,
|
|
||||||
const WebRtc_UWord16 payloadSize,
|
|
||||||
const RTPFragmentationHeader* fragmentation);
|
|
||||||
|
|
||||||
WebRtc_UWord16 GetPayloadSize();
|
void RegisterReceiverACM(AudioCodingModule* acm);
|
||||||
WebRtc_UWord32 GetTimeStampDiff();
|
|
||||||
void ResetPayloadSize();
|
|
||||||
void set_codec_mode(StereoMonoMode mode);
|
|
||||||
void set_lost_packet(bool lost);
|
|
||||||
|
|
||||||
private:
|
virtual WebRtc_Word32 SendData(const FrameType frame_type,
|
||||||
AudioCodingModule* _receiverACM;
|
const WebRtc_UWord8 payload_type,
|
||||||
WebRtc_Word16 _seqNo;
|
const WebRtc_UWord32 timestamp,
|
||||||
WebRtc_UWord8 _payloadData[60 * 32 * 2 * 2];
|
const WebRtc_UWord8* payload_data,
|
||||||
WebRtc_UWord32 _timeStampDiff;
|
const WebRtc_UWord16 payload_size,
|
||||||
WebRtc_UWord32 _lastInTimestamp;
|
const RTPFragmentationHeader* fragmentation);
|
||||||
WebRtc_UWord64 _totalBytes;
|
|
||||||
WebRtc_UWord16 _payloadSize;
|
WebRtc_UWord16 payload_size();
|
||||||
StereoMonoMode _codec_mode;
|
WebRtc_UWord32 timestamp_diff();
|
||||||
// Simulate packet losses
|
void reset_payload_size();
|
||||||
bool _lost_packet;
|
void set_codec_mode(StereoMonoMode mode);
|
||||||
|
void set_lost_packet(bool lost);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AudioCodingModule* receiver_acm_;
|
||||||
|
WebRtc_Word16 seq_no_;
|
||||||
|
WebRtc_UWord8 payload_data_[60 * 32 * 2 * 2];
|
||||||
|
WebRtc_UWord32 timestamp_diff_;
|
||||||
|
WebRtc_UWord32 last_in_timestamp_;
|
||||||
|
WebRtc_UWord64 total_bytes_;
|
||||||
|
WebRtc_UWord16 payload_size_;
|
||||||
|
StereoMonoMode codec_mode_;
|
||||||
|
// Simulate packet losses
|
||||||
|
bool lost_packet_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestStereo : public ACMTest
|
class TestStereo : public ACMTest {
|
||||||
{
|
public:
|
||||||
public:
|
TestStereo(int test_mode);
|
||||||
TestStereo(int testMode);
|
~TestStereo();
|
||||||
~TestStereo();
|
|
||||||
|
|
||||||
void Perform();
|
void Perform();
|
||||||
private:
|
private:
|
||||||
// The default value of '-1' indicates that the registration is based only on codec name
|
// The default value of '-1' indicates that the registration is based only on
|
||||||
// and a sampling frequncy matching is not required. This is useful for codecs which support
|
// codec name and a sampling frequncy matching is not required. This is useful
|
||||||
// several sampling frequency.
|
// for codecs which support several sampling frequency.
|
||||||
WebRtc_Word16 RegisterSendCodec(char side,
|
WebRtc_Word16 RegisterSendCodec(char side, char* codec_name,
|
||||||
char* codecName,
|
WebRtc_Word32 samp_freq_hz, int rate,
|
||||||
WebRtc_Word32 sampFreqHz,
|
int pack_size, int channels,
|
||||||
int rate,
|
int payload_type);
|
||||||
int packSize,
|
|
||||||
int channels,
|
|
||||||
int payload_type);
|
|
||||||
|
|
||||||
void Run(TestPackStereo* channel, int in_channels, int out_channels,
|
void Run(TestPackStereo* channel, int in_channels, int out_channels,
|
||||||
int percent_loss = 0);
|
int percent_loss = 0);
|
||||||
void OpenOutFile(WebRtc_Word16 testNumber);
|
void OpenOutFile(WebRtc_Word16 test_number);
|
||||||
void DisplaySendReceiveCodec();
|
void DisplaySendReceiveCodec();
|
||||||
|
|
||||||
WebRtc_Word32 SendData(
|
WebRtc_Word32 SendData(const FrameType frame_type,
|
||||||
const FrameType frameType,
|
const WebRtc_UWord8 payload_type,
|
||||||
const WebRtc_UWord8 payloadType,
|
const WebRtc_UWord32 timestamp,
|
||||||
const WebRtc_UWord32 timeStamp,
|
const WebRtc_UWord8* payload_data,
|
||||||
const WebRtc_UWord8* payloadData,
|
const WebRtc_UWord16 payload_size,
|
||||||
const WebRtc_UWord16 payloadSize,
|
const RTPFragmentationHeader* fragmentation);
|
||||||
const RTPFragmentationHeader* fragmentation);
|
|
||||||
|
|
||||||
int _testMode;
|
int test_mode_;
|
||||||
|
|
||||||
AudioCodingModule* _acmA;
|
AudioCodingModule* acm_a_;
|
||||||
AudioCodingModule* _acmB;
|
AudioCodingModule* acm_b_;
|
||||||
|
|
||||||
TestPackStereo* _channelA2B;
|
TestPackStereo* channel_a2b_;
|
||||||
|
|
||||||
PCMFile _in_file_stereo;
|
PCMFile* in_file_stereo_;
|
||||||
PCMFile _in_file_mono;
|
PCMFile* in_file_mono_;
|
||||||
PCMFile _outFileB;
|
PCMFile out_file_;
|
||||||
WebRtc_Word16 _testCntr;
|
WebRtc_Word16 test_cntr_;
|
||||||
WebRtc_UWord16 _packSizeSamp;
|
WebRtc_UWord16 pack_size_samp_;
|
||||||
WebRtc_UWord16 _packSizeBytes;
|
WebRtc_UWord16 pack_size_bytes_;
|
||||||
int _counter;
|
int counter_;
|
||||||
|
|
||||||
// Payload types for stereo codecs and CNG
|
// Payload types for stereo codecs and CNG
|
||||||
int g722_pltype_;
|
int g722_pltype_;
|
||||||
int l16_8khz_pltype_;
|
int l16_8khz_pltype_;
|
||||||
int l16_16khz_pltype_;
|
int l16_16khz_pltype_;
|
||||||
int l16_32khz_pltype_;
|
int l16_32khz_pltype_;
|
||||||
int pcma_pltype_;
|
int pcma_pltype_;
|
||||||
int pcmu_pltype_;
|
int pcmu_pltype_;
|
||||||
int celt_pltype_;
|
int celt_pltype_;
|
||||||
int cn_8khz_pltype_;
|
int cn_8khz_pltype_;
|
||||||
int cn_16khz_pltype_;
|
int cn_16khz_pltype_;
|
||||||
int cn_32khz_pltype_;
|
int cn_32khz_pltype_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TEST_STEREO_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user