Making use of the opus_int* types in the toplevel Opus code

This commit is contained in:
Jean-Marc Valin 2011-07-29 20:10:27 -04:00
parent ff5f7228fd
commit d6a0216cf1
4 changed files with 20 additions and 18 deletions

View file

@ -28,6 +28,8 @@
#ifndef OPUS_H #ifndef OPUS_H
#define OPUS_H #define OPUS_H
#include "opus_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -175,7 +177,7 @@ OPUS_EXPORT OpusEncoder *opus_encoder_init(
/* Returns length of the data payload (in bytes) */ /* Returns length of the data payload (in bytes) */
OPUS_EXPORT int opus_encode( OPUS_EXPORT int opus_encode(
OpusEncoder *st, /* Encoder state */ OpusEncoder *st, /* Encoder state */
const short *pcm, /* Input signal (interleaved if 2 channels). length is frame_size*channels */ const opus_int16 *pcm, /* Input signal (interleaved if 2 channels). length is frame_size*channels */
int frame_size, /* Number of samples per frame of input signal */ int frame_size, /* Number of samples per frame of input signal */
unsigned char *data, /* Output payload (no more than max_data_bytes long) */ unsigned char *data, /* Output payload (no more than max_data_bytes long) */
int max_data_bytes /* Allocated memory for payload; don't use for controlling bitrate */ int max_data_bytes /* Allocated memory for payload; don't use for controlling bitrate */
@ -200,7 +202,7 @@ OPUS_EXPORT int opus_decode(
OpusDecoder *st, /* Decoder state */ OpusDecoder *st, /* Decoder state */
const unsigned char *data, /* Input payload. Use a NULL pointer to indicate packet loss */ const unsigned char *data, /* Input payload. Use a NULL pointer to indicate packet loss */
int len, /* Number of bytes in payload */ int len, /* Number of bytes in payload */
short *pcm, /* Output signal (interleaved if 2 channels). length is frame_size*channels */ opus_int16 *pcm, /* Output signal (interleaved if 2 channels). length is frame_size*channels */
int frame_size, /* Number of samples per frame of input signal */ int frame_size, /* Number of samples per frame of input signal */
int decode_fec /* Flag (0/1) to request that any in-band forward error correction data be */ int decode_fec /* Flag (0/1) to request that any in-band forward error correction data be */
/* decoded. If no such data is available the frame is decoded as if it were lost. */ /* decoded. If no such data is available the frame is decoded as if it were lost. */

View file

@ -111,7 +111,7 @@ OpusDecoder *opus_decoder_create(int Fs, int channels)
return opus_decoder_init((OpusDecoder*)raw_state, Fs, channels); return opus_decoder_init((OpusDecoder*)raw_state, Fs, channels);
} }
static void smooth_fade(const short *in1, const short *in2, short *out, static void smooth_fade(const opus_int16 *in1, const opus_int16 *in2, opus_int16 *out,
int overlap, int channels, const opus_val16 *window, int Fs) int overlap, int channels, const opus_val16 *window, int Fs)
{ {
int i, c; int i, c;
@ -144,7 +144,7 @@ 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, short *pcm, int frame_size, int decode_fec) int len, opus_int16 *pcm, int frame_size, int decode_fec)
{ {
void *silk_dec; void *silk_dec;
CELTDecoder *celt_dec; CELTDecoder *celt_dec;
@ -152,8 +152,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
ec_dec dec; ec_dec dec;
silk_DecControlStruct DecControl; silk_DecControlStruct DecControl;
opus_int32 silk_frame_size; opus_int32 silk_frame_size;
short pcm_celt[960*2]; opus_int16 pcm_celt[960*2];
short pcm_transition[480*2]; opus_int16 pcm_transition[480*2];
int audiosize; int audiosize;
int mode; int mode;
@ -162,7 +162,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
int redundancy=0; int redundancy=0;
int redundancy_bytes = 0; int redundancy_bytes = 0;
int celt_to_silk=0; int celt_to_silk=0;
short redundant_audio[240*2]; opus_int16 redundant_audio[240*2];
int c; int c;
int F2_5, F5, F10, F20; int F2_5, F5, F10, F20;
const opus_val16 *window; const opus_val16 *window;
@ -413,7 +413,7 @@ static int parse_size(const unsigned char *data, int len, short *size)
} }
int opus_decode(OpusDecoder *st, const unsigned char *data, int opus_decode(OpusDecoder *st, const unsigned char *data,
int len, short *pcm, int frame_size, int decode_fec) int len, opus_int16 *pcm, int frame_size, int decode_fec)
{ {
int i, bytes, nb_samples; int i, bytes, nb_samples;
int count; int count;

View file

@ -48,8 +48,8 @@ struct OpusDecoder {
int rangeFinal; int rangeFinal;
}; };
static inline short SAT16(int x) { static inline opus_int16 SAT16(opus_int32 x) {
return x > 32767 ? 32767 : x < -32768 ? -32768 : (short)x; return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
}; };
#endif /* OPUS_DECODER_H */ #endif /* OPUS_DECODER_H */

View file

@ -162,7 +162,7 @@ OpusEncoder *opus_encoder_create(int Fs, int channels, int mode)
return opus_encoder_init((OpusEncoder*)raw_state, Fs, channels, mode); return opus_encoder_init((OpusEncoder*)raw_state, Fs, channels, mode);
} }
int opus_encode(OpusEncoder *st, const short *pcm, int frame_size, int opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size,
unsigned char *data, int max_data_bytes) unsigned char *data, int max_data_bytes)
{ {
void *silk_enc; void *silk_enc;
@ -181,7 +181,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
int celt_to_silk = 0; int celt_to_silk = 0;
/* TODO: This is 60 only so we can handle 60ms speech/audio switching /* TODO: This is 60 only so we can handle 60ms speech/audio switching
it shouldn't be too hard to reduce to 20 ms if needed */ it shouldn't be too hard to reduce to 20 ms if needed */
short pcm_buf[60*48*2]; opus_int16 pcm_buf[60*48*2];
int nb_compr_bytes; int nb_compr_bytes;
int to_celt = 0; int to_celt = 0;
opus_int32 mono_rate; opus_int32 mono_rate;
@ -510,16 +510,16 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
delta_Q14 = ( st->hybrid_stereo_width_Q14 - st->silk_mode.stereoWidth_Q14 ) / nSamples_8ms; delta_Q14 = ( st->hybrid_stereo_width_Q14 - st->silk_mode.stereoWidth_Q14 ) / nSamples_8ms;
for( i = 0; i < nSamples_8ms; i++ ) { for( i = 0; i < nSamples_8ms; i++ ) {
width_Q14 += delta_Q14; width_Q14 += delta_Q14;
diff = pcm_buf[ 2*i+1 ] - (int)pcm_buf[ 2*i ]; diff = pcm_buf[ 2*i+1 ] - (opus_int32)pcm_buf[ 2*i ];
diff = ( diff * width_Q14 ) >> 15; diff = ( diff * width_Q14 ) >> 15;
pcm_buf[ 2*i ] = (short)( pcm_buf[ 2*i ] + diff ); pcm_buf[ 2*i ] = (opus_int16)( pcm_buf[ 2*i ] + diff );
pcm_buf[ 2*i+1 ] = (short)( pcm_buf[ 2*i+1 ] - diff ); pcm_buf[ 2*i+1 ] = (opus_int16)( pcm_buf[ 2*i+1 ] - diff );
} }
for( ; i < frame_size; i++ ) { for( ; i < frame_size; i++ ) {
diff = pcm_buf[ 2*i+1 ] - (int)pcm_buf[ 2*i ]; diff = pcm_buf[ 2*i+1 ] - (opus_int32)pcm_buf[ 2*i ];
diff = ( diff * width_Q14 ) >> 15; diff = ( diff * width_Q14 ) >> 15;
pcm_buf[ 2*i ] = (short)( pcm_buf[ 2*i ] + diff ); pcm_buf[ 2*i ] = (opus_int16)( pcm_buf[ 2*i ] + diff );
pcm_buf[ 2*i+1 ] = (short)( pcm_buf[ 2*i+1 ] - diff ); pcm_buf[ 2*i+1 ] = (opus_int16)( pcm_buf[ 2*i+1 ] - diff );
} }
st->hybrid_stereo_width_Q14 = st->silk_mode.stereoWidth_Q14; st->hybrid_stereo_width_Q14 = st->silk_mode.stereoWidth_Q14;
} }