xue@11: /* xue@11: Harmonic sinusoidal modelling and tools xue@11: xue@11: C++ code package for harmonic sinusoidal modelling and relevant signal processing. xue@11: Centre for Digital Music, Queen Mary, University of London. xue@11: This file copyright 2011 Wen Xue. xue@11: xue@11: This program is free software; you can redistribute it and/or xue@11: modify it under the terms of the GNU General Public License as xue@11: published by the Free Software Foundation; either version 2 of the xue@11: License, or (at your option) any later version. xue@11: */ xue@1: #ifndef vibratoH xue@1: #define vibratoH xue@1: xue@1: Chris@5: /** Chris@5: \file vibrato.h - vibrato analysis and synthesis using harmonic sinusoids xue@1: xue@1: Further reading: Wen X. and M. Sandler, "Analysis and synthesis of audio vibrato using harmonic sinusoids," xue@1: in Proc. AES 124th Convention, Amsterdam, 2008. xue@1: */ xue@1: xue@1: #include xue@1: #include "hs.h" xue@1: //--------------------------------------------------------------------------- xue@1: Chris@5: /** xue@1: TVo is the data structure hosting descriptors of a vibrato representation of a harmonic sinusoid. Its xue@1: basic framework is shared by the TSF object which hosts a more elaborate source-filter model than TVo, xue@1: but does not look into vibrato-specific features such as modulator shape. xue@1: xue@1: An analysis/sythesis cycle converts THS to TVo and back. xue@1: */ xue@1: struct TVo xue@1: { xue@1: //basic characteristics Chris@5: int M; ///< number of partials Chris@5: int L; ///< number of frames Chris@5: int P; ///< number of F0 peaks Chris@5: double h; ///< hop size Chris@5: double* F0C; ///< [0:L-1] pitch carrier Chris@5: double* A0C; ///< [0:L-1] amplitude carreir Chris@5: int afres; ///< filter model bins Chris@5: double LogAF[4096]; ///< [0:afres-1] filter model xue@1: Chris@5: int* peakfr; ///< [0:P-1] peak positions, in frames Chris@5: double* lp; ///< [0:P-1] peak positions, refined to floating-point values in frames Chris@5: double* Dp; ///< [1:P-1] single-cycle rms of F0D Chris@5: int* Kp; ///< [1:P-1] order of single-cycle modulator shape descriptor Chris@5: double** fxr; ///< [1:P-1][0:2K] single-cycle modulator shape coefficients - cosine, sine, cosine, ... Chris@5: double** LogASp; ///< [1:P-1][0:M-1] single-cycle source model xue@1: int K; xue@1: xue@1: //other properties Chris@5: double rate; ///< vibrato rate Chris@5: double regularity;///< vibrato regularity Chris@5: double F0max; ///< maximal fundamental frequency Chris@5: double F0min; ///< minimal fundamental frequency Chris@5: double F0Cmax; ///< maximal fundamental carrier frequency Chris@5: double F0Cmin; ///< minimal fundamental carrier frequency Chris@5: double F0Overall; ///< overall average fundamental frequency Chris@5: double F0Dmax; ///< maximal fundamental modulator frequency Chris@5: double F0Dmin; ///< minimal fundamental modulator frequency Chris@5: double* F0; ///< [0:L-1] pitch Chris@5: double* F0D; ///< [0:L-1] pitch modulator Chris@5: double D; ///< rms of F0D, Chris@5: double LogAS[100];///< [0:M-1] source model Chris@5: double FXR[100]; ///< average cycle modulator shape coefficients Chris@5: double FRes[50]; ///< average modulator residues Chris@5: double** fres; ///< [1:P-1][0:K-1] single-cycle modulator residues xue@1: xue@1: TVo(); xue@1: ~TVo(); xue@1: void AllocateL(int AnL); xue@1: void ReAllocateL(int newL); xue@1: void AllocateP(); xue@1: void AllocatePK(); xue@1: void SaveToFile(char* filename); xue@1: void SaveToFileHandle(FILE* file); xue@1: void LoadFromFileHandle(FILE* file); xue@1: double GetOldP(); xue@1: }; xue@1: xue@1: //--tool procedures---------------------------------------------------------- xue@1: double QIE(double* y); xue@1: double QIE(double* y, double& x); xue@1: xue@1: //--demodulation routines---------------------------------------------------- xue@1: void DeFM(double* f2, double* f1, double* AA, int npfr, int* peakfr, int Fr, double& fct, int& fcount, double* &frs, double* &f, bool furthersmoothing=false); xue@1: void DeFM(double* f2, double* f1, double* AA, int npfr, double* lp, int Fr, double& fct, int& fcount, double* &frs, double* &f, bool furthersmoothing=false); xue@1: void DeAM(double* A2, double* A1, int npfr, int* peakfr, int Fr); xue@1: void DeAM(double* A2, double* A1, int npfr, double* lp, int Fr); xue@1: xue@1: //--source-filter analysis routine------------------------------------------- xue@1: double S_F(int afres, double* LogAF, double* LogAS, int Fr, int M, atom** Partials, double* A0C, double* lp, int P, double F0Overall); xue@1: double S_F_SV(int afres, double* LogAF, double* LogAS, int Fr, int M, atom** Partials, double* A0C, double* lp, int P, double F=0.005, int FScaleMode=0, double theta=0.5, double sps=44100); xue@1: xue@1: //--vibrato analysis and synthesis routines---------------------------------- xue@1: void AnalyzeV(THS& HS, TVo& V, double*& peaky, double*& cyclefrs, double*& cyclefs, double sps, double h, int* cyclefrcount=0, xue@1: int SFMode=0, double SFF=0.01, int SFFScale=0, double SFtheta=0); xue@1: void RegularizeV(THS& HS, TVo& V, double sps, double h); xue@1: void SynthesizeV(THS* HS, TVo* V, double sps, int UseK=0); xue@1: TVo* InterpolateV(double newP, double rate, TVo& V); xue@1: xue@1: //--other functions---------------------------------------------------------- xue@1: void FindPeaks(int* peakfr, int& npfr, double* F0, int Fr, double periodinframe, double*& peaky); xue@1: void FS_QR(int& K, double* FXR, double* data, int Fr, double period, double shift, double* FRES); xue@1: void RateAndReg(double& rate, double& regularity, double* data, int frst, int fren, int padrate, double sps, double offst); xue@1: xue@1: #endif