Phonemes ={	
	names = {
					"eee", "ihh", "ehh", "aaa",
					"ahh", "aww", "ohh", "uhh",
				   	"uuu", "ooo", "rrr", "lll",
				   	"mmm", "nnn", "nng", "ngg",
					"fff", "sss", "thh", "shh",
					"xxx", "hee", "hoo", "hah",
				    "bbb", "ddd", "jjj", "ggg",
				    "vvv", "zzz", "thz", "zhh"
			 	},
	
	   gains =  {
		   {1.0, 0.0},    -- eee
		   {1.0, 0.0},    -- ihh
		   {1.0, 0.0},    -- ehh
		   {1.0, 0.0},    -- aaa
		
		   {1.0, 0.0},    -- ahh
		   {1.0, 0.0},    -- aww
		   {1.0, 0.0},    -- ohh
		   {1.0, 0.0},    -- uhh
		
		   {1.0, 0.0},    -- uuu
		   {1.0, 0.0},    -- ooo
		   {1.0, 0.0},    -- rrr
		   {1.0, 0.0},    -- lll
		
		   {1.0, 0.0},    -- mmm
		   {1.0, 0.0},    -- nnn
		   {1.0, 0.0},    -- nng
		   {1.0, 0.0},    -- ngg
		
		   {0.0, 0.7},    -- fff
		   {0.0, 0.7},    -- sss
		   {0.0, 0.7},    -- thh
		   {0.0, 0.7},    -- shh
		
		   {0.0, 0.7},    -- xxx
		   {0.0, 0.1},    -- hee
		   {0.0, 0.1},    -- hoo
		   {0.0, 0.1},    -- hah
		
		   {1.0, 0.1},    -- bbb
		   {1.0, 0.1},    -- ddd
		   {1.0, 0.1},    -- jjj
		   {1.0, 0.1},    -- ggg
		
		   {1.0, 1.0},    -- vvv
		   {1.0, 1.0},    -- zzz
		   {1.0, 1.0},    -- thz
		   {1.0, 1.0}     -- zhh
	   },
	   
	   parameters = {
		   {  { 273, 0.996,  10},       -- eee (beet)
		      {2086, 0.945, -16}, 
		      {2754, 0.979, -12}, 
		      {3270, 0.440, -17}	},
		   {  { 385, 0.987,  10},       -- ihh (bit)
		      {2056, 0.930, -20},
		      {2587, 0.890, -20}, 
		      {3150, 0.400, -20}	},
		   {  { 515, 0.977,  10},       -- ehh (bet)
		      {1805, 0.810, -10}, 
		      {2526, 0.875, -10}, 
		      {3103, 0.400, -13}	},
		   {  { 773, 0.950,  10},       -- aaa (bat)
		      {1676, 0.830,  -6},
		      {2380, 0.880, -20}, 
		      {3027, 0.600, -20}	},
		     
		   {  { 770, 0.950,   0},       -- ahh (father)
		      {1153, 0.970,  -9},
		      {2450, 0.780, -29},
		      {3140, 0.800, -39}	},
		   {  { 637, 0.910,   0},       -- aww (bought)
		      { 895, 0.900,  -3},
		      {2556, 0.950, -17},
		      {3070, 0.910, -20}	},
		   {  { 637, 0.910,   0},       -- ohh (bone)  NOTE::  same as aww (bought)
		      { 895, 0.900,  -3},
		      {2556, 0.950, -17},
		      {3070, 0.910, -20}	},
		   {  { 561, 0.965,   0},       -- uhh (but)
		      {1084, 0.930, -10}, 
		      {2541, 0.930, -15}, 
		      {3345, 0.900, -20}	},
		    
		   {  { 515, 0.976,   0},       -- uuu (foot)
		      {1031, 0.950,  -3},
		      {2572, 0.960, -11},
		      {3345, 0.960, -20}	},
		   {  { 349, 0.986, 10},       -- ooo (boot)
		      { 918, 0.940, -20},
		      {2350, 0.960, -27},
		      {2731, 0.950, -33}	},
		   {  { 394, 0.959, -10},       -- rrr (bird)
		      {1297, 0.780, -16},
		      {1441, 0.980, -16},
		      {2754, 0.950, -40}	},
		   {  { 462, 0.990,   5},       -- lll (lull)
		      {1200, 0.640, -10},
		      {2500, 0.200, -20},
		      {3000, 0.100, -30}	},
		     
		   {  { 265, 0.987, -10},       -- mmm (mom)
		      {1176, 0.940, -22},
		      {2352, 0.970, -20},
		      {3277, 0.940, -31}	},
		   {  { 204, 0.980, -10},       -- nnn (nun)
		      {1570, 0.940, -15},
		      {2481, 0.980, -12},
		      {3133, 0.800, -30}	},
		   {  { 204, 0.980, -10},       -- nng (sang)    NOTE:: same as nnn
		      {1570, 0.940, -15},
		      {2481, 0.980, -12},
		      {3133, 0.800, -30}	},
		   {  { 204, 0.980, -10},       -- ngg (bong)    NOTE:: same as nnn
		      {1570, 0.940, -15},
		      {2481, 0.980, -12},
		      {3133, 0.800, -30}	},
		     
		   {  {1000, 0.300,   0},       -- fff
		      {2800, 0.860, -10},
		      {7425, 0.740,   0},
		      {8140, 0.860,   0}	},
		   {  {2000,    0.700,   -200},       -- sss
		      {2000, 0.700, -15},
		      {5257, 0.750,  -3}, 
		      {7171, 0.840,   0}	},
		   {  { 100, 0.900,   0},       -- thh
		      {4000, 0.500, -20},
		      {5500, 0.500, -15},
		      {8000, 0.400, -20}	},
		   {  {2693, 0.940,   0},       -- shh
		      {4000, 0.720, -10},
		      {6123, 0.870, -10},
		      {7755, 0.750, -18}	},
		
		   {  {1000, 0.300, -10},       -- xxx           NOTE:: Not Really Done Yet
		      {2800, 0.860, -10},
		      {7425, 0.740,   0},
		      {8140, 0.860,   0}	},
		   {  { 273, 0.996, -40},       -- hee (beet)    (noisy eee)
		      {2086, 0.945, -16}, 
		      {2754, 0.979, -12}, 
		      {3270, 0.440, -17}	},
		   {  { 349, 0.986, -40},       -- hoo (boot)    (noisy ooo)
		      { 918, 0.940, -10},
		      {2350, 0.960, -17},
		      {2731, 0.950, -23}	},
		   {  { 770, 0.950, -40},       -- hah (father)  (noisy ahh)
		      {1153, 0.970,  -3},
		      {2450, 0.780, -20},
		      {3140, 0.800, -32}	},
		     
		   {  {2000, 0.700, -20},       -- bbb           NOTE:: Not Really Done Yet
		      {5257, 0.750, -15},
		      {7171, 0.840,  -3}, 
		      {9000, 0.900,   0}	},
		   {  { 100, 0.900,   0},       -- ddd           NOTE:: Not Really Done Yet
		      {4000, 0.500, -20},
		      {5500, 0.500, -15},
		      {8000, 0.400, -20}	},
		   {  {2693, 0.940,   0},       -- jjj           NOTE:: Not Really Done Yet
		      {4000, 0.720, -10},
		      {6123, 0.870, -10},
		      {7755, 0.750, -18}	},
		   {  {2693, 0.940,   0},       -- ggg           NOTE:: Not Really Done Yet
		      {4000, 0.720, -10},
		      {6123, 0.870, -10},
		      {7755, 0.750, -18}	},
		     
		   {  {2000, 0.700, -20},       -- vvv           NOTE:: Not Really Done Yet
		      {5257, 0.750, -15},
		      {7171, 0.840,  -3}, 
		      {9000, 0.900,   0}	},
		   {  { 100, 0.900,   0},       -- zzz           NOTE:: Not Really Done Yet
		      {4000, 0.500, -20},
		      {5500, 0.500, -15},
		      {8000, 0.400, -20}	},
		   {  {2693, 0.940,   0},       -- thz           NOTE:: Not Really Done Yet
		      {4000, 0.720, -10},
		      {6123, 0.870, -10},
		      {7755, 0.750, -18}	},
		   {  {2693, 0.940,   0},       -- zhh           NOTE:: Not Really Done Yet
		      {4000, 0.720, -10},
		      {6123, 0.870, -10},
		      {7755, 0.750, -18}	}
		}
	
}
Phonemes._namesindex = swapkeyvalue(Phonemes.names)
function Phonemes:namesindex(name)
	return self._namesindex[name]
