static void opus_copy_channel_out_short( void *dst, int dst_stride, int dst_channel, const opus_val16 *src, int src_stride, int frame_size ) { opus_int16 *short_dst; opus_int32 i; short_dst = (opus_int16*)dst; if (src != NULL) { for (i=0;i<frame_size;i++) #if defined(FIXED_POINT) short_dst[i*dst_stride+dst_channel] = src[i*src_stride]; #else short_dst[i*dst_stride+dst_channel] = FLOAT2INT16(src[i*src_stride]); #endif } else { for (i=0;i<frame_size;i++) short_dst[i*dst_stride+dst_channel] = 0; } }
int opus_decode(OpusDecoder *st, const unsigned char *data, opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec) { VARDECL(float, out); int ret, i; int nb_samples; ALLOC_STACK; if(frame_size<=0) { RESTORE_STACK; return OPUS_BAD_ARG; } if (data != NULL && len > 0 && !decode_fec) { nb_samples = opus_decoder_get_nb_samples(st, data, len); if (nb_samples>0) frame_size = IMIN(frame_size, nb_samples); else return OPUS_INVALID_PACKET; } ALLOC(out, frame_size*st->channels, float); ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1); if (ret > 0) { for (i=0; i<ret*st->channels; i++) pcm[i] = FLOAT2INT16(out[i]); } RESTORE_STACK; return ret; }
void mapping_matrix_multiply_channel_in_float( const MappingMatrix *matrix, const float *input, int input_rows, opus_val16 *output, int output_row, int output_rows, int frame_size) { /* Matrix data is ordered col-wise. */ opus_int16* matrix_data; int i, col; celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); matrix_data = mapping_matrix_get_data(matrix); for (i = 0; i < frame_size; i++) { float tmp = 0; for (col = 0; col < input_rows; col++) { tmp += matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * input[MATRIX_INDEX(input_rows, col, i)]; } #if defined(FIXED_POINT) output[output_rows * i] = FLOAT2INT16((1/32768.f)*tmp); #else output[output_rows * i] = (1/32768.f)*tmp; #endif } }
void mapping_matrix_multiply_channel_out_short( const MappingMatrix *matrix, const opus_val16 *input, int input_row, int input_rows, opus_int16 *output, int output_rows, int frame_size) { /* Matrix data is ordered col-wise. */ opus_int16* matrix_data; int i, row; opus_int32 input_sample; celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); matrix_data = mapping_matrix_get_data(matrix); for (i = 0; i < frame_size; i++) { #if defined(FIXED_POINT) input_sample = (opus_int32)input[input_rows * i]; #else input_sample = (opus_int32)FLOAT2INT16(input[input_rows * i]); #endif for (row = 0; row < output_rows; row++) { opus_int32 tmp = (opus_int32)matrix_data[MATRIX_INDEX(matrix->rows, row, input_row)] * input_sample; output[MATRIX_INDEX(output_rows, row, i)] += (tmp + 16384) >> 15; } } }
int opus_multistream_decode(OpusMSDecoder *st, const unsigned char *data, opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec) { VARDECL(float, out); int ret, i; ALLOC_STACK; ALLOC(out, frame_size*st->layout.nb_channels, float); ret = opus_multistream_decode_native(st, data, len, out, frame_size, decode_fec); if (ret > 0) { for (i=0;i<ret*st->layout.nb_channels;i++) pcm[i] = FLOAT2INT16(out[i]); } RESTORE_STACK; return ret; }
int opus_decode(OpusDecoder *st, const unsigned char *data, int len, opus_int16 *pcm, int frame_size, int decode_fec) { VARDECL(float, out); int ret, i; ALLOC_STACK; if(frame_size<0)return OPUS_BAD_ARG; ALLOC(out, frame_size*st->channels, float); ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL); if (ret > 0) { for (i=0;i<ret*st->channels;i++) pcm[i] = FLOAT2INT16(out[i]); } RESTORE_STACK; return ret; }
int opus_multistream_encode_float( OpusMSEncoder *st, const float *pcm, int frame_size, unsigned char *data, opus_int32 max_data_bytes ) { int i, ret; VARDECL(opus_int16, in); ALLOC_STACK; ALLOC(in, frame_size*st->layout.nb_channels, opus_int16); for (i=0;i<frame_size*st->layout.nb_channels;i++) in[i] = FLOAT2INT16(pcm[i]); ret = opus_multistream_encode(st, in, frame_size, data, max_data_bytes); RESTORE_STACK; return ret; }