OpusMSDecoder *opus_multistream_decoder_create( opus_int32 Fs, int channels, int streams, int coupled_streams, const unsigned char *mapping, int *error ) { int ret; OpusMSDecoder *st; if ((channels>255) || (channels<1) || (coupled_streams>streams) || (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0)) { if (error) *error = OPUS_BAD_ARG; return NULL; } st = (OpusMSDecoder *)opus_alloc(opus_multistream_decoder_get_size(streams, coupled_streams)); if (st==NULL) { if (error) *error = OPUS_ALLOC_FAIL; return NULL; } ret = opus_multistream_decoder_init(st, Fs, channels, streams, coupled_streams, mapping); if (error) *error = ret; if (ret != OPUS_OK) { opus_free(st); st = NULL; } return st; }
FOpusDecoderWrapper(uint16 SampleRate, uint8 NumChannels) { #if WITH_OPUS check(NumChannels <= 8); const UnrealChannelLayout& Layout = UnrealMappings[NumChannels-1]; #if USE_UE4_MEM_ALLOC int32 DecSize = opus_multistream_decoder_get_size(Layout.NumStreams, Layout.NumCoupledStreams); Decoder = (OpusMSDecoder*)FMemory::Malloc(DecSize); DecError = opus_multistream_decoder_init(Decoder, SampleRate, NumChannels, Layout.NumStreams, Layout.NumCoupledStreams, Layout.Mapping); #else Decoder = opus_multistream_decoder_create(SampleRate, NumChannels, Layout.NumStreams, Layout.NumCoupledStreams, Layout.Mapping, &DecError); #endif #endif }
int opus_projection_decoder_init(OpusProjectionDecoder *st, opus_int32 Fs, int channels, int streams, int coupled_streams, unsigned char *demixing_matrix, opus_int32 demixing_matrix_size) { int nb_input_streams; opus_int32 expected_matrix_size; int i, ret; unsigned char mapping[255]; VARDECL(opus_int16, buf); ALLOC_STACK; /* Verify supplied matrix size. */ nb_input_streams = streams + coupled_streams; expected_matrix_size = nb_input_streams * channels * sizeof(opus_int16); if (expected_matrix_size != demixing_matrix_size) { RESTORE_STACK; return OPUS_BAD_ARG; } /* Convert demixing matrix input into internal format. */ ALLOC(buf, nb_input_streams * channels, opus_int16); for (i = 0; i < nb_input_streams * channels; i++) { int s = demixing_matrix[2*i + 1] << 8 | demixing_matrix[2*i]; s = ((s & 0xFFFF) ^ 0x8000) - 0x8000; buf[i] = (opus_int16)s; } /* Assign demixing matrix. */ st->demixing_matrix_size_in_bytes = mapping_matrix_get_size(channels, nb_input_streams); if (!st->demixing_matrix_size_in_bytes) { RESTORE_STACK; return OPUS_BAD_ARG; } mapping_matrix_init(get_demixing_matrix(st), channels, nb_input_streams, 0, buf, demixing_matrix_size); /* Set trivial mapping so each input channel pairs with a matrix column. */ for (i = 0; i < channels; i++) mapping[i] = i; ret = opus_multistream_decoder_init( get_multistream_decoder(st), Fs, channels, streams, coupled_streams, mapping); RESTORE_STACK; return ret; }