diff --git a/dnn/dump_data.c b/dnn/dump_data.c index 053ca774..2c1b783a 100644 --- a/dnn/dump_data.c +++ b/dnn/dump_data.c @@ -73,7 +73,7 @@ void compute_noise(int *noise, float noise_std) { } } -static short float2short(float x) +static opus_int16 float2short(float x) { int i; i = (int)floor(.5+x); @@ -81,9 +81,9 @@ static short float2short(float x) } -void write_audio(LPCNetEncState *st, const short *pcm, const int *noise, FILE *file) { +void write_audio(LPCNetEncState *st, const opus_int16 *pcm, const int *noise, FILE *file) { int i; - short data[2*FRAME_SIZE]; + opus_int16 data[2*FRAME_SIZE]; for (i=0;innet.gru_b_state, GRU_B_STATE_SIZE); } -void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, short *output, int N, int preload) +void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, opus_int16 *output, int N, int preload) { int i; @@ -270,12 +270,12 @@ void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, short *output, int N, int } } -void lpcnet_synthesize_impl(LPCNetState *lpcnet, const float *features, short *output, int N, int preload) +void lpcnet_synthesize_impl(LPCNetState *lpcnet, const float *features, opus_int16 *output, int N, int preload) { run_frame_network(lpcnet, lpcnet->gru_a_condition, lpcnet->gru_b_condition, lpcnet->lpc, features); lpcnet_synthesize_tail_impl(lpcnet, output, N, preload); } -void lpcnet_synthesize(LPCNetState *lpcnet, const float *features, short *output, int N) { +void lpcnet_synthesize(LPCNetState *lpcnet, const float *features, opus_int16 *output, int N) { lpcnet_synthesize_impl(lpcnet, features, output, N, 0); } diff --git a/dnn/lpcnet.h b/dnn/lpcnet.h index 52813c21..836b168b 100644 --- a/dnn/lpcnet.h +++ b/dnn/lpcnet.h @@ -27,7 +27,7 @@ #ifndef _LPCNET_H_ #define _LPCNET_H_ - +#include "opus_types.h" #define NB_FEATURES 20 #define NB_TOTAL_FEATURES 36 @@ -73,10 +73,10 @@ void lpcnet_decoder_destroy(LPCNetDecState *st); /** Decodes a packet of LPCNET_COMPRESSED_SIZE bytes (currently 8) into LPCNET_PACKET_SAMPLES samples (currently 640). * @param [in] st LPCNetDecState*: Decoder state * @param [in] buf const unsigned char *: Compressed packet - * @param [out] pcm short *: Decoded audio + * @param [out] pcm opus_int16 *: Decoded audio * @retval 0 Success */ -int lpcnet_decode(LPCNetDecState *st, const unsigned char *buf, short *pcm); +int lpcnet_decode(LPCNetDecState *st, const unsigned char *buf, opus_int16 *pcm); @@ -106,27 +106,19 @@ void lpcnet_encoder_destroy(LPCNetEncState *st); /** Encodes LPCNET_PACKET_SAMPLES speech samples (currently 640) into a packet of LPCNET_COMPRESSED_SIZE bytes (currently 8). * @param [in] st LPCNetDecState*: Encoder state - * @param [in] pcm short *: Input speech to be encoded + * @param [in] pcm opus_int16 *: Input speech to be encoded * @param [out] buf const unsigned char *: Compressed packet * @retval 0 Success */ -int lpcnet_encode(LPCNetEncState *st, const short *pcm, unsigned char *buf); - -/** Compute features on LPCNET_PACKET_SAMPLES speech samples (currently 640) and output features for 4 10-ms frames at once. - * @param [in] st LPCNetDecState*: Encoder state - * @param [in] pcm short *: Input speech to be analyzed - * @param [out] features float[4][NB_TOTAL_FEATURES]: Four feature vectors - * @retval 0 Success - */ -int lpcnet_compute_features(LPCNetEncState *st, const short *pcm, float features[4][NB_TOTAL_FEATURES]); +int lpcnet_encode(LPCNetEncState *st, const opus_int16 *pcm, unsigned char *buf); /** Compute features on LPCNET_FRAME_SIZE speech samples (currently 160) and output features for one 10-ms frame. * @param [in] st LPCNetDecState*: Encoder state - * @param [in] pcm short *: Input speech to be analyzed + * @param [in] pcm opus_int16 *: Input speech to be analyzed * @param [out] features float[NB_TOTAL_FEATURES]: Four feature vectors * @retval 0 Success */ -int lpcnet_compute_single_frame_features(LPCNetEncState *st, const short *pcm, float features[NB_TOTAL_FEATURES]); +int lpcnet_compute_single_frame_features(LPCNetEncState *st, const opus_int16 *pcm, float features[NB_TOTAL_FEATURES]); /** Compute features on LPCNET_FRAME_SIZE speech samples (currently 160) and output features for one 10-ms frame. @@ -164,11 +156,11 @@ void lpcnet_destroy(LPCNetState *st); /** Synthesizes speech from an LPCNet feature vector. * @param [in] st LPCNetState*: Synthesis state * @param [in] features const float *: Compressed packet - * @param [out] output short **: Synthesized speech + * @param [out] output opus_int16 **: Synthesized speech * @param [in] N int: Number of samples to generate * @retval 0 Success */ -void lpcnet_synthesize(LPCNetState *st, const float *features, short *output, int N); +void lpcnet_synthesize(LPCNetState *st, const float *features, opus_int16 *output, int N); #define LPCNET_PLC_CAUSAL 0 @@ -184,9 +176,9 @@ LPCNetPLCState *lpcnet_plc_create(int options); void lpcnet_plc_destroy(LPCNetPLCState *st); -int lpcnet_plc_update(LPCNetPLCState *st, short *pcm); +int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm); -int lpcnet_plc_conceal(LPCNetPLCState *st, short *pcm); +int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm); void lpcnet_plc_fec_add(LPCNetPLCState *st, const float *features); diff --git a/dnn/lpcnet_demo.c b/dnn/lpcnet_demo.c index 1b1a5650..a41f5120 100644 --- a/dnn/lpcnet_demo.c +++ b/dnn/lpcnet_demo.c @@ -158,7 +158,7 @@ int main(int argc, char **argv) { net = lpcnet_encoder_create(); while (1) { float features[NB_TOTAL_FEATURES]; - short pcm[LPCNET_FRAME_SIZE]; + opus_int16 pcm[LPCNET_FRAME_SIZE]; size_t ret; ret = fread(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fin); if (feof(fin) || ret != LPCNET_FRAME_SIZE) break; @@ -175,7 +175,7 @@ int main(int argc, char **argv) { while (1) { float in_features[NB_TOTAL_FEATURES]; float features[NB_FEATURES]; - short pcm[LPCNET_FRAME_SIZE]; + opus_int16 pcm[LPCNET_FRAME_SIZE]; size_t ret; ret = fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin); if (feof(fin) || ret != NB_TOTAL_FEATURES) break; @@ -185,7 +185,7 @@ int main(int argc, char **argv) { } lpcnet_destroy(net); } else if (mode == MODE_PLC) { - short pcm[FRAME_SIZE]; + opus_int16 pcm[FRAME_SIZE]; int count=0; int loss=0; int skip=0, extra=0; diff --git a/dnn/lpcnet_enc.c b/dnn/lpcnet_enc.c index f5e33689..0e77ced2 100644 --- a/dnn/lpcnet_enc.c +++ b/dnn/lpcnet_enc.c @@ -233,7 +233,7 @@ static int lpcnet_compute_single_frame_features_impl(LPCNetEncState *st, float * return 0; } -int lpcnet_compute_single_frame_features(LPCNetEncState *st, const short *pcm, float features[NB_TOTAL_FEATURES]) { +int lpcnet_compute_single_frame_features(LPCNetEncState *st, const opus_int16 *pcm, float features[NB_TOTAL_FEATURES]) { int i; float x[FRAME_SIZE]; for (i=0;iskip_analysis) { /*fprintf(stderr, "skip update\n");*/ if (st->blend) { - short tmp[FRAME_SIZE-TRAINING_OFFSET]; + opus_int16 tmp[FRAME_SIZE-TRAINING_OFFSET]; float zeros[2*NB_BANDS+NB_FEATURES+1] = {0}; RNN_COPY(zeros, plc_features, 2*NB_BANDS); zeros[2*NB_BANDS+NB_FEATURES] = 1; @@ -263,9 +263,9 @@ int lpcnet_plc_update(LPCNetPLCState *st, short *pcm) { } static const float att_table[10] = {0, 0, -.2, -.2, -.4, -.4, -.8, -.8, -1.6, -1.6}; -int lpcnet_plc_conceal(LPCNetPLCState *st, short *pcm) { +int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm) { int i; - short output[FRAME_SIZE]; + opus_int16 output[FRAME_SIZE]; run_frame_network_flush(&st->lpcnet); /* If we concealed the previous frame, finish synthesizing the rest of the samples. */ /* FIXME: Copy/predict features. */ diff --git a/dnn/lpcnet_private.h b/dnn/lpcnet_private.h index a0f0f7da..a2eba6db 100644 --- a/dnn/lpcnet_private.h +++ b/dnn/lpcnet_private.h @@ -77,7 +77,7 @@ struct LPCNetPLCState { int fec_read_pos; int fec_fill_pos; int fec_skip; - short pcm[PLC_BUF_SIZE+FRAME_SIZE]; + opus_int16 pcm[PLC_BUF_SIZE+FRAME_SIZE]; int pcm_fill; int skip_analysis; int blend; @@ -91,19 +91,17 @@ void preemphasis(float *y, float *mem, const float *x, float coef, int N); void compute_frame_features(LPCNetEncState *st, const float *in); -void decode_packet(float features[4][NB_TOTAL_FEATURES], float *vq_mem, const unsigned char buf[8]); - void lpcnet_reset_signal(LPCNetState *lpcnet); void run_frame_network(LPCNetState *lpcnet, float *gru_a_condition, float *gru_b_condition, float *lpc, const float *features); void run_frame_network_deferred(LPCNetState *lpcnet, const float *features); void run_frame_network_flush(LPCNetState *lpcnet); -void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, short *output, int N, int preload); -void lpcnet_synthesize_impl(LPCNetState *lpcnet, const float *features, short *output, int N, int preload); -void lpcnet_synthesize_blend_impl(LPCNetState *lpcnet, const short *pcm_in, short *output, int N); +void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, opus_int16 *output, int N, int preload); +void lpcnet_synthesize_impl(LPCNetState *lpcnet, const float *features, opus_int16 *output, int N, int preload); +void lpcnet_synthesize_blend_impl(LPCNetState *lpcnet, const opus_int16 *pcm_in, opus_int16 *output, int N); void process_single_frame(LPCNetEncState *st, FILE *ffeat); -int lpcnet_compute_single_frame_features(LPCNetEncState *st, const short *pcm, float features[NB_TOTAL_FEATURES]); +int lpcnet_compute_single_frame_features(LPCNetEncState *st, const opus_int16 *pcm, float features[NB_TOTAL_FEATURES]); void process_single_frame(LPCNetEncState *st, FILE *ffeat);