end
function unomenosa(a) return 1-a end
function dbamp(db)
	return 10^(db/20)
end
function Phonemes:paramsind(ind)
	local par= flop(self.parameters[ind])
	--a[1]=(1-a[1])*a[0];
	for i,v in ipairs(par[2]) do
		par[2][i]= -44100*math.log(v)/(math.pi*par[1][i])
		--par[2][i]=(1-v) --*par[1][i]
	end
		par[3]= functabla(par[3],dbamp)
	par[4]=self.gains[ind][1]
	par[5]=self.gains[ind][2]
	----------
	par[1] = {par[1]}
	par[2] = {par[2]}
	par[3] = {par[3]}
	return par
end
function Phonemes:params(name)
	local ind=self:namesindex(name)
	local par= flop(self.parameters[ind])
	--a[1]=(1-a[1])*a[0];
	for i,v in ipairs(par[2]) do
		par[2][i]= -44100*math.log(v)/(math.pi*par[1][i])--(1-v) --*par[1][i]
		--par[2][i] = 1-v
	end
	par[3]= functabla(par[3],dbamp)
	par[4]=self.gains[ind][1]
	par[5]=self.gains[ind][2]
	----------
	par[1] = {par[1]}
	par[2],par[3] = {par[3]},{par[2]}
	---------------
	return par
