Convert tabs to spaces in the opus and celt code.

Also reformat some, but by no means all, of the opus
code for line length and three-character indents.
This commit is contained in:
Ralph Giles 2011-10-26 20:24:49 -07:00
parent 4923f3f80e
commit da025d5632
10 changed files with 629 additions and 595 deletions

View file

@ -89,13 +89,15 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels)
CELTDecoder *celt_dec; CELTDecoder *celt_dec;
int ret, silkDecSizeBytes; int ret, silkDecSizeBytes;
if((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000)||(channels!=1&&channels!=2)) if ((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000)
|| (channels!=1&&channels!=2))
return OPUS_BAD_ARG; return OPUS_BAD_ARG;
OPUS_CLEAR((char*)st, opus_decoder_get_size(channels)); OPUS_CLEAR((char*)st, opus_decoder_get_size(channels));
/* Initialize SILK encoder */ /* Initialize SILK encoder */
ret = silk_Get_Decoder_Size(&silkDecSizeBytes); ret = silk_Get_Decoder_Size(&silkDecSizeBytes);
if(ret)return OPUS_INTERNAL_ERROR; if (ret)
return OPUS_INTERNAL_ERROR;
silkDecSizeBytes = align(silkDecSizeBytes); silkDecSizeBytes = align(silkDecSizeBytes);
st->silk_dec_offset = align(sizeof(OpusDecoder)); st->silk_dec_offset = align(sizeof(OpusDecoder));
@ -127,7 +129,8 @@ OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error)
{ {
int ret; int ret;
OpusDecoder *st; OpusDecoder *st;
if((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000)||(channels!=1&&channels!=2)) if ((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000)
|| (channels!=1&&channels!=2))
{ {
if (error) if (error)
*error = OPUS_BAD_ARG; *error = OPUS_BAD_ARG;
@ -151,8 +154,9 @@ OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error)
return st; return st;
} }
static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, opus_val16 *out, static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2,
int overlap, int channels, const opus_val16 *window, opus_int32 Fs) opus_val16 *out, int overlap, int channels,
const opus_val16 *window, opus_int32 Fs)
{ {
int i, c; int i, c;
int inc = 48000/Fs; int inc = 48000/Fs;
@ -177,7 +181,6 @@ static int opus_packet_get_mode(const unsigned char *data)
{ {
mode = MODE_HYBRID; mode = MODE_HYBRID;
} else { } else {
mode = MODE_SILK_ONLY; mode = MODE_SILK_ONLY;
} }
return mode; return mode;
@ -322,7 +325,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
} }
start_band = 0; start_band = 0;
if (!decode_fec && mode != MODE_CELT_ONLY && data != NULL && ec_tell(&dec)+17+20*(st->mode == MODE_HYBRID) <= 8*len) if (!decode_fec && mode != MODE_CELT_ONLY && data != NULL
&& ec_tell(&dec)+17+20*(st->mode == MODE_HYBRID) <= 8*len)
{ {
/* Check if we have a redundant 0-8 kHz band */ /* Check if we have a redundant 0-8 kHz band */
if (mode == MODE_HYBRID) if (mode == MODE_HYBRID)
@ -332,11 +336,14 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (redundancy) if (redundancy)
{ {
celt_to_silk = ec_dec_bit_logp(&dec, 1); celt_to_silk = ec_dec_bit_logp(&dec, 1);
/* redundancy_bytes will be at least two, in the non-hybrid case due to the ec_tell() check above */ /* redundancy_bytes will be at least two, in the non-hybrid
redundancy_bytes = mode==MODE_HYBRID ? (opus_int32)ec_dec_uint(&dec, 256)+2 : len-((ec_tell(&dec)+7)>>3); case due to the ec_tell() check above */
redundancy_bytes = mode==MODE_HYBRID ?
(opus_int32)ec_dec_uint(&dec, 256)+2 :
len-((ec_tell(&dec)+7)>>3);
len -= redundancy_bytes; len -= redundancy_bytes;
/* This is a sanity check. It should never happen for a valid packet, /* This is a sanity check. It should never happen for a valid
so the exact behaviour is not normative. */ packet, so the exact behaviour is not normative. */
if (len*8 < ec_tell(&dec)) if (len*8 < ec_tell(&dec))
{ {
len = 0; len = 0;
@ -383,7 +390,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (redundancy && celt_to_silk) if (redundancy && celt_to_silk)
{ {
celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0)); celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0));
celt_decode_with_ec(celt_dec, data+len, redundancy_bytes, redundant_audio, F5, NULL); celt_decode_with_ec(celt_dec, data+len, redundancy_bytes,
redundant_audio, F5, NULL);
celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng)); celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng));
} }
@ -397,12 +405,14 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (mode != st->prev_mode && st->prev_mode > 0 && !st->prev_redundancy) if (mode != st->prev_mode && st->prev_mode > 0 && !st->prev_redundancy)
celt_decoder_ctl(celt_dec, OPUS_RESET_STATE); celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
/* Decode CELT */ /* Decode CELT */
celt_ret = celt_decode_with_ec(celt_dec, decode_fec?NULL:data, len, pcm, celt_frame_size, &dec); celt_ret = celt_decode_with_ec(celt_dec, decode_fec ? NULL : data,
len, pcm, celt_frame_size, &dec);
} else { } else {
unsigned char silence[2] = {0xFF, 0xFF}; unsigned char silence[2] = {0xFF, 0xFF};
for (i=0;i<frame_size*st->channels;i++) for (i=0;i<frame_size*st->channels;i++)
pcm[i] = 0; pcm[i] = 0;
/* For hybrid -> SILK transitions, we let the CELT MDCT do a fade-out by decoding a silence frame */ /* For hybrid -> SILK transitions, we let the CELT MDCT
do a fade-out by decoding a silence frame */
if (st->prev_mode == MODE_HYBRID) if (st->prev_mode == MODE_HYBRID)
{ {
celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0)); celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0));
@ -624,8 +634,7 @@ static int opus_packet_parse_impl(const unsigned char *data, int len,
{ {
/* Because it's not encoded explicitly, it's possible the size of the /* Because it's not encoded explicitly, it's possible the size of the
last packet (or all the packets, for the CBR case) is larger than last packet (or all the packets, for the CBR case) is larger than
1275. 1275. Reject them here.*/
Reject them here.*/
if (last_size > 1275) if (last_size > 1275)
return OPUS_INVALID_PACKET; return OPUS_INVALID_PACKET;
size[count-1] = last_size; size[count-1] = last_size;
@ -653,12 +662,13 @@ int opus_packet_parse(const unsigned char *data, int len,
unsigned char *out_toc, const unsigned char *frames[48], unsigned char *out_toc, const unsigned char *frames[48],
short size[48], int *payload_offset) short size[48], int *payload_offset)
{ {
return opus_packet_parse_impl(data, len, 0, return opus_packet_parse_impl(data, len, 0, out_toc,
out_toc, frames, size, payload_offset); frames, size, payload_offset);
} }
int opus_decode_native(OpusDecoder *st, const unsigned char *data, int opus_decode_native(OpusDecoder *st, const unsigned char *data,
int len, opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited, int *packet_offset) int len, opus_val16 *pcm, int frame_size, int decode_fec,
int self_delimited, int *packet_offset)
{ {
int i, nb_samples; int i, nb_samples;
int count, offset; int count, offset;
@ -666,7 +676,8 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
int tot_offset; int tot_offset;
/* 48 x 2.5 ms = 120 ms */ /* 48 x 2.5 ms = 120 ms */
short size[48]; short size[48];
if (decode_fec<0 || decode_fec>1)return OPUS_BAD_ARG; if (decode_fec<0 || decode_fec>1)
return OPUS_BAD_ARG;
if (len==0 || data==NULL) if (len==0 || data==NULL)
return opus_decode_frame(st, NULL, 0, pcm, frame_size, 0); return opus_decode_frame(st, NULL, 0, pcm, frame_size, 0);
else if (len<0) else if (len<0)
@ -841,15 +852,16 @@ int opus_packet_get_bandwidth(const unsigned char *data)
bandwidth = OPUS_BANDWIDTH_NARROWBAND; bandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if ((data[0]&0x60) == 0x60) } else if ((data[0]&0x60) == 0x60)
{ {
bandwidth = (data[0]&0x10) ? OPUS_BANDWIDTH_FULLBAND : OPUS_BANDWIDTH_SUPERWIDEBAND; bandwidth = (data[0]&0x10) ? OPUS_BANDWIDTH_FULLBAND :
OPUS_BANDWIDTH_SUPERWIDEBAND;
} else { } else {
bandwidth = OPUS_BANDWIDTH_NARROWBAND + ((data[0]>>5)&0x3); bandwidth = OPUS_BANDWIDTH_NARROWBAND + ((data[0]>>5)&0x3);
} }
return bandwidth; return bandwidth;
} }
int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) int opus_packet_get_samples_per_frame(const unsigned char *data,
opus_int32 Fs)
{ {
int audiosize; int audiosize;
if (data[0]&0x80) if (data[0]&0x80)
@ -860,7 +872,6 @@ int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs)
{ {
audiosize = (data[0]&0x08) ? Fs/50 : Fs/100; audiosize = (data[0]&0x08) ? Fs/50 : Fs/100;
} else { } else {
audiosize = ((data[0]>>3)&0x3); audiosize = ((data[0]>>3)&0x3);
if (audiosize == 3) if (audiosize == 3)
audiosize = Fs*60/1000; audiosize = Fs*60/1000;
@ -891,7 +902,8 @@ int opus_packet_get_nb_frames(const unsigned char packet[], int len)
return packet[1]&0x3F; return packet[1]&0x3F;
} }
int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], int len) int opus_decoder_get_nb_samples(const OpusDecoder *dec,
const unsigned char packet[], int len)
{ {
int samples; int samples;
int count = opus_packet_get_nb_frames(packet, len); int count = opus_packet_get_nb_frames(packet, len);

View file

@ -169,11 +169,12 @@ int main(int argc, char *argv[])
args++; args++;
} }
if (sampling_rate != 8000 && sampling_rate != 12000 && sampling_rate != 16000 if (sampling_rate != 8000 && sampling_rate != 12000
&& sampling_rate != 24000 && sampling_rate != 48000) && sampling_rate != 16000 && sampling_rate != 24000
&& sampling_rate != 48000)
{ {
fprintf(stderr, "Supported sampling rates are 8000, 12000, 16000, " fprintf(stderr, "Supported sampling rates are 8000, 12000, "
"24000 and 48000.\n"); "16000, 24000 and 48000.\n");
return 1; return 1;
} }
frame_size = sampling_rate/50; frame_size = sampling_rate/50;
@ -207,7 +208,9 @@ int main(int argc, char *argv[])
else if (strcmp(argv[ args + 1 ], "FB")==0) else if (strcmp(argv[ args + 1 ], "FB")==0)
bandwidth = OPUS_BANDWIDTH_FULLBAND; bandwidth = OPUS_BANDWIDTH_FULLBAND;
else { else {
fprintf(stderr, "Unknown bandwidth %s. Supported are NB, MB, WB, SWB, FB.\n", argv[ args + 1 ]); fprintf(stderr, "Unknown bandwidth %s. "
"Supported are NB, MB, WB, SWB, FB.\n",
argv[ args + 1 ]);
return 1; return 1;
} }
args += 2; args += 2;
@ -225,7 +228,9 @@ int main(int argc, char *argv[])
else if (strcmp(argv[ args + 1 ], "60")==0) else if (strcmp(argv[ args + 1 ], "60")==0)
frame_size = 3*sampling_rate/50; frame_size = 3*sampling_rate/50;
else { else {
fprintf(stderr, "Unsupported frame size: %s ms. Supported are 2.5, 5, 10, 20, 40, 60.\n", argv[ args + 1 ]); fprintf(stderr, "Unsupported frame size: %s ms. "
"Supported are 2.5, 5, 10, 20, 40, 60.\n",
argv[ args + 1 ]);
return 1; return 1;
} }
args += 2; args += 2;
@ -339,9 +344,13 @@ int main(int argc, char *argv[])
} }
if (decode_only) if (decode_only)
fprintf(stderr, "Decoding with %ld Hz output (%d channels)\n", (long)sampling_rate, channels); fprintf(stderr, "Decoding with %ld Hz output (%d channels)\n",
(long)sampling_rate, channels);
else else
fprintf(stderr, "Encoding %ld Hz input at %.3f kb/s in %s mode with %d-sample frames.\n", (long)sampling_rate, bitrate_bps*0.001, bandwidth_string, frame_size); fprintf(stderr, "Encoding %ld Hz input at %.3f kb/s "
"in %s mode with %d-sample frames.\n",
(long)sampling_rate, bitrate_bps*0.001,
bandwidth_string, frame_size);
in = (short*)malloc(frame_size*channels*sizeof(short)); in = (short*)malloc(frame_size*channels*sizeof(short));
out = (short*)malloc(max_frame_size*channels*sizeof(short)); out = (short*)malloc(max_frame_size*channels*sizeof(short));
@ -368,7 +377,9 @@ int main(int argc, char *argv[])
err = fread(data[toggle], 1, len[toggle], fin); err = fread(data[toggle], 1, len[toggle], fin);
if (err<len[toggle]) if (err<len[toggle])
{ {
fprintf(stderr, "Ran out of input, expecting %d bytes got %d\n",len[toggle],err); fprintf(stderr, "Ran out of input, "
"expecting %d bytes got %d\n",
len[toggle],err);
break; break;
} }
} else { } else {
@ -428,7 +439,8 @@ int main(int argc, char *argv[])
fwrite(out+skip*channels, sizeof(short)*channels, output_samples-skip, fout); fwrite(out+skip*channels, sizeof(short)*channels, output_samples-skip, fout);
skip = 0; skip = 0;
} else { } else {
fprintf(stderr, "error decoding frame: %s\n", opus_strerror(output_samples)); fprintf(stderr, "error decoding frame: %s\n",
opus_strerror(output_samples));
} }
} }
} }
@ -436,9 +448,15 @@ int main(int argc, char *argv[])
if (!encode_only) if (!encode_only)
opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range)); opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
/* compare final range encoder rng values of encoder and decoder */ /* compare final range encoder rng values of encoder and decoder */
if( enc_final_range[toggle^use_inbandfec]!=0 && !encode_only && !lost && !lost_prev && if( enc_final_range[toggle^use_inbandfec]!=0 && !encode_only
dec_final_range != enc_final_range[toggle^use_inbandfec] ) { && !lost && !lost_prev
fprintf (stderr, "Error: Range coder state mismatch between encoder and decoder in frame %ld: 0x%8lx vs 0x%8lx\n", (long)count, (unsigned long)enc_final_range[toggle^use_inbandfec], (unsigned long)dec_final_range); && dec_final_range != enc_final_range[toggle^use_inbandfec] ) {
fprintf (stderr, "Error: Range coder state mismatch "
"between encoder and decoder "
"in frame %ld: 0x%8lx vs 0x%8lx\n",
(long)count,
(unsigned long)enc_final_range[toggle^use_inbandfec],
(unsigned long)dec_final_range);
return 0; return 0;
} }
@ -465,11 +483,15 @@ int main(int argc, char *argv[])
count++; count++;
toggle = (toggle + use_inbandfec) & 1; toggle = (toggle + use_inbandfec) & 1;
} }
fprintf (stderr, "average bitrate: %7.3f kb/s\n", 1e-3*bits*sampling_rate/(frame_size*(double)count)); fprintf (stderr, "average bitrate: %7.3f kb/s\n",
fprintf (stderr, "maximum bitrate: %7.3f bkp/s\n", 1e-3*bits_max*sampling_rate/frame_size); 1e-3*bits*sampling_rate/(frame_size*(double)count));
fprintf (stderr, "maximum bitrate: %7.3f bkp/s\n",
1e-3*bits_max*sampling_rate/frame_size);
if (!decode_only) if (!decode_only)
fprintf (stderr, "active bitrate: %7.3f kb/s\n", 1e-3*bits_act*sampling_rate/(frame_size*(double)count_act)); fprintf (stderr, "active bitrate: %7.3f kb/s\n",
fprintf (stderr, "bitrate standard deviation: %7.3f kb/s\n", 1e-3*sqrt(bits2/count - bits*bits/(count*(double)count))*sampling_rate/frame_size); 1e-3*bits_act*sampling_rate/(frame_size*(double)count_act));
fprintf (stderr, "bitrate standard deviation: %7.3f kb/s\n",
1e-3*sqrt(bits2/count - bits*bits/(count*(double)count))*sampling_rate/frame_size);
/* Close any files to which intermediate results were stored */ /* Close any files to which intermediate results were stored */
SILK_DEBUG_STORE_CLOSE_FILES SILK_DEBUG_STORE_CLOSE_FILES
silk_TimerSave("opus_timing.txt"); silk_TimerSave("opus_timing.txt");