From 64a3541aa9912d9f60684c7e2fde19e86d41907a Mon Sep 17 00:00:00 2001 From: Gregory Maxwell <greg@xiph.org> Date: Fri, 2 Sep 2011 10:31:17 -0400 Subject: [PATCH] Corrects many places where int was used where opus_int32 was needed. --- libcelt/celt.c | 4 +- libcelt/celt.h | 4 +- libcelt/test_opus_custom.c | 5 +- silk/silk_API.h | 6 +- silk/silk_dec_API.c | 4 +- silk/silk_enc_API.c | 4 +- src/opus.h | 10 ++-- src/opus_decoder.c | 110 ++++++++++++++++++------------------- src/opus_encoder.c | 14 ++--- src/test_opus.c | 15 ++--- 10 files changed, 87 insertions(+), 89 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index 6c0aafd72..2a9945fbf 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -215,7 +215,7 @@ CELTEncoder *opus_custom_encoder_create(const CELTMode *mode, int channels, int } #endif /* CUSTOM_MODES */ -int celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels) +int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels) { int ret; ret = opus_custom_encoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels); @@ -1928,7 +1928,7 @@ CELTDecoder *opus_custom_decoder_create(const CELTMode *mode, int channels, int } #endif /* CUSTOM_MODES */ -int celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels) +int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels) { int ret; ret = opus_custom_decoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels); diff --git a/libcelt/celt.h b/libcelt/celt.h index e80eb76b8..99e0b2e66 100644 --- a/libcelt/celt.h +++ b/libcelt/celt.h @@ -85,7 +85,7 @@ extern "C" { int celt_encoder_get_size(int channels); -int celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels); +int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels); @@ -94,7 +94,7 @@ int celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels); int celt_decoder_get_size(int channels); -int celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels); +int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels); /* @} */ diff --git a/libcelt/test_opus_custom.c b/libcelt/test_opus_custom.c index bb57f650d..741d2bd5b 100644 --- a/libcelt/test_opus_custom.c +++ b/libcelt/test_opus_custom.c @@ -48,10 +48,9 @@ int main(int argc, char *argv[]) OpusCustomEncoder *enc; OpusCustomDecoder *dec; int len; - opus_int32 frame_size, channels; + opus_int32 frame_size, channels, rate; int bytes_per_packet; unsigned char data[MAX_PACKET]; - int rate; int complexity; #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH) int i; @@ -68,7 +67,7 @@ int main(int argc, char *argv[]) return 1; } - rate = atoi(argv[1]); + rate = (opus_int32)atol(argv[1]); channels = atoi(argv[2]); frame_size = atoi(argv[3]); mode = opus_custom_mode_create(rate, frame_size, NULL); diff --git a/silk/silk_API.h b/silk/silk_API.h index e6af6fd89..7f2861dea 100644 --- a/silk/silk_API.h +++ b/silk/silk_API.h @@ -56,7 +56,7 @@ typedef struct { /* Get size in bytes of the Silk encoder state */ /***********************************************/ opus_int silk_Get_Encoder_Size( /* O: Returns error code */ - opus_int32 *encSizeBytes /* O: Number of bytes in SILK encoder state */ + int *encSizeBytes /* O: Number of bytes in SILK encoder state */ ); /*************************/ @@ -86,7 +86,7 @@ opus_int silk_Encode( /* O: Returns error c const opus_int16 *samplesIn, /* I: Speech sample input vector */ opus_int nSamplesIn, /* I: Number of samples in input vector */ ec_enc *psRangeEnc, /* I/O Compressor data structure */ - opus_int32 *nBytesOut, /* I/O: Number of bytes in payload (input: Max bytes) */ + opus_int *nBytesOut, /* I/O: Number of bytes in payload (input: Max bytes) */ const opus_int prefillFlag /* I: Flag to indicate prefilling buffers no coding */ ); @@ -98,7 +98,7 @@ opus_int silk_Encode( /* O: Returns error c /* Get size in bytes of the Silk decoder state */ /***********************************************/ opus_int silk_Get_Decoder_Size( /* O: Returns error code */ - opus_int32 *decSizeBytes /* O: Number of bytes in SILK decoder state */ + int *decSizeBytes /* O: Number of bytes in SILK decoder state */ ); /*************************/ diff --git a/silk/silk_dec_API.c b/silk/silk_dec_API.c index 8b75307b1..18a0024dd 100644 --- a/silk/silk_dec_API.c +++ b/silk/silk_dec_API.c @@ -45,7 +45,7 @@ typedef struct { /* Decoder functions */ /*********************/ -opus_int silk_Get_Decoder_Size( opus_int32 *decSizeBytes ) +opus_int silk_Get_Decoder_Size( int *decSizeBytes ) { opus_int ret = SILK_NO_ERROR; @@ -84,7 +84,7 @@ opus_int silk_Decode( opus_int32 nSamplesOutDec, LBRR_symbol; opus_int16 samplesOut1_tmp[ 2 ][ MAX_FS_KHZ * MAX_FRAME_LENGTH_MS + 2 ]; opus_int16 samplesOut2_tmp[ MAX_API_FS_KHZ * MAX_FRAME_LENGTH_MS ]; - opus_int MS_pred_Q13[ 2 ] = { 0 }; + opus_int32 MS_pred_Q13[ 2 ] = { 0 }; opus_int16 *resample_out_ptr; silk_decoder *psDec = ( silk_decoder * )decState; silk_decoder_state *channel_state = psDec->channel_state; diff --git a/silk/silk_enc_API.c b/silk/silk_enc_API.c index bc65caa8b..c9055e717 100644 --- a/silk/silk_enc_API.c +++ b/silk/silk_enc_API.c @@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Encoder functions */ /****************************************/ -opus_int silk_Get_Encoder_Size( opus_int32 *encSizeBytes ) +opus_int silk_Get_Encoder_Size( int *encSizeBytes ) { opus_int ret = SILK_NO_ERROR; @@ -128,7 +128,7 @@ opus_int silk_Encode( const opus_int16 *samplesIn, /* I: Speech sample input vector */ opus_int nSamplesIn, /* I: Number of samples in input vector */ ec_enc *psRangeEnc, /* I/O Compressor data structure */ - opus_int32 *nBytesOut, /* I/O: Number of bytes in payload (input: Max bytes) */ + opus_int *nBytesOut, /* I/O: Number of bytes in payload (input: Max bytes) */ const opus_int prefillFlag /* I: Flag to indicate prefilling buffers; no coding */ ) { diff --git a/src/opus.h b/src/opus.h index 08d706bfe..810a88f2f 100644 --- a/src/opus.h +++ b/src/opus.h @@ -75,7 +75,7 @@ OPUS_EXPORT int opus_encoder_get_size(int channels); /* Returns initialized encoder state */ OPUS_EXPORT OpusEncoder *opus_encoder_create( - int Fs, /* Sampling rate of input signal (Hz) */ + opus_int32 Fs, /* Sampling rate of input signal (Hz) */ int channels, /* Number of channels (1/2) in input signal */ int application, /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ int *error /* Error code */ @@ -83,7 +83,7 @@ OPUS_EXPORT OpusEncoder *opus_encoder_create( OPUS_EXPORT int opus_encoder_init( OpusEncoder *st, /* Encoder state */ - int Fs, /* Sampling rate of input signal (Hz) */ + opus_int32 Fs, /* Sampling rate of input signal (Hz) */ int channels, /* Number of channels (1/2) in input signal */ int application /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ ); @@ -115,13 +115,13 @@ OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...); OPUS_EXPORT int opus_decoder_get_size(int channels); OPUS_EXPORT OpusDecoder *opus_decoder_create( - int Fs, /* Sampling rate of output signal (Hz) */ + opus_int32 Fs, /* Sampling rate of output signal (Hz) */ int channels, /* Number of channels (1/2) in output signal */ int *error /* Error code*/ ); OPUS_EXPORT int opus_decoder_init(OpusDecoder *st, - int Fs, /* Sampling rate of output signal (Hz) */ + opus_int32 Fs, /* Sampling rate of output signal (Hz) */ int channels /* Number of channels (1/2) in output signal */ ); @@ -156,7 +156,7 @@ OPUS_EXPORT int opus_packet_parse(const unsigned char *data, int len, short size[48], int *payload_offset); OPUS_EXPORT int opus_packet_get_bandwidth(const unsigned char *data); -OPUS_EXPORT int opus_packet_get_samples_per_frame(const unsigned char *data, int Fs); +OPUS_EXPORT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs); OPUS_EXPORT int opus_packet_get_nb_channels(const unsigned char *data); OPUS_EXPORT int opus_packet_get_nb_frames(const unsigned char packet[], int len); OPUS_EXPORT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], int len); diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 1ce84e1d9..ce6e9ce06 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -44,7 +44,7 @@ struct OpusDecoder { int celt_dec_offset; int silk_dec_offset; int channels; - int Fs; /** Sampling rate (at the API level) */ + opus_int32 Fs; /** Sampling rate (at the API level) */ /* Everything beyond this point gets cleared on a reset */ #define OPUS_DECODER_RESET_START stream_channels @@ -56,7 +56,7 @@ struct OpusDecoder { int frame_size; int prev_redundancy; - int rangeFinal; + opus_uint32 rangeFinal; }; #ifdef FIXED_POINT @@ -68,61 +68,60 @@ static inline opus_int16 SAT16(opus_int32 x) { int opus_decoder_get_size(int channels) { - int silkDecSizeBytes, celtDecSizeBytes; - int ret; - ret = silk_Get_Decoder_Size( &silkDecSizeBytes ); - if(ret) - return 0; - silkDecSizeBytes = align(silkDecSizeBytes); - celtDecSizeBytes = celt_decoder_get_size(channels); - return align(sizeof(OpusDecoder))+silkDecSizeBytes+celtDecSizeBytes; - + int silkDecSizeBytes, celtDecSizeBytes; + int ret; + ret = silk_Get_Decoder_Size( &silkDecSizeBytes ); + if(ret) + return 0; + silkDecSizeBytes = align(silkDecSizeBytes); + celtDecSizeBytes = celt_decoder_get_size(channels); + return align(sizeof(OpusDecoder))+silkDecSizeBytes+celtDecSizeBytes; } -int opus_decoder_init(OpusDecoder *st, int Fs, int channels) +int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) { - void *silk_dec; - CELTDecoder *celt_dec; - int ret, silkDecSizeBytes; - - if (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; - } - silkDecSizeBytes = align(silkDecSizeBytes); - st->silk_dec_offset = align(sizeof(OpusDecoder)); - st->celt_dec_offset = st->silk_dec_offset+silkDecSizeBytes; - silk_dec = (char*)st+st->silk_dec_offset; - celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); - st->stream_channels = st->channels = channels; - - st->Fs = Fs; + void *silk_dec; + CELTDecoder *celt_dec; + int ret, silkDecSizeBytes; - /* Reset decoder */ - ret = silk_InitDecoder( silk_dec ); - if( ret ) { - goto failure; - } + if (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; + } + silkDecSizeBytes = align(silkDecSizeBytes); + st->silk_dec_offset = align(sizeof(OpusDecoder)); + st->celt_dec_offset = st->silk_dec_offset+silkDecSizeBytes; + silk_dec = (char*)st+st->silk_dec_offset; + celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); + st->stream_channels = st->channels = channels; + + st->Fs = Fs; + + /* Reset decoder */ + ret = silk_InitDecoder( silk_dec ); + if( ret ) { + goto failure; + } - /* Initialize CELT decoder */ - ret = celt_decoder_init(celt_dec, Fs, channels); - if (ret != OPUS_OK) - goto failure; - celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0)); + /* Initialize CELT decoder */ + ret = celt_decoder_init(celt_dec, Fs, channels); + if (ret != OPUS_OK) + goto failure; + celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0)); - st->prev_mode = 0; - st->frame_size = Fs/400; - return OPUS_OK; + st->prev_mode = 0; + st->frame_size = Fs/400; + return OPUS_OK; failure: - opus_free(st); - return OPUS_INTERNAL_ERROR; + opus_free(st); + return OPUS_INTERNAL_ERROR; } -OpusDecoder *opus_decoder_create(int Fs, int channels, int *error) +OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error) { int ret; OpusDecoder *st = (OpusDecoder *)opus_alloc(opus_decoder_get_size(channels)); @@ -142,7 +141,7 @@ OpusDecoder *opus_decoder_create(int Fs, int channels, int *error) } static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, opus_val16 *out, - int overlap, int channels, const opus_val16 *window, int Fs) + int overlap, int channels, const opus_val16 *window, opus_int32 Fs) { int i, c; int inc = 48000/Fs; @@ -176,10 +175,10 @@ static int opus_packet_get_mode(const unsigned char *data) static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, int len, opus_val16 *pcm, int frame_size, int decode_fec) { - void *silk_dec; - CELTDecoder *celt_dec; - int i, silk_ret=0, celt_ret=0; - ec_dec dec; + void *silk_dec; + CELTDecoder *celt_dec; + int i, silk_ret=0, celt_ret=0; + ec_dec dec; silk_DecControlStruct DecControl; opus_int32 silk_frame_size; VARDECL(opus_int16, pcm_silk); @@ -806,9 +805,9 @@ int opus_packet_get_bandwidth(const unsigned char *data) return bandwidth; } -int opus_packet_get_samples_per_frame(const unsigned char *data, int Fs) +int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) { - int audiosize; + int audiosize; if (data[0]&0x80) { audiosize = ((data[0]>>3)&0x3); @@ -859,4 +858,3 @@ int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char pack else return samples; } - diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 02c3ef721..7969e9392 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -61,7 +61,7 @@ struct OpusEncoder { int signal_type; int user_bandwidth; int voice_ratio; - int Fs; + opus_int32 Fs; int use_vbr; int vbr_constraint; int bitrate_bps; @@ -80,19 +80,19 @@ struct OpusEncoder { int first; opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2]; - int rangeFinal; + opus_uint32 rangeFinal; }; /* Transition tables for the voice and audio modes. First column is the middle (memoriless) threshold. The second column is the hysteresis (difference with the middle) */ -static const int voice_bandwidth_thresholds[10] = { +static const opus_int32 voice_bandwidth_thresholds[10] = { 11000, 1000, /* NB<->MB */ 14000, 1000, /* MB<->WB */ 21000, 2000, /* WB<->SWB */ 29000, 2000, /* SWB<->FB */ }; -static const int audio_bandwidth_thresholds[10] = { +static const opus_int32 audio_bandwidth_thresholds[10] = { 30000, 0, /* MB not allowed */ 20000, 2000, /* MB<->WB */ 26000, 2000, /* WB<->SWB */ @@ -112,7 +112,7 @@ int opus_encoder_get_size(int channels) return align(sizeof(OpusEncoder))+silkEncSizeBytes+celtEncSizeBytes; } -int opus_encoder_init(OpusEncoder* st, int Fs, int channels, int application) +int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int application) { void *silk_enc; CELTEncoder *celt_enc; @@ -306,7 +306,7 @@ static void hp_cutoff(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *ou #endif } -OpusEncoder *opus_encoder_create(int Fs, int channels, int mode, int *error) +OpusEncoder *opus_encoder_create(opus_int32 Fs, int channels, int mode, int *error) { int ret; OpusEncoder *st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels)); @@ -491,7 +491,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, /* Automatic (rate-dependent) bandwidth selection */ if (st->mode == MODE_CELT_ONLY || st->first || st->silk_mode.allowBandwidthSwitch) { - const int *bandwidth_thresholds; + const opus_int32 *bandwidth_thresholds; int bandwidth = OPUS_BANDWIDTH_FULLBAND; bandwidth_thresholds = st->mode == MODE_CELT_ONLY ? audio_bandwidth_thresholds : voice_bandwidth_thresholds; diff --git a/src/test_opus.c b/src/test_opus.c index 7ec1e0593..747f7ee9d 100644 --- a/src/test_opus.c +++ b/src/test_opus.c @@ -90,9 +90,9 @@ int main(int argc, char *argv[]) int args; int len[2]; int frame_size, channels; - int bitrate_bps; + opus_int32 bitrate_bps; unsigned char *data[2]; - int sampling_rate; + opus_int32 sampling_rate; int use_vbr; int max_payload_bytes; int complexity; @@ -101,7 +101,8 @@ int main(int argc, char *argv[]) int forcemono; int cvbr = 0; int packet_loss_perc; - int count=0, count_act=0, k; + opus_int32 count=0, count_act=0; + int k; int skip; int stop=0; short *in, *out; @@ -137,9 +138,9 @@ int main(int argc, char *argv[]) argc--; } application = atoi(argv[1]) + OPUS_APPLICATION_VOIP; - sampling_rate = atoi(argv[2]); + sampling_rate = (opus_int32)atol(argv[2]); channels = atoi(argv[3]); - bitrate_bps = atoi(argv[4]); + bitrate_bps = (opus_int32)atol(argv[4]); if (sampling_rate != 8000 && sampling_rate != 12000 && sampling_rate != 16000 && sampling_rate != 24000 && sampling_rate != 48000) @@ -321,7 +322,7 @@ int main(int argc, char *argv[]) break; } - fprintf(stderr, "Encoding %d Hz input at %.3f kb/s in %s mode with %d-sample frames.\n", 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)); @@ -409,7 +410,7 @@ int main(int argc, char *argv[]) /* 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 %d: 0x%8x vs 0x%8x\n", count, enc_final_range[toggle^use_inbandfec], dec_final_range); + 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; } -- GitLab