/*---------------------------------------------------------------------------*\ FILE........: phase.c AUTHOR......: David Rowe DATE CREATED: 1/2/09 Functions for modelling and synthesising phase. \*---------------------------------------------------------------------------*/ /* Copyright (C) 2009 David Rowe All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not,see . */ #include "defines.h" #include "phase.h" #include "fft.h" #include "comp.h" #include "glottal.c" #include #include #include #include #define GLOTTAL_FFT_SIZE 512 /*---------------------------------------------------------------------------*\ aks_to_H() Samples the complex LPC synthesis filter spectrum at the harmonic frequencies. \*---------------------------------------------------------------------------*/ void aks_to_H( MODEL *model, /* model parameters */ float aks[], /* LPC's */ float G, /* energy term */ COMP H[], /* complex LPC spectral samples */ int order ) { COMP Pw[FFT_DEC]; /* power spectrum */ int i,m; /* loop variables */ int am,bm; /* limits of current band */ float r; /* no. rads/bin */ float Em; /* energy in band */ float Am; /* spectral amplitude sample */ int b; /* centre bin of harmonic */ float phi_; /* phase of LPC spectra */ r = TWO_PI/(FFT_DEC); /* Determine DFT of A(exp(jw)) ------------------------------------------*/ for(i=0; iL; m++) { am = floor((m - 0.5)*model->Wo/r + 0.5); bm = floor((m + 0.5)*model->Wo/r + 0.5); b = floor(m*model->Wo/r + 0.5); Em = 0.0; for(i=am; iWo)*N/2; */ ex_phase[0] += (model->Wo)*N; ex_phase[0] -= TWO_PI*floor(ex_phase[0]/TWO_PI + 0.5); r = TWO_PI/GLOTTAL_FFT_SIZE; for(m=1; m<=model->L; m++) { /* generate excitation */ if (model->voiced) { /* I think adding a little jitter helps improve low pitch males like hts1a. This moves the onset of each harmonic over at +/- 0.25 of a sample. */ jitter = 0.25*(1.0 - 2.0*rand()/RAND_MAX); b = floor(m*model->Wo/r + 0.5); if (b > ((GLOTTAL_FFT_SIZE/2)-1)) { b = (GLOTTAL_FFT_SIZE/2)-1; } Ex[m].real = cos(ex_phase[0]*m - jitter*model->Wo*m + glottal[b]); Ex[m].imag = sin(ex_phase[0]*m - jitter*model->Wo*m + glottal[b]); } else { /* When a few samples were tested I found that LPC filter phase is not needed in the unvoiced case, but no harm in keeping it. */ float phi = TWO_PI*(float)rand()/RAND_MAX; Ex[m].real = cos(phi); Ex[m].imag = sin(phi); } /* filter using LPC filter */ A_[m].real = H[m].real*Ex[m].real - H[m].imag*Ex[m].imag; A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag; /* modify sinusoidal phase */ new_phi = atan2(A_[m].imag, A_[m].real+1E-12); model->phi[m] = new_phi; } }