Reformat the WebRTC code base
Running clang-format with chromium's style guide. The goal is n-fold: * providing consistency and readability (that's what code guidelines are for) * preventing noise with presubmit checks and git cl format * building on the previous point: making it easier to automatically fix format issues * you name it Please consider using git-hyper-blame to ignore this commit. Bug: webrtc:9340 Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87 Reviewed-on: https://webrtc-review.googlesource.com/81185 Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23660}
This commit is contained in:
@ -123,7 +123,7 @@ AudioEncoder::EncodedInfo AudioEncoderG722Impl::EncodeImpl(
|
||||
const size_t bytes_to_encode = samples_per_channel / 2 * num_channels_;
|
||||
EncodedInfo info;
|
||||
info.encoded_bytes = encoded->AppendData(
|
||||
bytes_to_encode, [&] (rtc::ArrayView<uint8_t> encoded) {
|
||||
bytes_to_encode, [&](rtc::ArrayView<uint8_t> encoded) {
|
||||
// Interleave the encoded bytes of the different channels. Each separate
|
||||
// channel and the interleaved stream encodes two samples per byte, most
|
||||
// significant half first.
|
||||
|
||||
@ -46,8 +46,8 @@ class AudioEncoderG722Impl final : public AudioEncoder {
|
||||
// The encoder state for one channel.
|
||||
struct EncoderState {
|
||||
G722EncInst* encoder;
|
||||
std::unique_ptr<int16_t[]> speech_buffer; // Queued up for encoding.
|
||||
rtc::Buffer encoded_buffer; // Already encoded.
|
||||
std::unique_ptr<int16_t[]> speech_buffer; // Queued up for encoding.
|
||||
rtc::Buffer encoded_buffer; // Already encoded.
|
||||
EncoderState();
|
||||
~EncoderState();
|
||||
};
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
*
|
||||
* Copyright (C) 2005 Steve Underwood
|
||||
*
|
||||
* Despite my general liking of the GPL, I place my own contributions
|
||||
* Despite my general liking of the GPL, I place my own contributions
|
||||
* to this code in the public domain for the benefit of all mankind -
|
||||
* even the slimy ones who might try to proprietize my work and use it
|
||||
* to my detriment.
|
||||
@ -25,7 +25,6 @@
|
||||
* -Added new defines for minimum and maximum values of short int
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#if !defined(_G722_ENC_DEC_H_)
|
||||
@ -35,12 +34,14 @@
|
||||
|
||||
/*! \page g722_page G.722 encoding and decoding
|
||||
\section g722_page_sec_1 What does it do?
|
||||
The G.722 module is a bit exact implementation of the ITU G.722 specification for all three
|
||||
specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
|
||||
The G.722 module is a bit exact implementation of the ITU G.722 specification
|
||||
for all three specified bit rates - 64000bps, 56000bps and 48000bps. It passes
|
||||
the ITU tests.
|
||||
|
||||
To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
|
||||
support an option for the linear audio to be an 8k samples/second stream. In this mode the
|
||||
codec is considerably faster, and still fully compatible with wideband terminals using G.722.
|
||||
To allow fast and flexible interworking with narrow band telephony, the encoder
|
||||
and decoder support an option for the linear audio to be an 8k samples/second
|
||||
stream. In this mode the codec is considerably faster, and still fully
|
||||
compatible with wideband terminals using G.722.
|
||||
|
||||
\section g722_page_sec_2 How does it work?
|
||||
???.
|
||||
@ -49,86 +50,78 @@ codec is considerably faster, and still fully compatible with wideband terminals
|
||||
#define WEBRTC_INT16_MAX 32767
|
||||
#define WEBRTC_INT16_MIN -32768
|
||||
|
||||
enum
|
||||
{
|
||||
G722_SAMPLE_RATE_8000 = 0x0001,
|
||||
G722_PACKED = 0x0002
|
||||
};
|
||||
enum { G722_SAMPLE_RATE_8000 = 0x0001, G722_PACKED = 0x0002 };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*! TRUE if the operating in the special ITU test mode, with the band split filters
|
||||
disabled. */
|
||||
int itu_test_mode;
|
||||
/*! TRUE if the G.722 data is packed */
|
||||
int packed;
|
||||
/*! TRUE if encode from 8k samples/second */
|
||||
int eight_k;
|
||||
/*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
|
||||
int bits_per_sample;
|
||||
typedef struct {
|
||||
/*! TRUE if the operating in the special ITU test mode, with the band split
|
||||
filters disabled. */
|
||||
int itu_test_mode;
|
||||
/*! TRUE if the G.722 data is packed */
|
||||
int packed;
|
||||
/*! TRUE if encode from 8k samples/second */
|
||||
int eight_k;
|
||||
/*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
|
||||
int bits_per_sample;
|
||||
|
||||
/*! Signal history for the QMF */
|
||||
int x[24];
|
||||
/*! Signal history for the QMF */
|
||||
int x[24];
|
||||
|
||||
struct
|
||||
{
|
||||
int s;
|
||||
int sp;
|
||||
int sz;
|
||||
int r[3];
|
||||
int a[3];
|
||||
int ap[3];
|
||||
int p[3];
|
||||
int d[7];
|
||||
int b[7];
|
||||
int bp[7];
|
||||
int sg[7];
|
||||
int nb;
|
||||
int det;
|
||||
} band[2];
|
||||
struct {
|
||||
int s;
|
||||
int sp;
|
||||
int sz;
|
||||
int r[3];
|
||||
int a[3];
|
||||
int ap[3];
|
||||
int p[3];
|
||||
int d[7];
|
||||
int b[7];
|
||||
int bp[7];
|
||||
int sg[7];
|
||||
int nb;
|
||||
int det;
|
||||
} band[2];
|
||||
|
||||
unsigned int in_buffer;
|
||||
int in_bits;
|
||||
unsigned int out_buffer;
|
||||
int out_bits;
|
||||
unsigned int in_buffer;
|
||||
int in_bits;
|
||||
unsigned int out_buffer;
|
||||
int out_bits;
|
||||
} G722EncoderState;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*! TRUE if the operating in the special ITU test mode, with the band split filters
|
||||
disabled. */
|
||||
int itu_test_mode;
|
||||
/*! TRUE if the G.722 data is packed */
|
||||
int packed;
|
||||
/*! TRUE if decode to 8k samples/second */
|
||||
int eight_k;
|
||||
/*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
|
||||
int bits_per_sample;
|
||||
typedef struct {
|
||||
/*! TRUE if the operating in the special ITU test mode, with the band split
|
||||
filters disabled. */
|
||||
int itu_test_mode;
|
||||
/*! TRUE if the G.722 data is packed */
|
||||
int packed;
|
||||
/*! TRUE if decode to 8k samples/second */
|
||||
int eight_k;
|
||||
/*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
|
||||
int bits_per_sample;
|
||||
|
||||
/*! Signal history for the QMF */
|
||||
int x[24];
|
||||
/*! Signal history for the QMF */
|
||||
int x[24];
|
||||
|
||||
struct
|
||||
{
|
||||
int s;
|
||||
int sp;
|
||||
int sz;
|
||||
int r[3];
|
||||
int a[3];
|
||||
int ap[3];
|
||||
int p[3];
|
||||
int d[7];
|
||||
int b[7];
|
||||
int bp[7];
|
||||
int sg[7];
|
||||
int nb;
|
||||
int det;
|
||||
} band[2];
|
||||
|
||||
unsigned int in_buffer;
|
||||
int in_bits;
|
||||
unsigned int out_buffer;
|
||||
int out_bits;
|
||||
struct {
|
||||
int s;
|
||||
int sp;
|
||||
int sz;
|
||||
int r[3];
|
||||
int a[3];
|
||||
int ap[3];
|
||||
int p[3];
|
||||
int d[7];
|
||||
int b[7];
|
||||
int bp[7];
|
||||
int sg[7];
|
||||
int nb;
|
||||
int det;
|
||||
} band[2];
|
||||
|
||||
unsigned int in_buffer;
|
||||
int in_bits;
|
||||
unsigned int out_buffer;
|
||||
int out_bits;
|
||||
} G722DecoderState;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -138,8 +131,8 @@ extern "C" {
|
||||
G722EncoderState* WebRtc_g722_encode_init(G722EncoderState* s,
|
||||
int rate,
|
||||
int options);
|
||||
int WebRtc_g722_encode_release(G722EncoderState *s);
|
||||
size_t WebRtc_g722_encode(G722EncoderState *s,
|
||||
int WebRtc_g722_encode_release(G722EncoderState* s);
|
||||
size_t WebRtc_g722_encode(G722EncoderState* s,
|
||||
uint8_t g722_data[],
|
||||
const int16_t amp[],
|
||||
size_t len);
|
||||
@ -147,8 +140,8 @@ size_t WebRtc_g722_encode(G722EncoderState *s,
|
||||
G722DecoderState* WebRtc_g722_decode_init(G722DecoderState* s,
|
||||
int rate,
|
||||
int options);
|
||||
int WebRtc_g722_decode_release(G722DecoderState *s);
|
||||
size_t WebRtc_g722_decode(G722DecoderState *s,
|
||||
int WebRtc_g722_decode_release(G722DecoderState* s);
|
||||
size_t WebRtc_g722_decode(G722DecoderState* s,
|
||||
int16_t amp[],
|
||||
const uint8_t g722_data[],
|
||||
size_t len);
|
||||
|
||||
@ -17,21 +17,20 @@
|
||||
* Solution to support multiple instances
|
||||
*/
|
||||
|
||||
typedef struct WebRtcG722EncInst G722EncInst;
|
||||
typedef struct WebRtcG722DecInst G722DecInst;
|
||||
typedef struct WebRtcG722EncInst G722EncInst;
|
||||
typedef struct WebRtcG722DecInst G722DecInst;
|
||||
|
||||
/*
|
||||
* Comfort noise constants
|
||||
*/
|
||||
|
||||
#define G722_WEBRTC_SPEECH 1
|
||||
#define G722_WEBRTC_CNG 2
|
||||
#define G722_WEBRTC_SPEECH 1
|
||||
#define G722_WEBRTC_CNG 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_CreateEncoder(...)
|
||||
*
|
||||
@ -43,8 +42,7 @@ extern "C" {
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst);
|
||||
|
||||
int16_t WebRtcG722_CreateEncoder(G722EncInst** G722enc_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_EncoderInit(...)
|
||||
@ -59,8 +57,7 @@ int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst);
|
||||
* -1 - Error
|
||||
*/
|
||||
|
||||
int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst);
|
||||
|
||||
int16_t WebRtcG722_EncoderInit(G722EncInst* G722enc_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_FreeEncoder(...)
|
||||
@ -73,9 +70,7 @@ int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst);
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst);
|
||||
|
||||
|
||||
int WebRtcG722_FreeEncoder(G722EncInst* G722enc_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_Encode(...)
|
||||
@ -99,7 +94,6 @@ size_t WebRtcG722_Encode(G722EncInst* G722enc_inst,
|
||||
size_t len,
|
||||
uint8_t* encoded);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_CreateDecoder(...)
|
||||
*
|
||||
@ -111,7 +105,7 @@ size_t WebRtcG722_Encode(G722EncInst* G722enc_inst,
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int16_t WebRtcG722_CreateDecoder(G722DecInst **G722dec_inst);
|
||||
int16_t WebRtcG722_CreateDecoder(G722DecInst** G722dec_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_DecoderInit(...)
|
||||
@ -136,8 +130,7 @@ void WebRtcG722_DecoderInit(G722DecInst* inst);
|
||||
* -1 - Error
|
||||
*/
|
||||
|
||||
int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst);
|
||||
|
||||
int WebRtcG722_FreeDecoder(G722DecInst* G722dec_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_Decode(...)
|
||||
@ -159,11 +152,11 @@ int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst);
|
||||
* Return value : Samples in decoded vector
|
||||
*/
|
||||
|
||||
size_t WebRtcG722_Decode(G722DecInst *G722dec_inst,
|
||||
size_t WebRtcG722_Decode(G722DecInst* G722dec_inst,
|
||||
const uint8_t* encoded,
|
||||
size_t len,
|
||||
int16_t *decoded,
|
||||
int16_t *speechType);
|
||||
int16_t* decoded,
|
||||
int16_t* speechType);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcG722_Version(...)
|
||||
@ -171,12 +164,10 @@ size_t WebRtcG722_Decode(G722DecInst *G722dec_inst,
|
||||
* Get a string with the current version of the codec
|
||||
*/
|
||||
|
||||
int16_t WebRtcG722_Version(char *versionStr, short len);
|
||||
|
||||
int16_t WebRtcG722_Version(char* versionStr, short len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MODULES_AUDIO_CODING_CODECS_G722_G722_INTERFACE_H_ */
|
||||
|
||||
@ -22,137 +22,135 @@
|
||||
|
||||
/* Runtime statistics */
|
||||
#include <time.h>
|
||||
#define CLOCKS_PER_SEC_G722 100000
|
||||
#define CLOCKS_PER_SEC_G722 100000
|
||||
|
||||
// Forward declaration
|
||||
typedef struct WebRtcG722EncInst G722EncInst;
|
||||
typedef struct WebRtcG722DecInst G722DecInst;
|
||||
typedef struct WebRtcG722EncInst G722EncInst;
|
||||
typedef struct WebRtcG722DecInst G722DecInst;
|
||||
|
||||
/* function for reading audio data from PCM file */
|
||||
bool readframe(int16_t *data, FILE *inp, size_t length)
|
||||
{
|
||||
size_t rlen = fread(data, sizeof(int16_t), length, inp);
|
||||
if (rlen >= length)
|
||||
return false;
|
||||
memset(data + rlen, 0, (length - rlen) * sizeof(int16_t));
|
||||
return true;
|
||||
bool readframe(int16_t* data, FILE* inp, size_t length) {
|
||||
size_t rlen = fread(data, sizeof(int16_t), length, inp);
|
||||
if (rlen >= length)
|
||||
return false;
|
||||
memset(data + rlen, 0, (length - rlen) * sizeof(int16_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char inname[60], outbit[40], outname[40];
|
||||
FILE *inp, *outbitp, *outp;
|
||||
int main(int argc, char* argv[]) {
|
||||
char inname[60], outbit[40], outname[40];
|
||||
FILE *inp, *outbitp, *outp;
|
||||
|
||||
int framecnt;
|
||||
bool endfile;
|
||||
size_t framelength = 160;
|
||||
G722EncInst *G722enc_inst;
|
||||
G722DecInst *G722dec_inst;
|
||||
int framecnt;
|
||||
bool endfile;
|
||||
size_t framelength = 160;
|
||||
G722EncInst* G722enc_inst;
|
||||
G722DecInst* G722dec_inst;
|
||||
|
||||
/* Runtime statistics */
|
||||
double starttime;
|
||||
double runtime = 0;
|
||||
double length_file;
|
||||
/* Runtime statistics */
|
||||
double starttime;
|
||||
double runtime = 0;
|
||||
double length_file;
|
||||
|
||||
size_t stream_len = 0;
|
||||
int16_t shortdata[960];
|
||||
int16_t decoded[960];
|
||||
uint8_t streamdata[80 * 6];
|
||||
int16_t speechType[1];
|
||||
size_t stream_len = 0;
|
||||
int16_t shortdata[960];
|
||||
int16_t decoded[960];
|
||||
uint8_t streamdata[80 * 6];
|
||||
int16_t speechType[1];
|
||||
|
||||
/* handling wrong input arguments in the command line */
|
||||
if (argc!=5) {
|
||||
printf("\n\nWrong number of arguments or flag values.\n\n");
|
||||
/* handling wrong input arguments in the command line */
|
||||
if (argc != 5) {
|
||||
printf("\n\nWrong number of arguments or flag values.\n\n");
|
||||
|
||||
printf("\n");
|
||||
printf("Usage:\n\n");
|
||||
printf("./testG722.exe framelength infile outbitfile outspeechfile \n\n");
|
||||
printf("with:\n");
|
||||
printf("framelength : Framelength in samples.\n\n");
|
||||
printf("infile : Normal speech input file\n\n");
|
||||
printf("outbitfile : Bitstream output file\n\n");
|
||||
printf("outspeechfile: Speech output file\n\n");
|
||||
exit(0);
|
||||
printf("\n");
|
||||
printf("Usage:\n\n");
|
||||
printf("./testG722.exe framelength infile outbitfile outspeechfile \n\n");
|
||||
printf("with:\n");
|
||||
printf("framelength : Framelength in samples.\n\n");
|
||||
printf("infile : Normal speech input file\n\n");
|
||||
printf("outbitfile : Bitstream output file\n\n");
|
||||
printf("outspeechfile: Speech output file\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Get frame length */
|
||||
int framelength_int = atoi(argv[1]);
|
||||
if (framelength_int < 0) {
|
||||
printf(" G.722: Invalid framelength %d.\n", framelength_int);
|
||||
exit(1);
|
||||
}
|
||||
framelength = static_cast<size_t>(framelength_int);
|
||||
|
||||
/* Get Input and Output files */
|
||||
sscanf(argv[2], "%s", inname);
|
||||
sscanf(argv[3], "%s", outbit);
|
||||
sscanf(argv[4], "%s", outname);
|
||||
|
||||
if ((inp = fopen(inname, "rb")) == NULL) {
|
||||
printf(" G.722: Cannot read file %s.\n", inname);
|
||||
exit(1);
|
||||
}
|
||||
if ((outbitp = fopen(outbit, "wb")) == NULL) {
|
||||
printf(" G.722: Cannot write file %s.\n", outbit);
|
||||
exit(1);
|
||||
}
|
||||
if ((outp = fopen(outname, "wb")) == NULL) {
|
||||
printf(" G.722: Cannot write file %s.\n", outname);
|
||||
exit(1);
|
||||
}
|
||||
printf("\nInput:%s\nOutput bitstream:%s\nOutput:%s\n", inname, outbit,
|
||||
outname);
|
||||
|
||||
/* Create and init */
|
||||
WebRtcG722_CreateEncoder((G722EncInst**)&G722enc_inst);
|
||||
WebRtcG722_CreateDecoder((G722DecInst**)&G722dec_inst);
|
||||
WebRtcG722_EncoderInit((G722EncInst*)G722enc_inst);
|
||||
WebRtcG722_DecoderInit((G722DecInst*)G722dec_inst);
|
||||
|
||||
/* Initialize encoder and decoder */
|
||||
framecnt = 0;
|
||||
endfile = false;
|
||||
while (!endfile) {
|
||||
framecnt++;
|
||||
|
||||
/* Read speech block */
|
||||
endfile = readframe(shortdata, inp, framelength);
|
||||
|
||||
/* Start clock before call to encoder and decoder */
|
||||
starttime = clock() / (double)CLOCKS_PER_SEC_G722;
|
||||
|
||||
/* G.722 encoding + decoding */
|
||||
stream_len = WebRtcG722_Encode((G722EncInst*)G722enc_inst, shortdata,
|
||||
framelength, streamdata);
|
||||
WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded,
|
||||
speechType);
|
||||
|
||||
/* Stop clock after call to encoder and decoder */
|
||||
runtime += (double)((clock() / (double)CLOCKS_PER_SEC_G722) - starttime);
|
||||
|
||||
/* Write coded bits to file */
|
||||
if (fwrite(streamdata, sizeof(short), stream_len / 2, outbitp) !=
|
||||
stream_len / 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get frame length */
|
||||
int framelength_int = atoi(argv[1]);
|
||||
if (framelength_int < 0) {
|
||||
printf(" G.722: Invalid framelength %d.\n", framelength_int);
|
||||
exit(1);
|
||||
/* Write coded speech to file */
|
||||
if (fwrite(decoded, sizeof(short), framelength, outp) != framelength) {
|
||||
return -1;
|
||||
}
|
||||
framelength = static_cast<size_t>(framelength_int);
|
||||
}
|
||||
|
||||
/* Get Input and Output files */
|
||||
sscanf(argv[2], "%s", inname);
|
||||
sscanf(argv[3], "%s", outbit);
|
||||
sscanf(argv[4], "%s", outname);
|
||||
WebRtcG722_FreeEncoder((G722EncInst*)G722enc_inst);
|
||||
WebRtcG722_FreeDecoder((G722DecInst*)G722dec_inst);
|
||||
|
||||
if ((inp = fopen(inname,"rb")) == NULL) {
|
||||
printf(" G.722: Cannot read file %s.\n", inname);
|
||||
exit(1);
|
||||
}
|
||||
if ((outbitp = fopen(outbit,"wb")) == NULL) {
|
||||
printf(" G.722: Cannot write file %s.\n", outbit);
|
||||
exit(1);
|
||||
}
|
||||
if ((outp = fopen(outname,"wb")) == NULL) {
|
||||
printf(" G.722: Cannot write file %s.\n", outname);
|
||||
exit(1);
|
||||
}
|
||||
printf("\nInput:%s\nOutput bitstream:%s\nOutput:%s\n", inname, outbit, outname);
|
||||
length_file = ((double)framecnt * (double)framelength / 16000);
|
||||
printf("\n\nLength of speech file: %.1f s\n", length_file);
|
||||
printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime,
|
||||
(100 * runtime / length_file));
|
||||
printf("---------------------END----------------------\n");
|
||||
|
||||
/* Create and init */
|
||||
WebRtcG722_CreateEncoder((G722EncInst **)&G722enc_inst);
|
||||
WebRtcG722_CreateDecoder((G722DecInst **)&G722dec_inst);
|
||||
WebRtcG722_EncoderInit((G722EncInst *)G722enc_inst);
|
||||
WebRtcG722_DecoderInit((G722DecInst *)G722dec_inst);
|
||||
fclose(inp);
|
||||
fclose(outbitp);
|
||||
fclose(outp);
|
||||
|
||||
|
||||
/* Initialize encoder and decoder */
|
||||
framecnt = 0;
|
||||
endfile = false;
|
||||
while (!endfile) {
|
||||
framecnt++;
|
||||
|
||||
/* Read speech block */
|
||||
endfile = readframe(shortdata, inp, framelength);
|
||||
|
||||
/* Start clock before call to encoder and decoder */
|
||||
starttime = clock()/(double)CLOCKS_PER_SEC_G722;
|
||||
|
||||
/* G.722 encoding + decoding */
|
||||
stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, framelength, streamdata);
|
||||
WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded,
|
||||
speechType);
|
||||
|
||||
/* Stop clock after call to encoder and decoder */
|
||||
runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime);
|
||||
|
||||
/* Write coded bits to file */
|
||||
if (fwrite(streamdata, sizeof(short), stream_len / 2, outbitp) !=
|
||||
stream_len / 2) {
|
||||
return -1;
|
||||
}
|
||||
/* Write coded speech to file */
|
||||
if (fwrite(decoded, sizeof(short), framelength, outp) !=
|
||||
framelength) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst);
|
||||
WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst);
|
||||
|
||||
length_file = ((double)framecnt*(double)framelength/16000);
|
||||
printf("\n\nLength of speech file: %.1f s\n", length_file);
|
||||
printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file));
|
||||
printf("---------------------END----------------------\n");
|
||||
|
||||
fclose(inp);
|
||||
fclose(outbitp);
|
||||
fclose(outp);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user