diff options
| author | Dirk Engling <erdgeist@bauklotz.fritz.box> | 2020-10-15 16:27:49 +0200 |
|---|---|---|
| committer | Dirk Engling <erdgeist@bauklotz.fritz.box> | 2020-10-15 16:27:49 +0200 |
| commit | 9022d768021bbe15c7815cc6f8b64218b46f0e10 (patch) | |
| tree | e60ed1ea72a21b3873684a5afae67b26a798f927 /sine.c | |
| parent | f02dfce6e6c34b3d8a7b8a0e784b506178e331fa (diff) | |
Diffstat (limited to 'sine.c')
| -rw-r--r-- | sine.c | 49 |
1 files changed, 18 insertions, 31 deletions
| @@ -97,11 +97,10 @@ C2CONST c2const_create(int Fs, float framelength_s) { | |||
| 97 | 97 | ||
| 98 | \*---------------------------------------------------------------------------*/ | 98 | \*---------------------------------------------------------------------------*/ |
| 99 | 99 | ||
| 100 | void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[], COMP W[]) | 100 | void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[], float W[]) |
| 101 | { | 101 | { |
| 102 | float m; | 102 | float m; |
| 103 | COMP wshift[FFT_ENC]; | 103 | COMP wshift[FFT_ENC]; |
| 104 | COMP temp; | ||
| 105 | int i,j; | 104 | int i,j; |
| 106 | int m_pitch = c2const->m_pitch; | 105 | int m_pitch = c2const->m_pitch; |
| 107 | int nw = c2const->nw; | 106 | int nw = c2const->nw; |
| @@ -156,6 +155,8 @@ void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[ | |||
| 156 | nw/2 nw/2 | 155 | nw/2 nw/2 |
| 157 | */ | 156 | */ |
| 158 | 157 | ||
| 158 | COMP temp[FFT_ENC]; | ||
| 159 | |||
| 159 | for(i=0; i<FFT_ENC; i++) { | 160 | for(i=0; i<FFT_ENC; i++) { |
| 160 | wshift[i].real = 0.0; | 161 | wshift[i].real = 0.0; |
| 161 | wshift[i].imag = 0.0; | 162 | wshift[i].imag = 0.0; |
| @@ -165,7 +166,7 @@ void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[ | |||
| 165 | for(i=FFT_ENC-nw/2,j=m_pitch/2-nw/2; i<FFT_ENC; i++,j++) | 166 | for(i=FFT_ENC-nw/2,j=m_pitch/2-nw/2; i<FFT_ENC; i++,j++) |
| 166 | wshift[i].real = w[j]; | 167 | wshift[i].real = w[j]; |
| 167 | 168 | ||
| 168 | codec2_fft(fft_fwd_cfg, wshift, W); | 169 | codec2_fft(fft_fwd_cfg, wshift, temp); |
| 169 | 170 | ||
| 170 | /* | 171 | /* |
| 171 | Re-arrange W[] to be symmetrical about FFT_ENC/2. Makes later | 172 | Re-arrange W[] to be symmetrical about FFT_ENC/2. Makes later |
| @@ -192,12 +193,8 @@ void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[ | |||
| 192 | 193 | ||
| 193 | 194 | ||
| 194 | for(i=0; i<FFT_ENC/2; i++) { | 195 | for(i=0; i<FFT_ENC/2; i++) { |
| 195 | temp.real = W[i].real; | 196 | W[i] = temp[i + FFT_ENC / 2].real; |
| 196 | temp.imag = W[i].imag; | 197 | W[i + FFT_ENC / 2] = temp[i].real; |
| 197 | W[i].real = W[i+FFT_ENC/2].real; | ||
| 198 | W[i].imag = W[i+FFT_ENC/2].imag; | ||
| 199 | W[i+FFT_ENC/2].real = temp.real; | ||
| 200 | W[i+FFT_ENC/2].imag = temp.imag; | ||
| 201 | } | 198 | } |
| 202 | 199 | ||
| 203 | } | 200 | } |
| @@ -402,39 +399,30 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float | |||
| 402 | 399 | ||
| 403 | \*---------------------------------------------------------------------------*/ | 400 | \*---------------------------------------------------------------------------*/ |
| 404 | 401 | ||
| 405 | void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase) | 402 | void estimate_amplitudes(MODEL *model, COMP Sw[], float W[], int est_phase) |
| 406 | { | 403 | { |
| 407 | int i,m; /* loop variables */ | 404 | int i,m; /* loop variables */ |
| 408 | int am,bm; /* bounds of current harmonic */ | 405 | int am,bm; /* bounds of current harmonic */ |
| 409 | int b; /* DFT bin of centre of current harmonic */ | ||
| 410 | float den; /* denominator of amplitude expression */ | 406 | float den; /* denominator of amplitude expression */ |
| 411 | float r, one_on_r; /* number of rads/bin */ | ||
| 412 | int offset; | ||
| 413 | COMP Am; | ||
| 414 | 407 | ||
| 415 | r = TWO_PI/FFT_ENC; | 408 | float r = TWO_PI/FFT_ENC; |
| 416 | one_on_r = 1.0/r; | 409 | float one_on_r = 1.0/r; |
| 417 | 410 | ||
| 418 | for(m=1; m<=model->L; m++) { | 411 | for(m=1; m<=model->L; m++) { |
| 412 | /* Estimate ampltude of harmonic */ | ||
| 413 | |||
| 419 | den = 0.0; | 414 | den = 0.0; |
| 420 | am = (int)((m - 0.5)*model->Wo*one_on_r + 0.5); | 415 | am = (int)((m - 0.5)*model->Wo*one_on_r + 0.5); |
| 421 | bm = (int)((m + 0.5)*model->Wo*one_on_r + 0.5); | 416 | bm = (int)((m + 0.5)*model->Wo*one_on_r + 0.5); |
| 422 | b = (int)(m*model->Wo/r + 0.5); | ||
| 423 | |||
| 424 | /* Estimate ampltude of harmonic */ | ||
| 425 | 417 | ||
| 426 | den = 0.0; | ||
| 427 | Am.real = Am.imag = 0.0; | ||
| 428 | offset = FFT_ENC/2 - (int)(m*model->Wo*one_on_r + 0.5); | ||
| 429 | for(i=am; i<bm; i++) { | 418 | for(i=am; i<bm; i++) { |
| 430 | den += Sw[i].real*Sw[i].real + Sw[i].imag*Sw[i].imag; | 419 | den += Sw[i].real*Sw[i].real + Sw[i].imag*Sw[i].imag; |
| 431 | Am.real += Sw[i].real*W[i + offset].real; | ||
| 432 | Am.imag += Sw[i].imag*W[i + offset].real; | ||
| 433 | } | 420 | } |
| 434 | 421 | ||
| 435 | model->A[m] = sqrtf(den); | 422 | model->A[m] = sqrtf(den); |
| 436 | 423 | ||
| 437 | if (est_phase) { | 424 | if (est_phase) { |
| 425 | int b = (int)(m*model->Wo/r + 0.5); /* DFT bin of centre of current harmonic */ | ||
| 438 | 426 | ||
| 439 | /* Estimate phase of harmonic, this is expensive in CPU for | 427 | /* Estimate phase of harmonic, this is expensive in CPU for |
| 440 | embedded devicesso we make it an option */ | 428 | embedded devicesso we make it an option */ |
| @@ -459,7 +447,7 @@ float est_voicing_mbe( | |||
| 459 | C2CONST *c2const, | 447 | C2CONST *c2const, |
| 460 | MODEL *model, | 448 | MODEL *model, |
| 461 | COMP Sw[], | 449 | COMP Sw[], |
| 462 | COMP W[] | 450 | float W[] |
| 463 | ) | 451 | ) |
| 464 | { | 452 | { |
| 465 | int l,al,bl,m; /* loop variables */ | 453 | int l,al,bl,m; /* loop variables */ |
| @@ -497,9 +485,9 @@ float est_voicing_mbe( | |||
| 497 | 485 | ||
| 498 | offset = FFT_ENC/2 - l*Wo*FFT_ENC/TWO_PI + 0.5; | 486 | offset = FFT_ENC/2 - l*Wo*FFT_ENC/TWO_PI + 0.5; |
| 499 | for(m=al; m<bl; m++) { | 487 | for(m=al; m<bl; m++) { |
| 500 | Am.real += Sw[m].real*W[offset+m].real; | 488 | Am.real += Sw[m].real*W[offset+m]; |
| 501 | Am.imag += Sw[m].imag*W[offset+m].real; | 489 | Am.imag += Sw[m].imag*W[offset+m]; |
| 502 | den += W[offset+m].real*W[offset+m].real; | 490 | den += W[offset+m]*W[offset+m]; |
| 503 | } | 491 | } |
| 504 | 492 | ||
| 505 | Am.real = Am.real/den; | 493 | Am.real = Am.real/den; |
| @@ -507,10 +495,9 @@ float est_voicing_mbe( | |||
| 507 | 495 | ||
| 508 | /* Determine error between estimated harmonic and original */ | 496 | /* Determine error between estimated harmonic and original */ |
| 509 | 497 | ||
| 510 | // Redundant! offset = FFT_ENC/2 - l*Wo*FFT_ENC/TWO_PI + 0.5; | ||
| 511 | for(m=al; m<bl; m++) { | 498 | for(m=al; m<bl; m++) { |
| 512 | Ew.real = Sw[m].real - Am.real*W[offset+m].real; | 499 | Ew.real = Sw[m].real - Am.real*W[offset+m]; |
| 513 | Ew.imag = Sw[m].imag - Am.imag*W[offset+m].real; | 500 | Ew.imag = Sw[m].imag - Am.imag*W[offset+m]; |
| 514 | error += Ew.real*Ew.real; | 501 | error += Ew.real*Ew.real; |
| 515 | error += Ew.imag*Ew.imag; | 502 | error += Ew.imag*Ew.imag; |
| 516 | } | 503 | } |
