hssf.h
Go to the documentation of this file.
1 /*
2  Harmonic sinusoidal modelling and tools
3 
4  C++ code package for harmonic sinusoidal modelling and relevant signal processing.
5  Centre for Digital Music, Queen Mary, University of London.
6  This file copyright 2011 Wen Xue.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 */
13 #ifndef hssfH
14 #define hssfH
15 
24 #include <stdio.h>
25 #include "hs.h"
26 
27 //---------------------------------------------------------------------------
28 const double Amel=1127.0104803341574386544633680278;
29 const bool useA0=true; //if true, use A0D+A0C instead of A0C in S-F decomposition as pre-normalizer
30 
31 
40 struct TSF
41 {
42  //basic characteristics
43  int M;
44  int L;
45  int P;
46  double offst;
47  double* F0C;
48  double* F0D;
49  double* logA0C;
50  double* logA0D;
51 
52  double* lp;
53 
54  double F;
55  double Fs;
56  int FScaleMode;
57  int K;
58  double** b;
59  double** h;
60  double* avgb;
61  double* avgh;
62 
63  //other properties
64 
65  double rate;
66  double regularity;
67  double F0max;
68  double F0min;
69  double F0Cmax;
70  double F0Cmin;
71  double F0Overall;
72  double F0Dmax;
73  double F0Dmin;
74  double* F0;
75  double* logA0;
76 
77  TSF();
78  ~TSF();
79 
80  //copy function
81  void Duplicate(TSF& SF);
82 
83  //output routines
84  double LogAF(double f);
85  double LogAF(double f, int fr);
86  double LogAS(int m, int fr);
87 
88  //memory handling routines
89  void AllocateL(int AnL);
90  void ReAllocateL(int newL);
91  void AllocateP();
92  void AllocateSF();
93 
94  //I/O routines
95  void SaveSFToFileHandle(FILE* f);
96  void SaveToFileHandle(FILE* f);
97  void LoadSFFromFileHandle(FILE* f);
98  void LoadFromFileHandle(FILE* f);
99  void SaveToFile(char* filename);
100 
101  //other member functions
102  void ShiftFilterByDB(double dB);
103 };
104 
105 //--tool procedures----------------------------------------------------------
106 int Sign(double);
107 
108 //--general source-filter model routines-------------------------------------
109 void S_F_b(TSF& SF, atom** Partials);
110 
111 //--slow-variation SF estimation routines------------------------------------
112 double P2_DelFtr(double** d, int L, int K, double** x, double F);
113 double P3_DelSrc(double** d, int L, int M, int K, double** x, double** f, double F);
114 int SF_SV(double** h, int L, int M, int K, double** a, double** f, double F, double theta, double ep, int maxiter);
115 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);
116 void SF_SV_cf(double* h, double** b, int L, int M, int K, double** a, double** f, double F, double ep, int maxiter);
117 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);
118 
119 //--filter-bank SF estimation routines---------------------------------------
120 int SF_FB(double* hl, int M, int K, double** al, double** fl, double F, int LMode);
121 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);
122 
123 //--source-filter analysis and synthesis routines----------------------------
124 void AnalyzeSF_1(THS& HS, TSF& SF, double sps, double offst);
125 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);
126 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);
127 void SynthesizeSF(THS* HS, TSF* SF, double sps);
128 
129 
130 #endif
void LoadSFFromFileHandle(FILE *f)
Definition: hssf.cpp:109
double P2_DelFtr(double **d, int L, int K, double **x, double F)
Definition: hssf.cpp:543
void ShiftFilterByDB(double dB)
Definition: hssf.cpp:238
void Duplicate(TSF &SF)
Definition: hssf.cpp:78
int M
number of partials
Definition: hssf.h:43
double * avgh
[0:K+1] average filter
Definition: hssf.h:61
double F0Cmin
minimal fundamental carrier frequency
Definition: hssf.h:70
void SynthesizeSF(THS *HS, TSF *SF, double sps)
Definition: hssf.cpp:1143
double F0max
maximal fundamental frequency
Definition: hssf.h:67
int FScaleMode
linear or mel
Definition: hssf.h:56
int P
number of segmentation points
Definition: hssf.h:45
double F0Overall
overall average fundamental frequency
Definition: hssf.h:71
void AnalyzeSF_1(THS &HS, TSF &SF, double sps, double offst)
Definition: hssf.cpp:282
void AllocateSF()
Definition: hssf.cpp:66
double * F0D
[0:L-1] pitch modulator
Definition: hssf.h:48
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)
Definition: hssf.cpp:670
int SF_SV(double **h, int L, int M, int K, double **a, double **f, double F, double theta, double ep, int maxiter)
Definition: hssf.cpp:1002
double F0Cmax
maximal fundamental carrier frequency
Definition: hssf.h:69
double * lp
[0:P-1] peak positions
Definition: hssf.h:52
double ** h
[0:L-1][0:K+1] single-frame filter, in dB
Definition: hssf.h:59
Definition: hs.h:49
double F0min
minimal fundamental frequency
Definition: hssf.h:68
int L
number of frames
Definition: hssf.h:44
void AllocateP()
Definition: hssf.cpp:57
double P3_DelSrc(double **d, int L, int M, int K, double **x, double **f, double F)
Definition: hssf.cpp:574
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)
Definition: hssf.cpp:264
double Fs
sampling frequency
Definition: hssf.h:55
int Sign(double)
Definition: hssf.cpp:1127
double * logA0D
[0:L-1] amplitude modulator
Definition: hssf.h:50
void SaveToFile(char *filename)
Definition: hssf.cpp:208
double * F0
[0:L-1] fundamental frequency
Definition: hssf.h:74
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)
Definition: hssf.cpp:733
double F
filter: band with (linear or mel) associated to each b[][]
Definition: hssf.h:54
double rate
vibrato rate
Definition: hssf.h:65
double * logA0
[0:L-1] log amplitude
Definition: hssf.h:75
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)
Definition: hssf.cpp:351
double LogAF(double f)
Definition: hssf.cpp:129
void SF_SV_cf(double *h, double **b, int L, int M, int K, double **a, double **f, double F, double ep, int maxiter)
Definition: hssf.cpp:1104
void LoadFromFileHandle(FILE *f)
Definition: hssf.cpp:92
void S_F_b(TSF &SF, atom **Partials)
Definition: hssf.cpp:649
double LogAS(int m, int fr)
Definition: hssf.cpp:165
double F0Dmax
maximal fundamental modulator frequency
Definition: hssf.h:72
void ReAllocateL(int newL)
Definition: hssf.cpp:176
double * avgb
[0:M-1] average source
Definition: hssf.h:60
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)
Definition: hssf.cpp:794
double * F0C
[0:L-1] pitch carrier
Definition: hssf.h:47
int K
number of filter bands
Definition: hssf.h:57
Definition: hs.h:147
void AllocateL(int AnL)
Definition: hssf.cpp:46
double ** b
[0:L-1][0:M-1] single-frame source, in dB
Definition: hssf.h:58
Definition: hssf.h:40
double regularity
vibrato regularity
Definition: hssf.h:66
void SaveSFToFileHandle(FILE *f)
Definition: hssf.cpp:191
double F0Dmin
minimal fundamental modulator frequency
Definition: hssf.h:73
double offst
hop size
Definition: hssf.h:46
void SaveToFileHandle(FILE *f)
Definition: hssf.cpp:220
double * logA0C
[0:L-1] amplitude carreir
Definition: hssf.h:49
int SF_FB(double *hl, int M, int K, double **al, double **fl, double F, int LMode)
Definition: hssf.cpp:875