phoneme a
  vwl starttype #a endtype #a
  length 130
  FMT(vwl_lv/a, 100)           // adjusted from aa_3
endphoneme

phoneme a`     // shorter variant of a
  vwl starttype #a endtype #a
  length 60
  FMT(vwl_lv/a, 100)
endphoneme

phoneme a:
  vwl starttype #a endtype #a
  length 310
  lng
  FMT(vwl_lv/aa, 90)
endphoneme

phoneme E
  vwl starttype #e endtype #e
  ipa æ
  length 120
  FMT(vwl_lv/e2, 100)
endphoneme

phoneme E:
  vwl starttype #e endtype #e
  ipa æː
  length 300
  FMT(vwl_lv/ee2, 100)
endphoneme

phoneme e
  vwl starttype #e endtype #e
  length 120
  FMT(vwl_lv/e, 100)  // other alternative e_5
endphoneme

phoneme e:
  vwl starttype #e endtype #e
  length 300
  FMT(vwl_lv/ee, 100) // other alternative e_8
endphoneme

phoneme i
  vwl starttype #i endtype #i
  length 120
  FMT(vwl_lv/i, 110) // was i_6
endphoneme

phoneme i:
  vwl starttype #i endtype #i
  length 280
  FMT(vwl_lv/ii, 90) // was i_7
endphoneme

phoneme y   // English y, short Latgalian "hard i"
  vwl starttype #i endtype #i
  length 120
  FMT(vwl_lv/y, 100)
endphoneme

phoneme y:   // Long Latgalian "hard i"
  vwl starttype #i endtype #i
  length 300
  FMT(vwl_lv/yy, 90)
endphoneme

phoneme o
  vwl starttype #o endtype #o
  length 120
  FMT(vwl_lv/o, 90)
endphoneme

phoneme o` // shorter version of o
  vwl starttype #o endtype #o
  length 60
  FMT(vwl_lv/o, 90)
endphoneme

phoneme o:
  vwl starttype #o endtype #o
  length 300
  FMT(vwl_lv/oo, 75)
endphoneme

phoneme u
  vwl starttype #u endtype #u
  length 120
  FMT(vwl_lv/u, 100)
endphoneme

phoneme u:
  vwl starttype #u endtype #u
  length 300
  FMT(vwl_lv/uu, 90)
endphoneme

phoneme ai
  vwl starttype #a endtype #i
  length 280
  lng
  FMT(vwl_lv/ai, 100)
endphoneme

phoneme au
  vwl starttype #a endtype #u
  length 280
  lng
  FMT(vwl_lv/au, 100)
endphoneme

phoneme ei
  vwl starttype #e endtype #i
  length 280
  lng
  FMT(vwl_lv/ei, 100)
endphoneme

phoneme ie
  vwl starttype #i endtype #e
  length 250
  lng
  FMT(vwl_lv/ie, 100)
endphoneme

phoneme iu
  vwl starttype #i endtype #u
  length 250
  lng
  FMT(vwl_lv/iu, 100)
endphoneme

phoneme ui
  vwl starttype #u endtype #i
  length 250
  lng
  FMT(vwl_lv/ui, 100)
endphoneme

phoneme uo
  vwl starttype #u endtype #a
  length 280
  lng
  FMT(vwl_lv/ua, 110)
endphoneme

