OLD | NEW |
1 /* Copyright (c) 2011 Xiph.Org Foundation | 1 /* Copyright (c) 2011 Xiph.Org Foundation |
2 Written by Jean-Marc Valin */ | 2 Written by Jean-Marc Valin */ |
3 /* | 3 /* |
4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
6 are met: | 6 are met: |
7 | 7 |
8 - Redistributions of source code must retain the above copyright | 8 - Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 int frame_size | 69 int frame_size |
70 ); | 70 ); |
71 | 71 |
72 struct OpusMSEncoder { | 72 struct OpusMSEncoder { |
73 ChannelLayout layout; | 73 ChannelLayout layout; |
74 int lfe_stream; | 74 int lfe_stream; |
75 int application; | 75 int application; |
76 int variable_duration; | 76 int variable_duration; |
77 int surround; | 77 int surround; |
78 opus_int32 bitrate_bps; | 78 opus_int32 bitrate_bps; |
79 opus_val32 subframe_mem[3]; | 79 float subframe_mem[3]; |
80 /* Encoder states go here */ | 80 /* Encoder states go here */ |
81 /* then opus_val32 window_mem[channels*120]; */ | 81 /* then opus_val32 window_mem[channels*120]; */ |
82 /* then opus_val32 preemph_mem[channels]; */ | 82 /* then opus_val32 preemph_mem[channels]; */ |
83 }; | 83 }; |
84 | 84 |
85 static opus_val32 *ms_get_preemph_mem(OpusMSEncoder *st) | 85 static opus_val32 *ms_get_preemph_mem(OpusMSEncoder *st) |
86 { | 86 { |
87 int s; | 87 int s; |
88 char *ptr; | 88 char *ptr; |
89 int coupled_size, mono_size; | 89 int coupled_size, mono_size; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } else { | 198 } else { |
199 max = b; | 199 max = b; |
200 diff = SUB32(EXTEND32(b),EXTEND32(a)); | 200 diff = SUB32(EXTEND32(b),EXTEND32(a)); |
201 } | 201 } |
202 if (diff >= QCONST16(8.f, DB_SHIFT)) | 202 if (diff >= QCONST16(8.f, DB_SHIFT)) |
203 return max; | 203 return max; |
204 #ifdef FIXED_POINT | 204 #ifdef FIXED_POINT |
205 low = SHR32(diff, DB_SHIFT-1); | 205 low = SHR32(diff, DB_SHIFT-1); |
206 frac = SHL16(diff - SHL16(low, DB_SHIFT-1), 16-DB_SHIFT); | 206 frac = SHL16(diff - SHL16(low, DB_SHIFT-1), 16-DB_SHIFT); |
207 #else | 207 #else |
208 low = floor(2*diff); | 208 low = (int)floor(2*diff); |
209 frac = 2*diff - low; | 209 frac = 2*diff - low; |
210 #endif | 210 #endif |
211 return max + diff_table[low] + MULT16_16_Q15(frac, SUB16(diff_table[low+1], d
iff_table[low])); | 211 return max + diff_table[low] + MULT16_16_Q15(frac, SUB16(diff_table[low+1], d
iff_table[low])); |
212 } | 212 } |
213 #else | 213 #else |
214 opus_val16 logSum(opus_val16 a, opus_val16 b) | 214 opus_val16 logSum(opus_val16 a, opus_val16 b) |
215 { | 215 { |
216 return log2(pow(4, a)+ pow(4, b))/2; | 216 return log2(pow(4, a)+ pow(4, b))/2; |
217 } | 217 } |
218 #endif | 218 #endif |
(...skipping 12 matching lines...) Expand all Loading... |
231 opus_val32 bandE[21]; | 231 opus_val32 bandE[21]; |
232 opus_val16 maskLogE[3][21]; | 232 opus_val16 maskLogE[3][21]; |
233 VARDECL(opus_val32, in); | 233 VARDECL(opus_val32, in); |
234 VARDECL(opus_val16, x); | 234 VARDECL(opus_val16, x); |
235 VARDECL(opus_val32, freq); | 235 VARDECL(opus_val32, freq); |
236 SAVE_STACK; | 236 SAVE_STACK; |
237 | 237 |
238 upsample = resampling_factor(rate); | 238 upsample = resampling_factor(rate); |
239 frame_size = len*upsample; | 239 frame_size = len*upsample; |
240 | 240 |
241 for (LM=0;LM<=celt_mode->maxLM;LM++) | 241 for (LM=0;LM<celt_mode->maxLM;LM++) |
242 if (celt_mode->shortMdctSize<<LM==frame_size) | 242 if (celt_mode->shortMdctSize<<LM==frame_size) |
243 break; | 243 break; |
244 | 244 |
245 ALLOC(in, frame_size+overlap, opus_val32); | 245 ALLOC(in, frame_size+overlap, opus_val32); |
246 ALLOC(x, len, opus_val16); | 246 ALLOC(x, len, opus_val16); |
247 ALLOC(freq, frame_size, opus_val32); | 247 ALLOC(freq, frame_size, opus_val32); |
248 | 248 |
249 channel_pos(channels, pos); | 249 channel_pos(channels, pos); |
250 | 250 |
251 for (c=0;c<3;c++) | 251 for (c=0;c<3;c++) |
252 for (i=0;i<21;i++) | 252 for (i=0;i<21;i++) |
253 maskLogE[c][i] = -QCONST16(28.f, DB_SHIFT); | 253 maskLogE[c][i] = -QCONST16(28.f, DB_SHIFT); |
254 | 254 |
255 for (c=0;c<channels;c++) | 255 for (c=0;c<channels;c++) |
256 { | 256 { |
257 OPUS_COPY(in, mem+c*overlap, overlap); | 257 OPUS_COPY(in, mem+c*overlap, overlap); |
258 (*copy_channel_in)(x, 1, pcm, channels, c, len); | 258 (*copy_channel_in)(x, 1, pcm, channels, c, len); |
259 preemphasis(x, in+overlap, frame_size, 1, upsample, celt_mode->preemph, pr
eemph_mem+c, 0); | 259 celt_preemphasis(x, in+overlap, frame_size, 1, upsample, celt_mode->preemp
h, preemph_mem+c, 0); |
260 clt_mdct_forward(&celt_mode->mdct, in, freq, celt_mode->window, overlap, c
elt_mode->maxLM-LM, 1); | 260 clt_mdct_forward(&celt_mode->mdct, in, freq, celt_mode->window, overlap, c
elt_mode->maxLM-LM, 1); |
261 if (upsample != 1) | 261 if (upsample != 1) |
262 { | 262 { |
263 int bound = len; | 263 int bound = len; |
264 for (i=0;i<bound;i++) | 264 for (i=0;i<bound;i++) |
265 freq[i] *= upsample; | 265 freq[i] *= upsample; |
266 for (;i<frame_size;i++) | 266 for (;i<frame_size;i++) |
267 freq[i] = 0; | 267 freq[i] = 0; |
268 } | 268 } |
269 | 269 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 int coupled_ratio; /* Q8 */ | 606 int coupled_ratio; /* Q8 */ |
607 int lfe_ratio; /* Q8 */ | 607 int lfe_ratio; /* Q8 */ |
608 | 608 |
609 ptr = (char*)st + align(sizeof(OpusMSEncoder)); | 609 ptr = (char*)st + align(sizeof(OpusMSEncoder)); |
610 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_SAMPLE_RATE(&Fs)); | 610 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_SAMPLE_RATE(&Fs)); |
611 | 611 |
612 if (st->bitrate_bps > st->layout.nb_channels*40000) | 612 if (st->bitrate_bps > st->layout.nb_channels*40000) |
613 stream_offset = 20000; | 613 stream_offset = 20000; |
614 else | 614 else |
615 stream_offset = st->bitrate_bps/st->layout.nb_channels/2; | 615 stream_offset = st->bitrate_bps/st->layout.nb_channels/2; |
| 616 stream_offset += 60*(Fs/frame_size-50); |
616 /* We start by giving each stream (coupled or uncoupled) the same bitrate. | 617 /* We start by giving each stream (coupled or uncoupled) the same bitrate. |
617 This models the main saving of coupled channels over uncoupled. */ | 618 This models the main saving of coupled channels over uncoupled. */ |
618 /* The LFE stream is an exception to the above and gets fewer bits. */ | 619 /* The LFE stream is an exception to the above and gets fewer bits. */ |
619 lfe_offset = 3500; | 620 lfe_offset = 3500 + 60*(Fs/frame_size-50); |
620 /* Coupled streams get twice the mono rate after the first 20 kb/s. */ | 621 /* Coupled streams get twice the mono rate after the first 20 kb/s. */ |
621 coupled_ratio = 512; | 622 coupled_ratio = 512; |
622 /* Should depend on the bitrate, for now we assume LFE gets 1/8 the bits of m
ono */ | 623 /* Should depend on the bitrate, for now we assume LFE gets 1/8 the bits of m
ono */ |
623 lfe_ratio = 32; | 624 lfe_ratio = 32; |
624 | 625 |
625 /* Compute bitrate allocation between streams */ | 626 /* Compute bitrate allocation between streams */ |
626 if (st->bitrate_bps==OPUS_AUTO) | 627 if (st->bitrate_bps==OPUS_AUTO) |
627 { | 628 { |
628 channel_rate = Fs+60*Fs/frame_size; | 629 channel_rate = Fs+60*Fs/frame_size; |
629 } else if (st->bitrate_bps==OPUS_BITRATE_MAX) | 630 } else if (st->bitrate_bps==OPUS_BITRATE_MAX) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 opus_int32 Fs; | 680 opus_int32 Fs; |
680 int coupled_size; | 681 int coupled_size; |
681 int mono_size; | 682 int mono_size; |
682 int s; | 683 int s; |
683 char *ptr; | 684 char *ptr; |
684 int tot_size; | 685 int tot_size; |
685 VARDECL(opus_val16, buf); | 686 VARDECL(opus_val16, buf); |
686 VARDECL(opus_val16, bandSMR); | 687 VARDECL(opus_val16, bandSMR); |
687 unsigned char tmp_data[MS_FRAME_TMP]; | 688 unsigned char tmp_data[MS_FRAME_TMP]; |
688 OpusRepacketizer rp; | 689 OpusRepacketizer rp; |
689 opus_int32 complexity; | 690 opus_int32 vbr; |
690 const CELTMode *celt_mode; | 691 const CELTMode *celt_mode; |
691 opus_int32 bitrates[256]; | 692 opus_int32 bitrates[256]; |
692 opus_val16 bandLogE[42]; | 693 opus_val16 bandLogE[42]; |
693 opus_val32 *mem = NULL; | 694 opus_val32 *mem = NULL; |
694 opus_val32 *preemph_mem=NULL; | 695 opus_val32 *preemph_mem=NULL; |
695 int frame_size; | 696 int frame_size; |
696 ALLOC_STACK; | 697 ALLOC_STACK; |
697 | 698 |
698 if (st->surround) | 699 if (st->surround) |
699 { | 700 { |
700 preemph_mem = ms_get_preemph_mem(st); | 701 preemph_mem = ms_get_preemph_mem(st); |
701 mem = ms_get_window_mem(st); | 702 mem = ms_get_window_mem(st); |
702 } | 703 } |
703 | 704 |
704 ptr = (char*)st + align(sizeof(OpusMSEncoder)); | 705 ptr = (char*)st + align(sizeof(OpusMSEncoder)); |
705 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_SAMPLE_RATE(&Fs)); | 706 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_SAMPLE_RATE(&Fs)); |
706 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_COMPLEXITY(&complexity)); | 707 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_VBR(&vbr)); |
707 opus_encoder_ctl((OpusEncoder*)ptr, CELT_GET_MODE(&celt_mode)); | 708 opus_encoder_ctl((OpusEncoder*)ptr, CELT_GET_MODE(&celt_mode)); |
708 | 709 |
709 { | 710 { |
710 opus_int32 delay_compensation; | 711 opus_int32 delay_compensation; |
711 int channels; | 712 int channels; |
712 | 713 |
713 channels = st->layout.nb_streams + st->layout.nb_coupled_streams; | 714 channels = st->layout.nb_streams + st->layout.nb_coupled_streams; |
714 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_LOOKAHEAD(&delay_compensation
)); | 715 opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_LOOKAHEAD(&delay_compensation
)); |
715 delay_compensation -= Fs/400; | 716 delay_compensation -= Fs/400; |
716 frame_size = compute_frame_size(pcm, analysis_frame_size, | 717 frame_size = compute_frame_size(pcm, analysis_frame_size, |
717 st->variable_duration, channels, Fs, st->bitrate_bps, | 718 st->variable_duration, channels, Fs, st->bitrate_bps, |
718 delay_compensation, downmix, st->subframe_mem); | 719 delay_compensation, downmix |
| 720 #ifndef DISABLE_FLOAT_API |
| 721 , st->subframe_mem |
| 722 #endif |
| 723 ); |
719 } | 724 } |
720 | 725 |
721 if (400*frame_size < Fs) | 726 if (400*frame_size < Fs) |
722 { | 727 { |
723 RESTORE_STACK; | 728 RESTORE_STACK; |
724 return OPUS_BAD_ARG; | 729 return OPUS_BAD_ARG; |
725 } | 730 } |
726 /* Validate frame_size before using it to allocate stack space. | 731 /* Validate frame_size before using it to allocate stack space. |
727 This mirrors the checks in opus_encode[_float](). */ | 732 This mirrors the checks in opus_encode[_float](). */ |
728 if (400*frame_size != Fs && 200*frame_size != Fs && | 733 if (400*frame_size != Fs && 200*frame_size != Fs && |
(...skipping 15 matching lines...) Expand all Loading... |
744 | 749 |
745 if (max_data_bytes < 4*st->layout.nb_streams-1) | 750 if (max_data_bytes < 4*st->layout.nb_streams-1) |
746 { | 751 { |
747 RESTORE_STACK; | 752 RESTORE_STACK; |
748 return OPUS_BUFFER_TOO_SMALL; | 753 return OPUS_BUFFER_TOO_SMALL; |
749 } | 754 } |
750 | 755 |
751 /* Compute bitrate allocation between streams (this could be a lot better) */ | 756 /* Compute bitrate allocation between streams (this could be a lot better) */ |
752 surround_rate_allocation(st, bitrates, frame_size); | 757 surround_rate_allocation(st, bitrates, frame_size); |
753 | 758 |
| 759 if (!vbr) |
| 760 max_data_bytes = IMIN(max_data_bytes, 3*st->bitrate_bps/(3*8*Fs/frame_size
)); |
| 761 |
754 ptr = (char*)st + align(sizeof(OpusMSEncoder)); | 762 ptr = (char*)st + align(sizeof(OpusMSEncoder)); |
755 for (s=0;s<st->layout.nb_streams;s++) | 763 for (s=0;s<st->layout.nb_streams;s++) |
756 { | 764 { |
757 OpusEncoder *enc; | 765 OpusEncoder *enc; |
758 enc = (OpusEncoder*)ptr; | 766 enc = (OpusEncoder*)ptr; |
759 if (s < st->layout.nb_coupled_streams) | 767 if (s < st->layout.nb_coupled_streams) |
760 ptr += align(coupled_size); | 768 ptr += align(coupled_size); |
761 else | 769 else |
762 ptr += align(mono_size); | 770 ptr += align(mono_size); |
763 opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrates[s])); | 771 opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrates[s])); |
764 if (st->surround) | 772 if (st->surround) |
765 { | 773 { |
766 opus_int32 equiv_rate; | 774 opus_int32 equiv_rate; |
767 equiv_rate = st->bitrate_bps; | 775 equiv_rate = st->bitrate_bps; |
768 if (frame_size*50 < Fs) | 776 if (frame_size*50 < Fs) |
769 equiv_rate -= 60*(Fs/frame_size - 50)*st->layout.nb_channels; | 777 equiv_rate -= 60*(Fs/frame_size - 50)*st->layout.nb_channels; |
770 if (equiv_rate > 112000) | 778 if (equiv_rate > 10000*st->layout.nb_channels) |
771 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); | 779 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); |
772 else if (equiv_rate > 76000) | 780 else if (equiv_rate > 7000*st->layout.nb_channels) |
773 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_SUPERWIDEBAN
D)); | 781 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_SUPERWIDEBAN
D)); |
774 else if (equiv_rate > 48000) | 782 else if (equiv_rate > 5000*st->layout.nb_channels) |
775 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_WIDEBAND)); | 783 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_WIDEBAND)); |
776 else | 784 else |
777 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND))
; | 785 opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND))
; |
778 if (s < st->layout.nb_coupled_streams) | 786 if (s < st->layout.nb_coupled_streams) |
779 { | 787 { |
780 /* To preserve the spatial image, force stereo CELT on coupled strea
ms */ | 788 /* To preserve the spatial image, force stereo CELT on coupled strea
ms */ |
781 opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_CELT_ONLY)); | 789 opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_CELT_ONLY)); |
782 opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(2)); | 790 opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(2)); |
783 } | 791 } |
784 } | 792 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 c1 = chan; | 839 c1 = chan; |
832 c2 = -1; | 840 c2 = -1; |
833 } | 841 } |
834 if (st->surround) | 842 if (st->surround) |
835 opus_encoder_ctl(enc, OPUS_SET_ENERGY_MASK(bandLogE)); | 843 opus_encoder_ctl(enc, OPUS_SET_ENERGY_MASK(bandLogE)); |
836 /* number of bytes left (+Toc) */ | 844 /* number of bytes left (+Toc) */ |
837 curr_max = max_data_bytes - tot_size; | 845 curr_max = max_data_bytes - tot_size; |
838 /* Reserve three bytes for the last stream and four for the others */ | 846 /* Reserve three bytes for the last stream and four for the others */ |
839 curr_max -= IMAX(0,4*(st->layout.nb_streams-s-1)-1); | 847 curr_max -= IMAX(0,4*(st->layout.nb_streams-s-1)-1); |
840 curr_max = IMIN(curr_max,MS_FRAME_TMP); | 848 curr_max = IMIN(curr_max,MS_FRAME_TMP); |
| 849 if (!vbr && s == st->layout.nb_streams-1) |
| 850 opus_encoder_ctl(enc, OPUS_SET_BITRATE(curr_max*(8*Fs/frame_size))); |
841 len = opus_encode_native(enc, buf, frame_size, tmp_data, curr_max, lsb_dep
th, | 851 len = opus_encode_native(enc, buf, frame_size, tmp_data, curr_max, lsb_dep
th, |
842 pcm, analysis_frame_size, c1, c2, st->layout.nb_channels, downmix); | 852 pcm, analysis_frame_size, c1, c2, st->layout.nb_channels, downmix); |
843 if (len<0) | 853 if (len<0) |
844 { | 854 { |
845 RESTORE_STACK; | 855 RESTORE_STACK; |
846 return len; | 856 return len; |
847 } | 857 } |
848 /* We need to use the repacketizer to add the self-delimiting lengths | 858 /* We need to use the repacketizer to add the self-delimiting lengths |
849 while taking into account the fact that the encoder can now return | 859 while taking into account the fact that the encoder can now return |
850 more than one frame at a time (e.g. 60 ms CELT-only) */ | 860 more than one frame at a time (e.g. 60 ms CELT-only) */ |
851 opus_repacketizer_cat(&rp, tmp_data, len); | 861 opus_repacketizer_cat(&rp, tmp_data, len); |
852 len = opus_repacketizer_out_range_impl(&rp, 0, opus_repacketizer_get_nb_fr
ames(&rp), data, max_data_bytes-tot_size, s != st->layout.nb_streams-1); | 862 len = opus_repacketizer_out_range_impl(&rp, 0, opus_repacketizer_get_nb_fr
ames(&rp), |
| 863 data, max_data_bytes-tot_size, s != st->layout.nb_streams-1, !vbr &&
s == st->layout.nb_streams-1); |
853 data += len; | 864 data += len; |
854 tot_size += len; | 865 tot_size += len; |
855 } | 866 } |
856 /*printf("\n");*/ | 867 /*printf("\n");*/ |
857 RESTORE_STACK; | 868 RESTORE_STACK; |
858 return tot_size; | 869 return tot_size; |
859 | |
860 } | 870 } |
861 | 871 |
862 #if !defined(DISABLE_FLOAT_API) | 872 #if !defined(DISABLE_FLOAT_API) |
863 static void opus_copy_channel_in_float( | 873 static void opus_copy_channel_in_float( |
864 opus_val16 *dst, | 874 opus_val16 *dst, |
865 int dst_stride, | 875 int dst_stride, |
866 const void *src, | 876 const void *src, |
867 int src_stride, | 877 int src_stride, |
868 int src_channel, | 878 int src_channel, |
869 int frame_size | 879 int frame_size |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 case OPUS_GET_COMPLEXITY_REQUEST: | 1021 case OPUS_GET_COMPLEXITY_REQUEST: |
1012 case OPUS_GET_PACKET_LOSS_PERC_REQUEST: | 1022 case OPUS_GET_PACKET_LOSS_PERC_REQUEST: |
1013 case OPUS_GET_DTX_REQUEST: | 1023 case OPUS_GET_DTX_REQUEST: |
1014 case OPUS_GET_VOICE_RATIO_REQUEST: | 1024 case OPUS_GET_VOICE_RATIO_REQUEST: |
1015 case OPUS_GET_VBR_CONSTRAINT_REQUEST: | 1025 case OPUS_GET_VBR_CONSTRAINT_REQUEST: |
1016 case OPUS_GET_SIGNAL_REQUEST: | 1026 case OPUS_GET_SIGNAL_REQUEST: |
1017 case OPUS_GET_LOOKAHEAD_REQUEST: | 1027 case OPUS_GET_LOOKAHEAD_REQUEST: |
1018 case OPUS_GET_SAMPLE_RATE_REQUEST: | 1028 case OPUS_GET_SAMPLE_RATE_REQUEST: |
1019 case OPUS_GET_INBAND_FEC_REQUEST: | 1029 case OPUS_GET_INBAND_FEC_REQUEST: |
1020 case OPUS_GET_FORCE_CHANNELS_REQUEST: | 1030 case OPUS_GET_FORCE_CHANNELS_REQUEST: |
| 1031 case OPUS_GET_PREDICTION_DISABLED_REQUEST: |
1021 { | 1032 { |
1022 OpusEncoder *enc; | 1033 OpusEncoder *enc; |
1023 /* For int32* GET params, just query the first stream */ | 1034 /* For int32* GET params, just query the first stream */ |
1024 opus_int32 *value = va_arg(ap, opus_int32*); | 1035 opus_int32 *value = va_arg(ap, opus_int32*); |
1025 enc = (OpusEncoder*)ptr; | 1036 enc = (OpusEncoder*)ptr; |
1026 ret = opus_encoder_ctl(enc, request, value); | 1037 ret = opus_encoder_ctl(enc, request, value); |
1027 } | 1038 } |
1028 break; | 1039 break; |
1029 case OPUS_GET_FINAL_RANGE_REQUEST: | 1040 case OPUS_GET_FINAL_RANGE_REQUEST: |
1030 { | 1041 { |
(...skipping 25 matching lines...) Expand all Loading... |
1056 case OPUS_SET_VBR_CONSTRAINT_REQUEST: | 1067 case OPUS_SET_VBR_CONSTRAINT_REQUEST: |
1057 case OPUS_SET_MAX_BANDWIDTH_REQUEST: | 1068 case OPUS_SET_MAX_BANDWIDTH_REQUEST: |
1058 case OPUS_SET_BANDWIDTH_REQUEST: | 1069 case OPUS_SET_BANDWIDTH_REQUEST: |
1059 case OPUS_SET_SIGNAL_REQUEST: | 1070 case OPUS_SET_SIGNAL_REQUEST: |
1060 case OPUS_SET_APPLICATION_REQUEST: | 1071 case OPUS_SET_APPLICATION_REQUEST: |
1061 case OPUS_SET_INBAND_FEC_REQUEST: | 1072 case OPUS_SET_INBAND_FEC_REQUEST: |
1062 case OPUS_SET_PACKET_LOSS_PERC_REQUEST: | 1073 case OPUS_SET_PACKET_LOSS_PERC_REQUEST: |
1063 case OPUS_SET_DTX_REQUEST: | 1074 case OPUS_SET_DTX_REQUEST: |
1064 case OPUS_SET_FORCE_MODE_REQUEST: | 1075 case OPUS_SET_FORCE_MODE_REQUEST: |
1065 case OPUS_SET_FORCE_CHANNELS_REQUEST: | 1076 case OPUS_SET_FORCE_CHANNELS_REQUEST: |
| 1077 case OPUS_SET_PREDICTION_DISABLED_REQUEST: |
1066 { | 1078 { |
1067 int s; | 1079 int s; |
1068 /* This works for int32 params */ | 1080 /* This works for int32 params */ |
1069 opus_int32 value = va_arg(ap, opus_int32); | 1081 opus_int32 value = va_arg(ap, opus_int32); |
1070 for (s=0;s<st->layout.nb_streams;s++) | 1082 for (s=0;s<st->layout.nb_streams;s++) |
1071 { | 1083 { |
1072 OpusEncoder *enc; | 1084 OpusEncoder *enc; |
1073 | 1085 |
1074 enc = (OpusEncoder*)ptr; | 1086 enc = (OpusEncoder*)ptr; |
1075 if (s < st->layout.nb_coupled_streams) | 1087 if (s < st->layout.nb_coupled_streams) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 case OPUS_GET_EXPERT_FRAME_DURATION_REQUEST: | 1126 case OPUS_GET_EXPERT_FRAME_DURATION_REQUEST: |
1115 { | 1127 { |
1116 opus_int32 *value = va_arg(ap, opus_int32*); | 1128 opus_int32 *value = va_arg(ap, opus_int32*); |
1117 if (!value) | 1129 if (!value) |
1118 { | 1130 { |
1119 goto bad_arg; | 1131 goto bad_arg; |
1120 } | 1132 } |
1121 *value = st->variable_duration; | 1133 *value = st->variable_duration; |
1122 } | 1134 } |
1123 break; | 1135 break; |
| 1136 case OPUS_RESET_STATE: |
| 1137 { |
| 1138 int s; |
| 1139 st->subframe_mem[0] = st->subframe_mem[1] = st->subframe_mem[2] = 0; |
| 1140 if (st->surround) |
| 1141 { |
| 1142 OPUS_CLEAR(ms_get_preemph_mem(st), st->layout.nb_channels); |
| 1143 OPUS_CLEAR(ms_get_window_mem(st), st->layout.nb_channels*120); |
| 1144 } |
| 1145 for (s=0;s<st->layout.nb_streams;s++) |
| 1146 { |
| 1147 OpusEncoder *enc; |
| 1148 enc = (OpusEncoder*)ptr; |
| 1149 if (s < st->layout.nb_coupled_streams) |
| 1150 ptr += align(coupled_size); |
| 1151 else |
| 1152 ptr += align(mono_size); |
| 1153 ret = opus_encoder_ctl(enc, OPUS_RESET_STATE); |
| 1154 if (ret != OPUS_OK) |
| 1155 break; |
| 1156 } |
| 1157 } |
| 1158 break; |
1124 default: | 1159 default: |
1125 ret = OPUS_UNIMPLEMENTED; | 1160 ret = OPUS_UNIMPLEMENTED; |
1126 break; | 1161 break; |
1127 } | 1162 } |
1128 | 1163 |
1129 va_end(ap); | 1164 va_end(ap); |
1130 return ret; | 1165 return ret; |
1131 bad_arg: | 1166 bad_arg: |
1132 va_end(ap); | 1167 va_end(ap); |
1133 return OPUS_BAD_ARG; | 1168 return OPUS_BAD_ARG; |
1134 } | 1169 } |
1135 | 1170 |
1136 void opus_multistream_encoder_destroy(OpusMSEncoder *st) | 1171 void opus_multistream_encoder_destroy(OpusMSEncoder *st) |
1137 { | 1172 { |
1138 opus_free(st); | 1173 opus_free(st); |
1139 } | 1174 } |
OLD | NEW |