diff options
Diffstat (limited to 'apps/codecs/libspeex/nb_celp.c')
-rw-r--r-- | apps/codecs/libspeex/nb_celp.c | 79 |
1 files changed, 29 insertions, 50 deletions
diff --git a/apps/codecs/libspeex/nb_celp.c b/apps/codecs/libspeex/nb_celp.c index 84cf1bb6d7..d29b9ae540 100644 --- a/apps/codecs/libspeex/nb_celp.c +++ b/apps/codecs/libspeex/nb_celp.c | |||
@@ -293,8 +293,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
293 | ALLOC(interp_qlpc, st->lpcSize, spx_coef_t); | 293 | ALLOC(interp_qlpc, st->lpcSize, spx_coef_t); |
294 | 294 | ||
295 | /* Move signals 1 frame towards the past */ | 295 | /* Move signals 1 frame towards the past */ |
296 | speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t)); | 296 | SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, st->max_pitch+2); |
297 | speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t)); | 297 | SPEEX_MOVE(st->swBuf, st->swBuf+st->frameSize, st->max_pitch+2); |
298 | 298 | ||
299 | if (st->highpass_enabled) | 299 | if (st->highpass_enabled) |
300 | highpass(in, in, st->frameSize, (st->isWideband?HIGHPASS_WIDEBAND:HIGHPASS_NARROWBAND)|HIGHPASS_INPUT, st->mem_hp); | 300 | highpass(in, in, st->frameSize, (st->isWideband?HIGHPASS_WIDEBAND:HIGHPASS_NARROWBAND)|HIGHPASS_INPUT, st->mem_hp); |
@@ -337,6 +337,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
337 | 337 | ||
338 | /* Whole frame analysis (open-loop estimation of pitch and excitation gain) */ | 338 | /* Whole frame analysis (open-loop estimation of pitch and excitation gain) */ |
339 | { | 339 | { |
340 | int diff = st->windowSize-st->frameSize; | ||
340 | if (st->first) | 341 | if (st->first) |
341 | for (i=0;i<st->lpcSize;i++) | 342 | for (i=0;i<st->lpcSize;i++) |
342 | interp_lsp[i] = lsp[i]; | 343 | interp_lsp[i] = lsp[i]; |
@@ -361,11 +362,9 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
361 | 362 | ||
362 | bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize); | 363 | bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize); |
363 | bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize); | 364 | bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize); |
364 | 365 | ||
365 | for (i=0;i<st->windowSize-st->frameSize;i++) | 366 | SPEEX_COPY(st->sw, st->winBuf, diff); |
366 | st->sw[i] = st->winBuf[i]; | 367 | SPEEX_COPY(st->sw+diff, in, st->frameSize-diff); |
367 | for (;i<st->frameSize;i++) | ||
368 | st->sw[i] = in[i-st->windowSize+st->frameSize]; | ||
369 | filter_mem16(st->sw, bw_lpc1, bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole, stack); | 368 | filter_mem16(st->sw, bw_lpc1, bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole, stack); |
370 | 369 | ||
371 | open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize, | 370 | open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize, |
@@ -397,10 +396,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
397 | } | 396 | } |
398 | 397 | ||
399 | /*Compute "real" excitation*/ | 398 | /*Compute "real" excitation*/ |
400 | for (i=0;i<st->windowSize-st->frameSize;i++) | 399 | SPEEX_COPY(st->exc, st->winBuf, diff); |
401 | st->exc[i] = st->winBuf[i]; | 400 | SPEEX_COPY(st->exc+diff, in, st->frameSize-diff); |
402 | for (;i<st->frameSize;i++) | ||
403 | st->exc[i] = in[i-st->windowSize+st->frameSize]; | ||
404 | fir_mem16(st->exc, interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc, stack); | 401 | fir_mem16(st->exc, interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc, stack); |
405 | 402 | ||
406 | /* Compute open-loop excitation gain */ | 403 | /* Compute open-loop excitation gain */ |
@@ -415,15 +412,12 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
415 | } | 412 | } |
416 | 413 | ||
417 | #ifdef VORBIS_PSYCHO | 414 | #ifdef VORBIS_PSYCHO |
418 | for(i=0;i<256-st->frameSize;i++) | 415 | SPEEX_MOVE(st->psy_window, st->psy_window+st->frameSize, 256-st->frameSize); |
419 | st->psy_window[i] = st->psy_window[i+st->frameSize]; | 416 | SPEEX_COPY(&st->psy_window[256-st->frameSize], in, st->frameSize); |
420 | for(i=0;i<st->frameSize;i++) | ||
421 | st->psy_window[256-st->frameSize+i] = in[i]; | ||
422 | compute_curve(st->psy, st->psy_window, st->curve); | 417 | compute_curve(st->psy, st->psy_window, st->curve); |
423 | /*print_vec(st->curve, 128, "curve");*/ | 418 | /*print_vec(st->curve, 128, "curve");*/ |
424 | if (st->first) | 419 | if (st->first) |
425 | for (i=0;i<128;i++) | 420 | SPEEX_COPY(st->old_curve, st->curve, 128); |
426 | st->old_curve[i] = st->curve[i]; | ||
427 | #endif | 421 | #endif |
428 | 422 | ||
429 | /*VBR stuff*/ | 423 | /*VBR stuff*/ |
@@ -562,7 +556,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
562 | st->first=1; | 556 | st->first=1; |
563 | st->bounded_pitch = 1; | 557 | st->bounded_pitch = 1; |
564 | 558 | ||
565 | speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t)); | 559 | SPEEX_COPY(st->winBuf, in+2*st->frameSize-st->windowSize, st->windowSize-st->frameSize); |
566 | 560 | ||
567 | /* Clear memory (no need to really compute it) */ | 561 | /* Clear memory (no need to really compute it) */ |
568 | for (i=0;i<st->lpcSize;i++) | 562 | for (i=0;i<st->lpcSize;i++) |
@@ -739,8 +733,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
739 | for (i=0;i<st->lpcSize;i++) | 733 | for (i=0;i<st->lpcSize;i++) |
740 | mem[i]=SHL32(st->mem_sw[i],1); | 734 | mem[i]=SHL32(st->mem_sw[i],1); |
741 | filter_mem16(ringing, st->bw_lpc1, st->bw_lpc2, ringing, response_bound, st->lpcSize, mem, stack); | 735 | filter_mem16(ringing, st->bw_lpc1, st->bw_lpc2, ringing, response_bound, st->lpcSize, mem, stack); |
742 | for (i=response_bound;i<st->subframeSize;i++) | 736 | SPEEX_MEMSET(&ringing[response_bound], 0, st->subframeSize-response_bound); |
743 | ringing[i]=0; | ||
744 | #else | 737 | #else |
745 | iir_mem16(ringing, interp_qlpc, ringing, st->subframeSize, st->lpcSize, mem, stack); | 738 | iir_mem16(ringing, interp_qlpc, ringing, st->subframeSize, st->lpcSize, mem, stack); |
746 | for (i=0;i<st->lpcSize;i++) | 739 | for (i=0;i<st->lpcSize;i++) |
@@ -762,8 +755,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
762 | target[i]=EXTRACT16(SATURATE(SUB32(sw[i],PSHR32(ringing[i],1)),32767)); | 755 | target[i]=EXTRACT16(SATURATE(SUB32(sw[i],PSHR32(ringing[i],1)),32767)); |
763 | 756 | ||
764 | /* Reset excitation */ | 757 | /* Reset excitation */ |
765 | for (i=0;i<st->subframeSize;i++) | 758 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
766 | exc[i]=0; | ||
767 | 759 | ||
768 | /* If we have a long-term predictor (otherwise, something's wrong) */ | 760 | /* If we have a long-term predictor (otherwise, something's wrong) */ |
769 | speex_assert (SUBMODE(ltp_quant)); | 761 | speex_assert (SUBMODE(ltp_quant)); |
@@ -804,8 +796,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
804 | st->pitch[sub]=pitch; | 796 | st->pitch[sub]=pitch; |
805 | } | 797 | } |
806 | /* Quantization of innovation */ | 798 | /* Quantization of innovation */ |
807 | for (i=0;i<st->subframeSize;i++) | 799 | SPEEX_MEMSET(innov, 0, st->subframeSize); |
808 | innov[i]=0; | ||
809 | 800 | ||
810 | /* FIXME: Make sure this is save from overflows (so far so good) */ | 801 | /* FIXME: Make sure this is save from overflows (so far so good) */ |
811 | for (i=0;i<st->subframeSize;i++) | 802 | for (i=0;i<st->subframeSize;i++) |
@@ -867,8 +858,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
867 | char *tmp_stack=stack; | 858 | char *tmp_stack=stack; |
868 | VARDECL(spx_sig_t *innov2); | 859 | VARDECL(spx_sig_t *innov2); |
869 | ALLOC(innov2, st->subframeSize, spx_sig_t); | 860 | ALLOC(innov2, st->subframeSize, spx_sig_t); |
870 | for (i=0;i<st->subframeSize;i++) | 861 | SPEEX_MEMSET(innov2, 0, st->subframeSize); |
871 | innov2[i]=0; | ||
872 | for (i=0;i<st->subframeSize;i++) | 862 | for (i=0;i<st->subframeSize;i++) |
873 | target[i]=MULT16_16_P13(QCONST16(2.2f,13), target[i]); | 863 | target[i]=MULT16_16_P13(QCONST16(2.2f,13), target[i]); |
874 | SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2, | 864 | SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2, |
@@ -887,10 +877,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
887 | } | 877 | } |
888 | } | 878 | } |
889 | 879 | ||
890 | for (i=0;i<st->subframeSize;i++) | ||
891 | sw[i] = exc[i]; | ||
892 | /* Final signal synthesis from excitation */ | 880 | /* Final signal synthesis from excitation */ |
893 | iir_mem16(sw, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack); | 881 | iir_mem16(exc, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack); |
894 | 882 | ||
895 | /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */ | 883 | /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */ |
896 | if (st->complexity!=0) | 884 | if (st->complexity!=0) |
@@ -909,10 +897,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
909 | 897 | ||
910 | #ifdef VORBIS_PSYCHO | 898 | #ifdef VORBIS_PSYCHO |
911 | if (st->submodeID>=1) | 899 | if (st->submodeID>=1) |
912 | { | 900 | SPEEX_COPY(st->old_curve, st->curve, 128); |
913 | for (i=0;i<128;i++) | ||
914 | st->old_curve[i] = st->curve[i]; | ||
915 | } | ||
916 | #endif | 901 | #endif |
917 | 902 | ||
918 | if (st->submodeID==1) | 903 | if (st->submodeID==1) |
@@ -927,7 +912,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
927 | 912 | ||
928 | /* The next frame will not be the first (Duh!) */ | 913 | /* The next frame will not be the first (Duh!) */ |
929 | st->first = 0; | 914 | st->first = 0; |
930 | speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t)); | 915 | SPEEX_COPY(st->winBuf, in+2*st->frameSize-st->windowSize, st->windowSize-st->frameSize); |
931 | 916 | ||
932 | if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0) | 917 | if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0) |
933 | st->bounded_pitch = 1; | 918 | st->bounded_pitch = 1; |
@@ -980,8 +965,7 @@ void *nb_decoder_init(const SpeexMode *m) | |||
980 | 965 | ||
981 | /* st->excBuf = (spx_word16_t*)speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); */ | 966 | /* st->excBuf = (spx_word16_t*)speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); */ |
982 | st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; | 967 | st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; |
983 | for (i=0;i<st->frameSize + st->max_pitch + 1;i++) | 968 | SPEEX_MEMSET(st->excBuf, 0, st->frameSize + st->max_pitch); |
984 | st->excBuf[i]=0; | ||
985 | 969 | ||
986 | /* st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); */ | 970 | /* st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); */ |
987 | /* st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); */ | 971 | /* st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); */ |
@@ -1079,7 +1063,7 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) | |||
1079 | innov_gain = compute_rms16(st->exc, st->frameSize); | 1063 | innov_gain = compute_rms16(st->exc, st->frameSize); |
1080 | noise_gain = MULT16_16_Q15(innov_gain, MULT16_16_Q15(fact, SUB16(Q15ONE,MULT16_16_Q15(pitch_gain,pitch_gain)))); | 1064 | noise_gain = MULT16_16_Q15(innov_gain, MULT16_16_Q15(fact, SUB16(Q15ONE,MULT16_16_Q15(pitch_gain,pitch_gain)))); |
1081 | /* Shift all buffers by one frame */ | 1065 | /* Shift all buffers by one frame */ |
1082 | speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); | 1066 | SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, 2*st->max_pitch + st->subframeSize + 12); |
1083 | 1067 | ||
1084 | 1068 | ||
1085 | pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT); | 1069 | pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT); |
@@ -1094,8 +1078,8 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) | |||
1094 | } | 1078 | } |
1095 | 1079 | ||
1096 | bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize); | 1080 | bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize); |
1097 | iir_mem16(&st->exc[-st->subframeSize], st->interp_qlpc, out, | 1081 | iir_mem16(&st->exc[-st->subframeSize], st->interp_qlpc, out, st->frameSize, |
1098 | st->frameSize, st->lpcSize, st->mem_sp, stack); | 1082 | st->lpcSize, st->mem_sp, stack); |
1099 | highpass(out, out, st->frameSize, HIGHPASS_NARROWBAND|HIGHPASS_OUTPUT, st->mem_hp); | 1083 | highpass(out, out, st->frameSize, HIGHPASS_NARROWBAND|HIGHPASS_OUTPUT, st->mem_hp); |
1100 | 1084 | ||
1101 | st->first = 0; | 1085 | st->first = 0; |
@@ -1229,7 +1213,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1229 | } | 1213 | } |
1230 | 1214 | ||
1231 | /* Shift all buffers by one frame */ | 1215 | /* Shift all buffers by one frame */ |
1232 | speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); | 1216 | SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, 2*st->max_pitch + st->subframeSize + 12); |
1233 | 1217 | ||
1234 | /* If null mode (no transmission), just set a couple things to zero*/ | 1218 | /* If null mode (no transmission), just set a couple things to zero*/ |
1235 | if (st->submodes[st->submodeID] == NULL) | 1219 | if (st->submodes[st->submodeID] == NULL) |
@@ -1346,8 +1330,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1346 | 1330 | ||
1347 | 1331 | ||
1348 | /* Reset excitation */ | 1332 | /* Reset excitation */ |
1349 | for (i=0;i<st->subframeSize;i++) | 1333 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
1350 | exc[i]=0; | ||
1351 | 1334 | ||
1352 | /*Adaptive codebook contribution*/ | 1335 | /*Adaptive codebook contribution*/ |
1353 | speex_assert (SUBMODE(ltp_unquant)); | 1336 | speex_assert (SUBMODE(ltp_unquant)); |
@@ -1411,8 +1394,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1411 | int q_energy; | 1394 | int q_energy; |
1412 | spx_word32_t ener; | 1395 | spx_word32_t ener; |
1413 | 1396 | ||
1414 | for (i=0;i<st->subframeSize;i++) | 1397 | SPEEX_MEMSET(innov, 0, st->subframeSize); |
1415 | innov[i]=0; | ||
1416 | 1398 | ||
1417 | /* Decode sub-frame gain correction */ | 1399 | /* Decode sub-frame gain correction */ |
1418 | if (SUBMODE(have_subframe_gain)==3) | 1400 | if (SUBMODE(have_subframe_gain)==3) |
@@ -1441,8 +1423,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1441 | char *tmp_stack=stack; | 1423 | char *tmp_stack=stack; |
1442 | VARDECL(spx_sig_t *innov2); | 1424 | VARDECL(spx_sig_t *innov2); |
1443 | ALLOC(innov2, st->subframeSize, spx_sig_t); | 1425 | ALLOC(innov2, st->subframeSize, spx_sig_t); |
1444 | for (i=0;i<st->subframeSize;i++) | 1426 | SPEEX_MEMSET(innov2, 0, st->subframeSize); |
1445 | innov2[i]=0; | ||
1446 | SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); | 1427 | SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); |
1447 | signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); | 1428 | signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); |
1448 | for (i=0;i<st->subframeSize;i++) | 1429 | for (i=0;i<st->subframeSize;i++) |
@@ -1469,8 +1450,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1469 | if (g>GAIN_SCALING) | 1450 | if (g>GAIN_SCALING) |
1470 | g=GAIN_SCALING; | 1451 | g=GAIN_SCALING; |
1471 | 1452 | ||
1472 | for (i=0;i<st->subframeSize;i++) | 1453 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
1473 | exc[i]=0; | ||
1474 | while (st->voc_offset<st->subframeSize) | 1454 | while (st->voc_offset<st->subframeSize) |
1475 | { | 1455 | { |
1476 | /* exc[st->voc_offset]= g*sqrt(2*ol_pitch)*ol_gain; | 1456 | /* exc[st->voc_offset]= g*sqrt(2*ol_pitch)*ol_gain; |
@@ -1505,8 +1485,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1505 | multicomb(st->exc-st->subframeSize, out, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); | 1485 | multicomb(st->exc-st->subframeSize, out, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); |
1506 | multicomb(st->exc+st->subframeSize, out+2*st->subframeSize, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); | 1486 | multicomb(st->exc+st->subframeSize, out+2*st->subframeSize, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); |
1507 | } else { | 1487 | } else { |
1508 | for (i=0;i<st->frameSize;i++) | 1488 | SPEEX_COPY(out, &st->exc[-st->subframeSize], st->frameSize); |
1509 | out[i]=st->exc[i-st->subframeSize]; | ||
1510 | } | 1489 | } |
1511 | 1490 | ||
1512 | /* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */ | 1491 | /* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */ |