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;
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;
OPUS_CLEAR((char*)st, opus_decoder_get_size(channels));
/* Initialize SILK encoder */
ret = silk_Get_Decoder_Size(&silkDecSizeBytes);
if(ret)return OPUS_INTERNAL_ERROR;
if (ret)
return OPUS_INTERNAL_ERROR;
silkDecSizeBytes = align(silkDecSizeBytes);
st->silk_dec_offset = align(sizeof(OpusDecoder));
@ -127,7 +129,8 @@ OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error)
{
int ret;
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)
*error = OPUS_BAD_ARG;
@ -151,8 +154,9 @@ OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error)
return st;
}
static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, opus_val16 *out,
int overlap, int channels, const opus_val16 *window, opus_int32 Fs)
static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2,
opus_val16 *out, int overlap, int channels,
const opus_val16 *window, opus_int32 Fs)
{
int i, c;
int inc = 48000/Fs;
@ -177,7 +181,6 @@ static int opus_packet_get_mode(const unsigned char *data)
{
mode = MODE_HYBRID;
} else {
mode = MODE_SILK_ONLY;
}
return mode;
@ -322,7 +325,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
}
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 */
if (mode == MODE_HYBRID)
@ -332,11 +336,14 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (redundancy)
{
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 = mode==MODE_HYBRID ? (opus_int32)ec_dec_uint(&dec, 256)+2 : len-((ec_tell(&dec)+7)>>3);
/* redundancy_bytes will be at least two, in the non-hybrid
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;
/* This is a sanity check. It should never happen for a valid packet,
so the exact behaviour is not normative. */
/* This is a sanity check. It should never happen for a valid
packet, so the exact behaviour is not normative. */
if (len*8 < ec_tell(&dec))
{
len = 0;
@ -383,7 +390,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (redundancy && celt_to_silk)
{
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));
}
@ -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)
celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
/* 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 {
unsigned char silence[2] = {0xFF, 0xFF};
for (i=0;i<frame_size*st->channels;i++)
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)
{
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
last packet (or all the packets, for the CBR case) is larger than
1275.
Reject them here.*/
1275. Reject them here.*/
if (last_size > 1275)
return OPUS_INVALID_PACKET;
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],
short size[48], int *payload_offset)
{
return opus_packet_parse_impl(data, len, 0,
out_toc, frames, size, payload_offset);
return opus_packet_parse_impl(data, len, 0, out_toc,
frames, size, payload_offset);
}
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 count, offset;
@ -666,7 +676,8 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
int tot_offset;
/* 48 x 2.5 ms = 120 ms */
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)
return opus_decode_frame(st, NULL, 0, pcm, frame_size, 0);
else if (len<0)
@ -841,15 +852,16 @@ int opus_packet_get_bandwidth(const unsigned char *data)
bandwidth = OPUS_BANDWIDTH_NARROWBAND;
} 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 {
bandwidth = OPUS_BANDWIDTH_NARROWBAND + ((data[0]>>5)&0x3);
}
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;
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;
} else {
audiosize = ((data[0]>>3)&0x3);
if (audiosize == 3)
audiosize = Fs*60/1000;
@ -891,7 +902,8 @@ int opus_packet_get_nb_frames(const unsigned char packet[], int len)
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 count = opus_packet_get_nb_frames(packet, len);

View file

@ -169,11 +169,12 @@ int main(int argc, char *argv[])
args++;
}
if (sampling_rate != 8000 && sampling_rate != 12000 && sampling_rate != 16000
&& sampling_rate != 24000 && sampling_rate != 48000)
if (sampling_rate != 8000 && sampling_rate != 12000
&& sampling_rate != 16000 && sampling_rate != 24000
&& sampling_rate != 48000)
{
fprintf(stderr, "Supported sampling rates are 8000, 12000, 16000, "
"24000 and 48000.\n");
fprintf(stderr, "Supported sampling rates are 8000, 12000, "
"16000, 24000 and 48000.\n");
return 1;
}
frame_size = sampling_rate/50;
@ -207,7 +208,9 @@ int main(int argc, char *argv[])
else if (strcmp(argv[ args + 1 ], "FB")==0)
bandwidth = OPUS_BANDWIDTH_FULLBAND;
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;
}
args += 2;
@ -225,7 +228,9 @@ int main(int argc, char *argv[])
else if (strcmp(argv[ args + 1 ], "60")==0)
frame_size = 3*sampling_rate/50;
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;
}
args += 2;
@ -339,9 +344,13 @@ int main(int argc, char *argv[])
}
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
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));
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);
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;
}
} else {
@ -428,7 +439,8 @@ int main(int argc, char *argv[])
fwrite(out+skip*channels, sizeof(short)*channels, output_samples-skip, fout);
skip = 0;
} 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)
opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
/* compare final range encoder rng values of encoder and decoder */
if( enc_final_range[toggle^use_inbandfec]!=0 && !encode_only && !lost && !lost_prev &&
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);
if( enc_final_range[toggle^use_inbandfec]!=0 && !encode_only
&& !lost && !lost_prev
&& 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;
}
@ -465,11 +483,15 @@ int main(int argc, char *argv[])
count++;
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, "maximum bitrate: %7.3f bkp/s\n", 1e-3*bits_max*sampling_rate/frame_size);
fprintf (stderr, "average bitrate: %7.3f kb/s\n",
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)
fprintf (stderr, "active bitrate: %7.3f kb/s\n", 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);
fprintf (stderr, "active bitrate: %7.3f kb/s\n",
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 */
SILK_DEBUG_STORE_CLOSE_FILES
silk_TimerSave("opus_timing.txt");