ref: d6a0216cf1ed5e5fdb9c390f8857afee5f153146
parent: ff5f7228fda6809abf53dfd378b4a2f095a74c1d
author: Jean-Marc Valin <[email protected]>
date: Fri Jul 29 16:10:27 EDT 2011
Making use of the opus_int* types in the toplevel Opus code
--- a/src/opus.h
+++ b/src/opus.h
@@ -28,6 +28,8 @@
#ifndef OPUS_H
#define OPUS_H
+#include "opus_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -175,7 +177,7 @@
/* Returns length of the data payload (in bytes) */
OPUS_EXPORT int opus_encode(
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 */
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 */
@@ -200,7 +202,7 @@
OpusDecoder *st, /* Decoder state */
const unsigned char *data, /* Input payload. Use a NULL pointer to indicate packet loss */
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 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. */
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -111,7 +111,7 @@
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 i, c;
@@ -144,7 +144,7 @@
}
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;
CELTDecoder *celt_dec;
@@ -152,8 +152,8 @@
ec_dec dec;
silk_DecControlStruct DecControl;
opus_int32 silk_frame_size;
- short pcm_celt[960*2];
- short pcm_transition[480*2];
+ opus_int16 pcm_celt[960*2];
+ opus_int16 pcm_transition[480*2];
int audiosize;
int mode;
@@ -162,7 +162,7 @@
int redundancy=0;
int redundancy_bytes = 0;
int celt_to_silk=0;
- short redundant_audio[240*2];
+ opus_int16 redundant_audio[240*2];
int c;
int F2_5, F5, F10, F20;
const opus_val16 *window;
@@ -413,7 +413,7 @@
}
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 count;
--- a/src/opus_decoder.h
+++ b/src/opus_decoder.h
@@ -48,8 +48,8 @@
int rangeFinal;
};
-static inline short SAT16(int x) {
- return x > 32767 ? 32767 : x < -32768 ? -32768 : (short)x;
+static inline opus_int16 SAT16(opus_int32 x) {
+ return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
};
#endif /* OPUS_DECODER_H */
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -162,7 +162,7 @@
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)
{
void *silk_enc;
@@ -181,7 +181,7 @@
int celt_to_silk = 0;
/* 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 */
- short pcm_buf[60*48*2];
+ opus_int16 pcm_buf[60*48*2];
int nb_compr_bytes;
int to_celt = 0;
opus_int32 mono_rate;
@@ -510,16 +510,16 @@
delta_Q14 = ( st->hybrid_stereo_width_Q14 - st->silk_mode.stereoWidth_Q14 ) / nSamples_8ms;
for( i = 0; i < nSamples_8ms; i++ ) {
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;
- pcm_buf[ 2*i ] = (short)( pcm_buf[ 2*i ] + diff );
- pcm_buf[ 2*i+1 ] = (short)( pcm_buf[ 2*i+1 ] - diff );
+ pcm_buf[ 2*i ] = (opus_int16)( pcm_buf[ 2*i ] + diff );
+ pcm_buf[ 2*i+1 ] = (opus_int16)( pcm_buf[ 2*i+1 ] - diff );
}
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;
- pcm_buf[ 2*i ] = (short)( pcm_buf[ 2*i ] + diff );
- pcm_buf[ 2*i+1 ] = (short)( pcm_buf[ 2*i+1 ] - diff );
+ pcm_buf[ 2*i ] = (opus_int16)( pcm_buf[ 2*i ] + diff );
+ pcm_buf[ 2*i+1 ] = (opus_int16)( pcm_buf[ 2*i+1 ] - diff );
}
st->hybrid_stereo_width_Q14 = st->silk_mode.stereoWidth_Q14;
}