Merge remote-tracking branch 'greg/master'

Conflicts:
	src/opus_encoder.c
This commit is contained in:
Jean-Marc Valin 2011-09-02 17:23:22 -04:00
commit 6268300c5e
10 changed files with 82 additions and 84 deletions

View file

@ -215,7 +215,7 @@ CELTEncoder *opus_custom_encoder_create(const CELTMode *mode, int channels, int
} }
#endif /* CUSTOM_MODES */ #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; int ret;
ret = opus_custom_encoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels); 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 */ #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; int ret;
ret = opus_custom_decoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels); ret = opus_custom_decoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels);

View file

@ -85,7 +85,7 @@ extern "C" {
int celt_encoder_get_size(int channels); 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_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);
/* @} */ /* @} */

View file

@ -48,10 +48,9 @@ int main(int argc, char *argv[])
OpusCustomEncoder *enc; OpusCustomEncoder *enc;
OpusCustomDecoder *dec; OpusCustomDecoder *dec;
int len; int len;
opus_int32 frame_size, channels; opus_int32 frame_size, channels, rate;
int bytes_per_packet; int bytes_per_packet;
unsigned char data[MAX_PACKET]; unsigned char data[MAX_PACKET];
int rate;
int complexity; int complexity;
#if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH) #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH)
int i; int i;
@ -68,7 +67,7 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
rate = atoi(argv[1]); rate = (opus_int32)atol(argv[1]);
channels = atoi(argv[2]); channels = atoi(argv[2]);
frame_size = atoi(argv[3]); frame_size = atoi(argv[3]);
mode = opus_custom_mode_create(rate, frame_size, NULL); mode = opus_custom_mode_create(rate, frame_size, NULL);

View file

