Mercurial > hg > x
comparison hssf.h @ 1:6422640a802f
first upload
author | Wen X <xue.wen@elec.qmul.ac.uk> |
---|---|
date | Tue, 05 Oct 2010 10:45:57 +0100 |
parents | |
children | 5f3c32dc6e17 |
comparison
equal
deleted
inserted
replaced
0:9b9f21935f24 | 1:6422640a802f |
---|---|
1 #ifndef hssfH | |
2 #define hssfH | |
3 | |
4 /* | |
5 hssf.cpp - source-filter modeling for harmonic sinusoids | |
6 | |
7 Further reading: Wen X. and M. Sandler, "Source-filter modeling in sinusoid domain," in Proc. AES 126th | |
8 Convention, Munich, 2009. | |
9 */ | |
10 | |
11 | |
12 #include <stdio.h> | |
13 #include "hs.h" | |
14 | |
15 //--------------------------------------------------------------------------- | |
16 const double Amel=1127.0104803341574386544633680278; | |
17 const bool useA0=true; //if true, use A0D+A0C instead of A0C in S-F decomposition as pre-normalizer | |
18 | |
19 | |
20 /* | |
21 TSF is the class implementing source-filter model for harmonic sinusoids. TSF shares the basic framework | |
22 of the vibrato description class TVo, but implements a more compact source-filter representation. It does | |
23 not go into detailed vibrato analysis such as extraction modulator shape. | |
24 | |
25 An analysis/synthesis cycle converts THS to TSF and back. | |
26 */ | |
27 | |
28 struct TSF | |
29 { | |
30 //basic characteristics | |
31 int M; //number of partials | |
32 int L; //number of frames | |
33 int P; //number of segmentation points | |
34 double offst; //hop size | |
35 double* F0C; //[0:L-1] pitch carrier | |
36 double* F0D; //[0:L-1] pitch modulator | |
37 double* logA0C; //[0:L-1] amplitude carreir | |
38 double* logA0D; //[0:L-1] amplitude modulator | |
39 | |
40 double* lp; //[0:P-1] peak positions | |
41 | |
42 double F; //filter: band with (linear or mel) associated to each b[][] | |
43 double Fs; //sampling frequency | |
44 int FScaleMode; //linear or mel | |
45 int K; //number of filter bands | |
46 double** b; //[0:L-1][0:M-1] single-frame source, in dB | |
47 double** h; //[0:L-1][0:K+1] single-frame filter, in dB | |
48 double* avgb; //[0:M-1] average source | |
49 double* avgh; //[0:K+1] average filter | |
50 | |
51 //other properties | |
52 | |
53 double rate; //vibrato rate | |
54 double regularity;//vibrato regularity | |
55 double F0max; //maximal fundamental frequency | |
56 double F0min; //minimal fundamental frequency | |
57 double F0Cmax; //maximal fundamental carrier frequency | |
58 double F0Cmin; //minimal fundamental carrier frequency | |
59 double F0Overall; //overall average fundamental frequency | |
60 double F0Dmax; //maximal fundamental modulator frequency | |
61 double F0Dmin; //minimal fundamental modulator frequency | |
62 double* F0; //[0:L-1] fundamental frequency | |
63 double* logA0; //[0:L-1] log amplitude | |
64 | |
65 TSF(); | |
66 ~TSF(); | |
67 | |
68 //copy function | |
69 void Duplicate(TSF& SF); | |
70 | |
71 //output routines | |
72 double LogAF(double f); | |
73 double LogAF(double f, int fr); | |
74 double LogAS(int m, int fr); | |
75 | |
76 //memory handling routines | |
77 void AllocateL(int AnL); | |
78 void ReAllocateL(int newL); | |
79 void AllocateP(); | |
80 void AllocateSF(); | |
81 | |
82 //I/O routines | |
83 void SaveSFToFileHandle(FILE* f); | |
84 void SaveToFileHandle(FILE* f); | |
85 void LoadSFFromFileHandle(FILE* f); | |
86 void LoadFromFileHandle(FILE* f); | |
87 void SaveToFile(char* filename); | |
88 | |
89 //other member functions | |
90 void ShiftFilterByDB(double dB); | |
91 }; | |
92 | |
93 //--tool procedures---------------------------------------------------------- | |
94 int Sign(double); | |
95 | |
96 //--general source-filter model routines------------------------------------- | |
97 void S_F_b(TSF& SF, atom** Partials); | |
98 | |
99 //--slow-variation SF estimation routines------------------------------------ | |
100 double P2_DelFtr(double** d, int L, int K, double** x, double F); | |
101 double P3_DelSrc(double** d, int L, int M, int K, double** x, double** f, double F); | |
102 int SF_SV(double** h, int L, int M, int K, double** a, double** f, double F, double theta, double ep, int maxiter); | |
103 double S_F_SV(int M, atom** Partials, double* logA0C, double* lp, int P, int& K, double** h, double* avgh, double** b, double* avgb, double F=0.005, int FScaleMode=0, double theta=0.5, double Fs=44100); | |
104 void SF_SV_cf(double* h, double** b, int L, int M, int K, double** a, double** f, double F, double ep, int maxiter); | |
105 double S_F_SV_cf(int afres, double* LogAF, double* LogAS, int Fr, int M, atom** Partials, double* A0C, double* lp, int P, int& K, double** h, double** b, double F=0.005, int FScaleMode=0, double Fs=44100); | |
106 | |
107 //--filter-bank SF estimation routines--------------------------------------- | |
108 int SF_FB(double* hl, int M, int K, double** al, double** fl, double F, int LMode); | |
109 double S_F_FB(int M, atom** Partials, double* logA0C, double* lp, int P, int& K, double** h, double* avgh, double** b, double* avgb, double F=0.005, int FScaleMode=0, double Fs=44100); | |
110 | |
111 //--source-filter analysis and synthesis routines---------------------------- | |
112 void AnalyzeSF_1(THS& HS, TSF& SF, double sps, double offst); | |
113 void AnalyzeSF_2(THS& HS, TSF& SF, double*& cyclefrs, double*& cyclefs, double sps, int* cyclefrcount=0, int SFMode=0, double SFF=0.01, int SFFScale=0, double SFtheta=0); | |
114 void AnalyzeSF(THS& HS, TSF& SF, double*& cyclefrs, double*& cyclefs, double sps, double offst, int* cyclefrcount=0, int SFMode=0, double SFF=0.01, int SFFScale=0, double SFtheta=0); | |
115 void SynthesizeSF(THS* HS, TSF* SF, double sps); | |
116 | |
117 | |
118 #endif |