end
function Phonemes:paramsD(name)
	local ind=self:namesindex(name)
	local par= flop(self.parameters[ind])

	par[3]= functabla(par[3],dbamp)
	par[4]=self.gains[ind][1]
	par[5]=self.gains[ind][2]
	----------
	--par[1] = {par[1]}
	local temp = par[2]
	par[2] = par[3]
	par[3] = temp
	---------------
	return par
end
function Phonemes:paramsPalabra(t)
	local res={}
	for i,v in ipairs(t) do
		res[i]=self:params(v)
	end
	return res
end
-----------------------------------------------------------------
Formants={
counterTenorA={ { 660, 1120, 2750, 3000, 3350 }, { 1, 0.50118723362727, 0.070794578438414, 0.063095734448019, 0.012589254117942 }, { 0.12121212121212, 0.080357142857143, 0.043636363636364, 0.043333333333333, 0.041791044776119 } },
altoE={ { 400, 1600, 2700, 3300, 4950 }, { 1, 0.063095734448019, 0.031622776601684, 0.017782794100389, 0.001 }, { 0.15, 0.05, 0.044444444444444, 0.045454545454545, 0.04040404040404 } },
bassA={ { 600, 1040, 2250, 2450, 2750 }, { 1, 0.44668359215096, 0.35481338923358, 0.35481338923358, 0.1 }, { 0.1, 0.067307692307692, 0.048888888888889, 0.048979591836735, 0.047272727272727 } },
bassI={ { 250, 1750, 2600, 3050, 3340 }, { 1, 0.031622776601684, 0.15848931924611, 0.079432823472428, 0.03981071705535 }, { 0.24, 0.051428571428571, 0.038461538461538, 0.039344262295082, 0.035928143712575 } },
altoI={ { 350, 1700, 2700, 3700, 4950 }, { 1, 0.1, 0.031622776601684, 0.015848931924611, 0.001 }, { 0.14285714285714, 0.058823529411765, 0.044444444444444, 0.040540540540541, 0.04040404040404 } },
altoA={ { 800, 1150, 2800, 3500, 4950 }, { 1, 0.63095734448019, 0.1, 0.015848931924611, 0.001 }, { 0.1, 0.078260869565217, 0.042857142857143, 0.037142857142857, 0.028282828282828 } },
tenorA={ { 650, 1080, 2650, 2900, 3250 }, { 1, 0.50118723362727, 0.44668359215096, 0.3981071705535, 0.079432823472428 }, { 0.12307692307692, 0.083333333333333, 0.045283018867925, 0.044827586206897, 0.043076923076923 } },
tenorO={ { 400, 800, 2600, 2800, 3000 }, { 1, 0.31622776601684, 0.25118864315096, 0.25118864315096, 0.050118723362727 }, { 0.1, 0.1, 0.038461538461538, 0.042857142857143, 0.04 } },
--sopranoA={ { 800, 1150, 2900, 3900, 4950 }, { 1, 0.50118723362727, 0.025118864315096, 0.1, 0.0031622776601684 }, { 0.1, 0.078260869565217, 0.041379310344828, 0.033333333333333, 0.028282828282828 } },
sopranoA={ { 600,800, 1150, 3900, 4950 }, {1, 1, 0.50118723362727, 0.1, 0.0031622776601684 }, {0.1, 0.1, 0.078260869565217, 0.033333333333333, 0.028282828282828 } },
--sopranoE={ { 350, 2000, 2800, 3600, 4950 }, { 1, 0.1, 0.17782794100389, 0.01, 0.0015848931924611 }, { 0.17142857142857, 0.05, 0.042857142857143, 0.041666666666667, 0.04040404040404 } },
sopranoE={ { 500, 1850, 2475, 3600, 4950 }, { 1, 0.5, 0.17782794100389, 0.01, 0.0015848931924611 }, { 0.05, 0.05, 0.042857142857143, 0.041666666666667, 0.04040404040404 } },
tenorI={ { 290, 1870, 2800, 3250, 3540 }, { 1, 0.17782794100389, 0.12589254117942, 0.1, 0.031622776601684 }, { 0.13793103448276, 0.048128342245989, 0.035714285714286, 0.036923076923077, 0.033898305084746 } },
tenorU={ { 350, 600, 2700, 2900, 3300 }, { 1, 0.1, 0.14125375446228, 0.19952623149689, 0.050118723362727 }, { 0.11428571428571, 0.1, 0.037037037037037, 0.041379310344828, 0.036363636363636 } },
--sopranoU={ { 325, 700, 2700, 3800, 4950 }, { 1, 0.15848931924611, 0.017782794100389, 0.01, 0.001 }, { 0.15384615384615, 0.085714285714286, 0.062962962962963, 0.047368421052632, 0.04040404040404 } },
sopranoU={ { 325, 700, 2700, 3800, 4950 }, { 1, 0.7848931924611, 0.17782794100389, 0.01, 0.001 }, { 0.15384615384615, 0.085714285714286, 0.062962962962963, 0.047368421052632, 0.04040404040404 } },
counterTenorE={ { 440, 1800, 2700, 3000, 3300 }, { 1, 0.19952623149689, 0.12589254117942, 0.1, 0.1 }, { 0.15909090909091, 0.044444444444444, 0.037037037037037, 0.04, 0.036363636363636 } },
altoO={ { 450, 800, 2830, 3500, 4950 }, { 1, 0.35481338923358, 0.15848931924611, 0.03981071705535, 0.0017782794100389 }, { 0.15555555555556, 0.1, 0.035335689045936, 0.037142857142857, 0.027272727272727 } },
counterTenorU={ { 370, 630, 2750, 3000, 3400 }, { 1, 0.1, 0.070794578438414, 0.031622776601684, 0.019952623149689 }, { 0.10810810810811, 0.095238095238095, 0.036363636363636, 0.04, 0.035294117647059 } },
--sopranoI={ { 270, 2140, 2950, 3900, 4950 }, { 1, 0.25118864315096, 0.050118723362727, 0.050118723362727, 0.0063095734448019 }, { 0.22222222222222, 0.042056074766355, 0.033898305084746, 0.030769230769231, 0.024242424242424 } },
sopranoI={ { 333, 2332, 2986, 3900, 4950 }, { 1, 0.65118864315096, 0.050118723362727, 0.050118723362727, 0.0063095734448019 }, { 0.05, 0.042056074766355, 0.033898305084746, 0.030769230769231, 0.024242424242424 } },
counterTenorO={ { 430, 820, 2700, 3000, 3300 }, { 1, 0.31622776601684, 0.050118723362727, 0.079432823472428, 0.019952623149689 }, { 0.093023255813953, 0.097560975609756, 0.037037037037037, 0.04, 0.036363636363636 } },
bassE={ { 400, 1620, 2400, 2800, 3100 }, { 1, 0.25118864315096, 0.35481338923358, 0.25118864315096, 0.12589254117942 }, { 0.1, 0.049382716049383, 0.041666666666667, 0.042857142857143, 0.038709677419355 } },
counterTenorI={ { 270, 1850, 2900, 3350, 3590 }, { 1, 0.063095734448019, 0.063095734448019, 0.015848931924611, 0.015848931924611 }, { 0.14814814814815, 0.048648648648649, 0.03448275862069, 0.035820895522388, 0.033426183844011 } },
bassO={ { 400, 750, 2400, 2600, 2900 }, { 1, 0.28183829312645, 0.089125093813375, 0.1, 0.01 }, { 0.1, 0.10666666666667, 0.041666666666667, 0.046153846153846, 0.041379310344828 } },
bassU={ { 350, 600, 2400, 2675, 2950 }, { 1, 0.1, 0.025118864315096, 0.03981071705535, 0.015848931924611 }, { 0.11428571428571, 0.13333333333333, 0.041666666666667, 0.044859813084112, 0.040677966101695 } },
altoU={ { 325, 700, 2530, 3500, 4950 }, { 1, 0.25118864315096, 0.031622776601684, 0.01, 0.00063095734448019 }, { 0.15384615384615, 0.085714285714286, 0.067193675889328, 0.051428571428571, 0.04040404040404 } },
tenorE={ { 400, 1700, 2600, 3200, 3580 }, { 1, 0.19952623149689, 0.25118864315096, 0.19952623149689, 0.1 }, { 0.175, 0.047058823529412, 0.038461538461538, 0.0375, 0.033519553072626 } },
--sopranoO={ { 450, 800, 2830, 3800, 4950 }, { 1, 0.28183829312645, 0.079432823472428, 0.079432823472428, 0.0031622776601684 }, { 0.15555555555556, 0.1, 0.035335689045936, 0.034210526315789, 0.027272727272727 } }
sopranoO={ { 450, 800, 2830, 3800, 4950 }, { 1, 0.7183829312645, 0.39432823472428, 0.079432823472428, 0.0031622776601684 }, { 0.15555555555556, 0.1, 0.035335689045936, 0.034210526315789, 0.027272727272727 } }
}

FormantsD = deepcopy(Formants)

--to avoid multiexpand
for k,v in pairs(Formants) do
	for i,v2 in ipairs(v) do
		v[i] = {v2}
	end
end
function Formants:params(k)
	return flop(Formants[k])
	--return Formants[k]
end
function Formants:paramsPalabra(t,voz)
	voz = voz or ""
	local res={}
	for i,v in ipairs(t) do
		res[i]=Formants[voz..v]--self:params(v)
	end
	return res
end