@ -56,7 +56,7 @@ typedef struct {
/* Get size in bytes of the Silk encoder state */ /* Get size in bytes of the Silk encoder state */
/***********************************************/ /***********************************************/
opus_int silk_Get_Encoder_Size( /* O: Returns error code */ 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 */ const opus_int16 *samplesIn, /* I: Speech sample input vector */
opus_int nSamplesIn, /* I: Number of samples in input vector */ opus_int nSamplesIn, /* I: Number of samples in input vector */
ec_enc *psRangeEnc, /* I/O Compressor data structure */ 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 */ 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 */ /* Get size in bytes of the Silk decoder state */
/***********************************************/ /***********************************************/
opus_int silk_Get_Decoder_Size( /* O: Returns error code */ 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 */
); );
/*************************/ /*************************/

View file

@ -45,7 +45,7 @@ typedef struct {
/* Decoder functions */ /* 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; opus_int ret = SILK_NO_ERROR;
@ -84,7 +84,7 @@ opus_int silk_Decode(
opus_int32 nSamplesOutDec, LBRR_symbol; opus_int32 nSamplesOutDec, LBRR_symbol;
opus_int16 samplesOut1_tmp[ 2 ][ MAX_FS_KHZ * MAX_FRAME_LENGTH_MS + 2 ]; 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_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; opus_int16 *resample_out_ptr;
silk_decoder *psDec = ( silk_decoder * )decState; silk_decoder *psDec = ( silk_decoder * )decState;
silk_decoder_state *channel_state = psDec->channel_state; silk_decoder_state *channel_state = psDec->channel_state;

View file

@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Encoder functions */ /* 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; opus_int ret = SILK_NO_ERROR;
@ -128,7 +128,7 @@ opus_int silk_Encode(
const opus_int16 *samplesIn, /* I: Speech sample input vector */ const opus_int16 *samplesIn, /* I: Speech sample input vector */
opus_int nSamplesIn, /* I: Number of samples in input vector */ opus_int nSamplesIn, /* I: Number of samples in input vector */
ec_enc *psRangeEnc, /* I/O Compressor data structure */ 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 */ const opus_int prefillFlag /* I: Flag to indicate prefilling buffers; no coding */
) )
{ {

View file

@ -75,7 +75,7 @@ OPUS_EXPORT int opus_encoder_get_size(int channels);
/* Returns initialized encoder state */ /* Returns initialized encoder state */
OPUS_EXPORT OpusEncoder *opus_encoder_create( 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 channels, /* Number of channels (1/2) in input signal */
int application, /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ int application, /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
int *error /* Error code */ int *error /* Error code */
@ -83,7 +83,7 @@ OPUS_EXPORT OpusEncoder *opus_encoder_create(
OPUS_EXPORT int opus_encoder_init( OPUS_EXPORT int opus_encoder_init(
OpusEncoder *st, /* Encoder state */ 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 channels, /* Number of channels (1/2) in input signal */
int application /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ 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 int opus_decoder_get_size(int channels);
OPUS_EXPORT OpusDecoder *opus_decoder_create( 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 channels, /* Number of channels (1/2) in output signal */
int *error /* Error code*/ int *error /* Error code*/
); );
OPUS_EXPORT int opus_decoder_init(OpusDecoder *st, 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 */ 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); short size[48], int *payload_offset);
OPUS_EXPORT int opus_packet_get_bandwidth(const unsigned char *data); 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_channels(const unsigned char *data);
OPUS_EXPORT int opus_packet_get_nb_frames(const unsigned char packet[], int len); 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); OPUS_EXPORT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], int len);

View file

@ -44,7 +44,7 @@ struct OpusDecoder {
int celt_dec_offset; int celt_dec_offset;
int silk_dec_offset; int silk_dec_offset;
int channels; 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 */ /* Everything beyond this point gets cleared on a reset */
#define OPUS_DECODER_RESET_START stream_channels #define OPUS_DECODER_RESET_START stream_channels
@ -56,7 +56,7 @@ struct OpusDecoder {
int frame_size; int frame_size;
int prev_redundancy; int prev_redundancy;
int rangeFinal; opus_uint32 rangeFinal;
}; };
#ifdef FIXED_POINT #ifdef FIXED_POINT
@ -68,61 +68,60 @@ static inline opus_int16 SAT16(opus_int32 x) {
int opus_decoder_get_size(int channels) int opus_decoder_get_size(int channels)
{ {
int silkDecSizeBytes, celtDecSizeBytes; int silkDecSizeBytes, celtDecSizeBytes;
int ret; int ret;
ret = silk_Get_Decoder_Size( &silkDecSizeBytes ); ret = silk_Get_Decoder_Size( &silkDecSizeBytes );
if(ret) if(ret)
return 0; return 0;
silkDecSizeBytes = align(silkDecSizeBytes); silkDecSizeBytes = align(silkDecSizeBytes);
celtDecSizeBytes = celt_decoder_get_size(channels); celtDecSizeBytes = celt_decoder_get_size(channels);
return align(sizeof(OpusDecoder))+silkDecSizeBytes+celtDecSizeBytes; 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; void *silk_dec;
CELTDecoder *celt_dec; CELTDecoder *celt_dec;
int ret, silkDecSizeBytes; int ret, silkDecSizeBytes;
if (channels<1 || channels > 2) if (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 ) { if( ret ) {
return OPUS_INTERNAL_ERROR; return OPUS_INTERNAL_ERROR;
} }
silkDecSizeBytes = align(silkDecSizeBytes); silkDecSizeBytes = align(silkDecSizeBytes);
st->silk_dec_offset = align(sizeof(OpusDecoder)); st->silk_dec_offset = align(sizeof(OpusDecoder));
st->celt_dec_offset = st->silk_dec_offset+silkDecSizeBytes; st->celt_dec_offset = st->silk_dec_offset+silkDecSizeBytes;
silk_dec = (char*)st+st->silk_dec_offset; silk_dec = (char*)st+st->silk_dec_offset;
celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset);
st->stream_channels = st->channels = channels; st->stream_channels = st->channels = channels;
st->Fs = Fs; st->Fs = Fs;
/* Reset decoder */ /* Reset decoder */
ret = silk_InitDecoder( silk_dec ); ret = silk_InitDecoder( silk_dec );
if( ret ) { if( ret ) {
goto failure; goto failure;
} }
/* Initialize CELT decoder */ /* Initialize CELT decoder */
ret = celt_decoder_init(celt_dec, Fs, channels); ret = celt_decoder_init(celt_dec, Fs, channels);
if (ret != OPUS_OK) if (ret != OPUS_OK)
goto failure; goto failure;
celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0)); celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0));
st->prev_mode = 0; st->prev_mode = 0;
st->frame_size = Fs/400; st->frame_size = Fs/400;
return OPUS_OK; return OPUS_OK;
failure: failure:
opus_free(st); opus_free(st);
return OPUS_INTERNAL_ERROR; 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; int ret;
OpusDecoder *st = (OpusDecoder *)opus_alloc(opus_decoder_get_size(channels)); 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, 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 i, c;
int inc = 48000/Fs; 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, static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
int len, opus_val16 *pcm, int frame_size, int decode_fec) int len, opus_val16 *pcm, int frame_size, int decode_fec)
{ {
void *silk_dec; void *silk_dec;
CELTDecoder *celt_dec; CELTDecoder *celt_dec;
int i, silk_ret=0, celt_ret=0; int i, silk_ret=0, celt_ret=0;
ec_dec dec; ec_dec dec;
silk_DecControlStruct DecControl; silk_DecControlStruct DecControl;
opus_int32 silk_frame_size; opus_int32 silk_frame_size;
VARDECL(opus_int16, pcm_silk); VARDECL(opus_int16, pcm_silk);
@ -806,9 +805,9 @@ int opus_packet_get_bandwidth(const unsigned char *data)
return bandwidth; 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) if (data[0]&0x80)
{ {
audiosize = ((data[0]>>3)&0x3); audiosize = ((data[0]>>3)&0x3);
@ -859,4 +858,3 @@ int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char pack
else else
return samples; return samples;
} }

View file

@ -61,7 +61,7 @@ struct OpusEncoder {
int signal_type; int signal_type;
int user_bandwidth; int user_bandwidth;
int voice_ratio; int voice_ratio;
int Fs; opus_int32 Fs;
int use_vbr; int use_vbr;
int vbr_constraint; int vbr_constraint;
int bitrate_bps; int bitrate_bps;
@ -80,7 +80,7 @@ struct OpusEncoder {
int first; int first;
opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2]; opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2];
int rangeFinal; opus_uint32 rangeFinal;
}; };
/* Transition tables for the voice and music. First column is the /* Transition tables for the voice and music. First column is the
@ -132,7 +132,7 @@ int opus_encoder_get_size(int channels)
return align(sizeof(OpusEncoder))+silkEncSizeBytes+celtEncSizeBytes; 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; void *silk_enc;
CELTEncoder *celt_enc; CELTEncoder *celt_enc;
@ -326,7 +326,7 @@ static void hp_cutoff(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *ou
#endif #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; int ret;
OpusEncoder *st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels)); OpusEncoder *st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels));

View file

@ -90,9 +90,9 @@ int main(int argc, char *argv[])
int args; int args;
int len[2]; int len[2];
int frame_size, channels; int frame_size, channels;
int bitrate_bps; opus_int32 bitrate_bps;
unsigned char *data[2]; unsigned char *data[2];
int sampling_rate; opus_int32 sampling_rate;
int use_vbr; int use_vbr;
int max_payload_bytes; int max_payload_bytes;
int complexity; int complexity;
@ -101,7 +101,8 @@ int main(int argc, char *argv[])
int forcemono; int forcemono;
int cvbr = 0; int cvbr = 0;
int packet_loss_perc; int packet_loss_perc;
int count=0, count_act=0, k; opus_int32 count=0, count_act=0;
int k;
int skip; int skip;
int stop=0; int stop=0;
short *in, *out; short *in, *out;
@ -138,9 +139,9 @@ int main(int argc, char *argv[])
argc--; argc--;
} }
application = atoi(argv[1]) + OPUS_APPLICATION_VOIP; application = atoi(argv[1]) + OPUS_APPLICATION_VOIP;
sampling_rate = atoi(argv[2]); sampling_rate = (opus_int32)atol(argv[2]);
channels = atoi(argv[3]); 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 if (sampling_rate != 8000 && sampling_rate != 12000 && sampling_rate != 16000
&& sampling_rate != 24000 && sampling_rate != 48000) && sampling_rate != 24000 && sampling_rate != 48000)
@ -325,7 +326,7 @@ int main(int argc, char *argv[])
break; 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)); 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));
@ -421,7 +422,7 @@ int main(int argc, char *argv[])
/* 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 && !lost && !lost_prev &&
dec_final_range != enc_final_range[toggle^use_inbandfec] ) { 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; return 0;
} }