phoneme uo`     // shorter version of uo
  vwl starttype #u endtype #a
  ipa uo
  length 150
  lng
  FMT(vwl_lv/ua, 90)
endphoneme

phoneme oi
  vwl starttype #o endtype #i
  length 250
  lng
  FMT(vwl_lv/oi, 100)
endphoneme

phoneme ts
  vls alv afr nolink
  ipa t͡s
  voicingswitch J
  length 55
  lengthmod 1
  WAV(ustop/ts2, 60)
endphoneme

phoneme tS
  vls pla afr sib
  ipa t͡ʃ
  voicingswitch dZ
  lengthmod 2
  length 80
  WAV(ustop/tsh,40)
endphoneme

phoneme D   // louder and shorter version of d
  vcd alv stp
  ipa d
  voicingswitch t
  length 8
  lengthmod 5
  Vowelin f1=1  f2=1700 -300 300  f3=-100 80
  Vowelout f1=2 f2=1700 -300 300  f3=-100 80 brk

  IF PreVoicing THEN
    FMT(d/xd, 110)
  ENDIF

  IF nextPh(isPause2) THEN
    FMT(d/d_, 120)  addWav(x/d_,110)
  ENDIF

  FMT(d/d, 110) addWav(x/d,110)
endphoneme

phoneme h // more quiet version of standard h
  vls glt apr
  lengthmod 3
  ipa h

  IF nextPh(#a) THEN
    WAV(h/h-lv, 20)
  ELIF nextPh(#e) THEN
    WAV(h/h-lv, 20)
  ELIF nextPh(#i) THEN
    WAV(h/h-lv, 20)
  ELIF nextPh(#o) THEN
    WAV(h/h-lv, 20)
  ELIF nextPh(#u) THEN
    WAV(h/h-lv, 20)
  ELIF nextPh(isPause) THEN
    WAV(h/h-lv, 20)
  ENDIF
  WAV(h/h-lv, 20)  // no vowel following
endphoneme

phoneme j // **y**es
  liquid pal starttype #i
  IF nextPhW(isVowel) THEN
    NextVowelStarts
      VowelStart(j/j@)
      VowelStart(j/ja)
      VowelStart(j/je)
      VowelStart(j/ji)
      VowelStart(j/jo)
      VowelStart(j/ju)
    EndSwitch
    VowelEnding(j/xj, 127) // In difference with English, vowel is lengthened, not shortened
  ELSE
    Vowelout len=127      // no vowel follows
    FMT(j/xj)
  ENDIF

  IF prevPh(isPause) THEN
    FMT(j/_j)
  ENDIF
endphoneme

phoneme k
  vls vel stp
  lengthmod 2
  voicingswitch g
  Vowelin f1=0  f2=2300 200 400  f3=-100 80
  Vowelout f1=0 f2=2300 300 400  f3=-100 80  rms=20
  IF nextPh(isPause2) THEN
    WAV(ustop/k_)
  ENDIF
  IF nextPh(#i) OR nextPh(l^) THEN
    WAV(ustop/ki)
  ENDIF
  IF nextPh(l) THEN
    WAV(ustop/kl)
  ENDIF
  WAV(ustop/k_unasp, 60)   // weaker
endphoneme

phoneme c
  vls pal stp pzd
  voicingswitch J
  WAV(ustop/c, 80)
endphoneme

phoneme l
  liquid

  IF nextPh(isNotVowel) THEN
    PrevVowelEndings
      VowelEnding(l/L1_@L)
      VowelEnding(l/L1_aL)
      VowelEnding(l/L1_eL)
      VowelEnding(l/L1_iL)
      VowelEnding(l/L1_oL)
      VowelEnding(l/L1_uL)
    EndSwitch

    FMT(l/l_)
    RETURN
  ENDIF

  CALL vowelstart_l

  IF prevPh(a) OR prevPh(a:) THEN
    VowelEnding(l/xl, 20) // FIXME
  ELSEIF prevPh(isVowel) THEN
    VowelEnding(l/xl, 10)
  ENDIF

  IF prevPh(isPause) THEN
    FMT(l/_l)
  ENDIF

  IF prevPh(t) THEN
    FMT(l/tl)
  ENDIF

  IF prevPh(l/) THEN
    FMT(l/l_long)    // double l, make it longer
  ENDIF

  FMT(l/l)
endphoneme

phoneme l^    // Latvian ļ, customized from standard l^
  liquid
  ipa ʎ
  lengthmod 7
  Vowelout len=60 lenadd rate
  length 80

  NextVowelStarts
    VowelStart(l^/j2@)
    VowelStart(l^/j2a)
    VowelStart(l^/j2e)
    VowelStart(l^/j2i)
    VowelStart(l^/j2o)
    VowelStart(l^/j2u)
  EndSwitch

  IF prevPh(isPause) THEN
    FMT(l^/_l^)
  ELSEIF nextPh(isPause) THEN
    length 100
    FMT(l^/l^_)
  ENDIF

  FMT(l^/l^)

endphoneme

phoneme m // copied from standard m phoneme with rule for 'mm'
  vcd blb nas
  Vowelout f1=2  f2=1000 -500 -350  f3=-200 80 brk
  lengthmod 4

  IF KlattSynth THEN
    Vowelin  f1=0  f2=1000 -50 -200  f3=-200 80
    IF nextPh(isPause2) THEN
      FMT(klatt/m_)
    ENDIF
    FMT(klatt/m)
  ENDIF

  NextVowelStarts
    VowelStart(m/m@)
    VowelStart(m/ma)
    VowelStart(m/me)
    VowelStart(m/mi)
    VowelStart(m/mo)
    VowelStart(m/mu)
  EndSwitch

  IF prevPh(isNotVowel) AND nextPhW(isLiquid) THEN
    FMT(m/mj)
  ELIF prevPh(isPause) THEN
    FMT(m/_m)
  ELIF nextPh(isNotVowel) THEN
    FMT(m/m_)
  ELIF nextPh(m) THEN // m/mj has no volume change, so doubled 'mm' merges better
    FMT(m/mj)
  ENDIF
endphoneme

phoneme n- // more voiced variant of n
  vwl starttype #a endtype #a
  ipa ŋ
  lengthmod 4
  length 140
  FMT(n/n-syl)
endphoneme

phoneme p
  vls blb stp
  lengthmod 2
  voicingswitch b
  Vowelin  f1=0  f2=1000 -50 -100  f3=-200 80
  Vowelout f1=0  f2=1000 -500 -350  f3=-300 80 rms=30
  IF nextPh(isPause2) THEN
    WAV(ustop/p_unasp_, 80)
  ENDIF
  IF nextPh(l) THEN
    WAV(ustop/pl)
  ENDIF
  WAV(ustop/p_unasp, 120)
endphoneme

phoneme R // Latvian hard r
  liquid trl
  ipa r
  lengthmod 6
  Vowelin  f1=0  f2=1700 -300 300  f3=-300 80
  Vowelout f1=2  f2=1700 -300 300  f3=-300 80 brk
FMT(r3/r_trill) addWav(r3/r_trill.wav, 60)
endphoneme

phoneme r // Latvian soft r
  liquid trl
  ipa r̝
  lengthmod 6
  Vowelin  f1=0  f2=1700 -300 300  f3=-300 80
  Vowelout f1=2  f2=1700 -300 300  f3=-300 80 brk
  FMT(j/j_) addWav(r3/r_trill.wav, 25)
endphoneme

phoneme s
  vls alv frc sib
  voicingswitch z
  lengthmod 3
  Vowelin  f1=0  f2=1700 -300 300  f3=-100 80
  Vowelout f1=0  f2=1700 -300 250  f3=-100 80  rms=20
  WAV(ufric/s,60)
endphoneme

phoneme t
  vls alv stp //lengthenstop
  lengthmod 1
  voicingswitch d
  IF nextPh(isPause2) THEN
    WAV(ustop/t_dnt, 40)
  ENDIF
  WAV(ustop/t_dnt, 50)
endphoneme

phoneme v        // from v# in standard phonemes
  vcd lbd frc
  ipa ʋ
  lengthmod 6
  voicingswitch f
  Vowelin  f1=0  f2=1000 -300 -200  f3=-300 100
  Vowelout f1=0  f2=1000 -500 -300  f3=-300 60  len=50
  IF nextPh(isPause2) THEN
    FMT(voc/v#_)
  ENDIF
  FMT(voc/v#)
endphoneme

phoneme v`        // shortened v
  vcd lbd frc
  ipa ʋ
  lengthmod 6
  voicingswitch f
  Vowelin  f1=0  f2=1000 -300 -200  f3=-300 100
  Vowelout f1=0  f2=1000 -500 -300  f3=-300 60  len=50
  length 8
  FMT(voc/v#_)
endphoneme

phoneme z- // Shorter version of z
  vcd alv frc sib
  length 30
  voicingswitch s
  Vowelout f1=0  f2=1700 -300 300  f3=-100 60  len=50

  IF KlattSynth THEN
    Vowelin f1=0 f2=1390 -300 300 f3=0 0
    Vowelout f1=1  f2=1390 -300 300  f3=-100 60  len=50 brk
  ENDIF

  IF nextPh(isPause2) THEN
    FMT(voc/z_) addWav(ufric/s_, 70)
  ENDIF
  FMT(voc/z) addWav(ufric/s_, 85)
endphoneme


phoneme z`  // Shortest version of z for diphthong dz
  vcd alv frc sib
  ipa z
  voicingswitch s
  length 10
  Vowelout f1=0  f2=1700 -300 300  f3=-100 60  len=50

  IF KlattSynth THEN
    Vowelin f1=0 f2=1390 -300 300 f3=0 0
    Vowelout f1=1  f2=1390 -300 300  f3=-100 60  len=50 brk
  ENDIF

  IF nextPh(isPause2) THEN
    length 20
    FMT(voc/z_, 120) addWav(ufric/s_, 95)
  ENDIF
  FMT(voc/z, 110) addWav(ufric/s_, 100)
endphoneme

phoneme Z` // Shortened version of Z for diphthong dZ
  vcd pla frc sib
  ipa ʐ
  voicingswitch S
  length 30
  lengthmod 6
  Vowelin  f1=0  f2=2000 0 300  f3=-200 80
  Vowelout f1=2  f2=2000 0 300  f3=-200 80 brk

  IF KlattSynth THEN
    IF nextPh(isPause2) THEN
      FMT(klatt/zh_, 70) addWav(vocw/zh, 70)
    ENDIF
    FMT(klatt/zh) addWav(vocw/zh, 130)
  ENDIF

  IF nextPh(isPause2) THEN
    FMT(voc/zh_, 80) addWav(vocw/zh, 70)
  ENDIF
  FMT(voc/zh) addWav(vocw/zh, 130)
endphoneme

phoneme >  // lengthen previous vowel less than using ":"
  ipa ː
  virtual
  length 30 // it actually seems working shorter, but anyway...
endphoneme

