// ph_pashto - Phoneme table for Pashto language
// Created: March 2025 by Hanif Rahman
// Updated: March 2025 - Fixed vowel formants, improved retroflex consonants, corrected stress patterns
// This file defines phonemes specific to Pashto language


//====================================================
// VOWELS
//====================================================

phoneme a    // َ (zabar/fatha) - short 'a' as in "man"
  vwl starttype #a endtype #a
  length 180
  ipa a
  FMT(vowel/a)
endphoneme

phoneme a:   // ا - long 'aa' as in "father"
  vwl starttype #a endtype #a
  length 280
  ipa aː
  FMT(vowel/a)  // Keeping formant consistent with short 'a'
endphoneme

phoneme e    // ِ (zer/kasra) - short 'e' as in "bed" "ketab"
  vwl starttype #e endtype #e
  length 170
  ipa e
  FMT(vowel/e)
endphoneme

phoneme e:   // ې - long 'ee' as in "bait" "peshawar"
  vwl starttype #e endtype #e
  length 250
  ipa eː
  FMT(vowel/e_mid)  // Using e_mid for better long vowel quality
endphoneme

phoneme i    // ِ (zer/kasra) - short 'i' as in "sit" same as e?
  vwl starttype #i endtype #i
  length 170
  ipa i
  IfNextVowelAppend(;)
  FMT(vowel/i)
endphoneme

phoneme i:   // ي - long 'ee' as in "see"
  vwl starttype #i endtype #i
  length 250
  ipa iː
  IfNextVowelAppend(;)
  FMT(vowel/i)  // Using standard i vowel
endphoneme

phoneme o    // ُ (pesh/damma) - short 'o' as in "pot"
  vwl starttype #o endtype #o
  length 170
  ipa o
  FMT(vowel/o)
endphoneme

phoneme o:   // و - long 'o' as in "go"
  vwl starttype #o endtype #o
  length 250
  ipa oː
  FMT(vowel/o)  // Using standard o vowel
endphoneme

phoneme u    // ُ (pesh/damma) - short 'u' as in "put"
  vwl starttype #u endtype #u
  length 170
  ipa u
  FMT(vowel/u)
endphoneme

phoneme u:   // و - long 'oo' as in "moon"
  vwl starttype #u endtype #u
  length 250
  ipa uː
  FMT(vowel/u)  // Using standard u vowel
endphoneme

phoneme @    // ə - schwa sound as in "about"
  vwl starttype #@ endtype #@
  length 130
  ipa ə
  unstressed
  FMT(vowel/@)
endphoneme

// Add unstressed variants of vowels for better prosody
phoneme a#   // َ (zabar/fatha) - unstressed short 'a'
  vwl starttype #a endtype #a
  length 140  // shorter than stressed version
  ipa a
  unstressed
  FMT(vowel/a_8)
endphoneme

phoneme i#   // ِ (zer/kasra) - unstressed short 'i'
  vwl starttype #i endtype #i
  length 130  // shorter than stressed version
  ipa i
  unstressed
  IfNextVowelAppend(;)
  FMT(vowel/i_6)
endphoneme

phoneme u#   // ُ (pesh/damma) - unstressed short 'u'
  vwl starttype #u endtype #u
  length 130  // shorter than stressed version
  ipa u
  unstressed
  FMT(vowel/u_6)
endphoneme

//====================================================
// CONSONANTS SPECIFIC TO PASHTO
//====================================================

phoneme ts
  // څ in Pashto - voiceless alveolar affricate
  vls alv afr
  lengthmod 2
  ipa ts
  Vowelin f1=0  f2=1700 -300 300  f3=-100 80
  Vowelout f1=0 f2=1700 -300 250  f3=-100 80  rms=20
  WAV(ustop/ts)
endphoneme

phoneme dz
  // ځ in Pashto - voiced alveolar affricate
  vcd alv afr
  lengthmod 5
  ipa dz
  voicingswitch ts
  Vowelin f1=1  f2=1700 -300 300  f3=-100 80
  Vowelout f1=1 f2=1700 -300 300  f3=-100 80  brk
  WAV(ustop/ts) addWav(x/d, 70)  // Using standard WAV files
endphoneme

phoneme t.
  // ټ in Pashto - retroflex/plosive t
  vls rfx stp
  lengthmod 2
  ipa ʈ
  voicingswitch d.
  Vowelin f1=0  f2=1800 -300 300  f3=-200 80 colr=2
  Vowelout f1=0 f2=1800 -300 250  f3=-200 80 colr=2 rms=20
  WAV(ustop/t_)  // Using standard t_ WAV
endphoneme

phoneme d.
  // ډ in Pashto - retroflex/plosive d
  vcd rfx stp
  lengthmod 5
  ipa ɖ
  voicingswitch t.
  Vowelin f1=2  f2=1800 -300 300  f3=-200 80 colr=2
  Vowelout f1=2 f2=1800 -300 300  f3=-200 80 colr=2 brk
  WAV(ustop/t_) addWav(x/d, 60)  // Using standard WAV files
endphoneme

phoneme r.
  // ړ in Pashto - retroflex flap
  vcd rfx flp
  lengthmod 6
  ipa ɽ
  Vowelin f1=3  f2=1200 -400 -100  f3=-400 80 colr=2
  Vowelout f1=3 f2=1200 -400 -100  f3=-400 80 colr=2
  FMT(r3/r_) addWav(r3/rx, 80)  // Using standard FMT
endphoneme

phoneme n.
  // ڼ in Pashto - retroflex nasal
  vcd rfx nas
  lengthmod 4
  ipa ɳ
  Vowelin f1=2  f2=1200 -500 -300  f3=-400 80 colr=2
  Vowelout f1=2 f2=1200 -500 -300  f3=-400 80 colr=2
  FMT(n/n_)  // Using standard FMT
endphoneme

phoneme S.
  // ښ in Pashto - retroflex fricative
  vls rfx frc sib
  lengthmod 3
  ipa ʂ
  voicingswitch Z.
  Vowelin  f1=0  f2=1800 -100 300  f3=-400 80 colr=2
  Vowelout f1=0  f2=1800 -100 300  f3=-400 80 colr=2
  WAV(ufric/sh)  // Using standard sh WAV
endphoneme

phoneme Z.
  // ږ in Pashto - voiced retroflex fricative
  vcd rfx frc sib
  lengthmod 6
  ipa ʐ
  voicingswitch S.
  Vowelin  f1=0  f2=1800 0 300  f3=-400 80 colr=2
  Vowelout f1=2  f2=1800 0 300  f3=-400 80 colr=2 brk
  FMT(voc/zh) addWav(vocw/zh, 110)  // Using standard zh WAV
endphoneme

phoneme Z
  // ژ in Pashto - voiced post-alveolar fricative (like French j)
  vcd pla frc sib
  lengthmod 6
  ipa ʒ
  voicingswitch S
  Vowelin  f1=0  f2=2000 0 300  f3=-200 80
  Vowelout f1=2  f2=2000 0 300  f3=-200 80 brk
  FMT(voc/zh) addWav(vocw/zh, 130)
endphoneme

phoneme Q
  // غ in Pashto - voiced uvular fricative
  vcd uvl frc
  lengthmod 6
  ipa ʁ
  voicingswitch X
  Vowelin f1=2  f2=1000 -500 -350  f3=-200 80
  Vowelout f1=2 f2=1000 -500 -350  f3=-200 80 brk
  FMT(voc/Q) addWav(vocw/Q, 60)  // Increased WAV amplitude for better voicing
endphoneme

phoneme X
  // خ in Pashto - voiceless uvular fricative
  vls uvl frc
  lengthmod 3
  ipa χ
  voicingswitch Q
  Vowelin f1=0  f2=1000 -500 -350  f3=-200 80
  Vowelout f1=0 f2=1000 -500 -350  f3=-200 80
  WAV(ufric/xx, 90)  // Adjusted amplitude for better contrast with Q
endphoneme

phoneme g
  // ګ in Pashto - voiced velar stop
  vcd vel stp
  lengthmod 5
  ipa ɡ
  voicingswitch k
  Vowelin f1=2  f2=2300 200 300  f3=-300 80
  Vowelout f1=2  f2=2300 250 300  f3=-300 80 brk
  IF PreVoicing THEN
    FMT(g/xg)
  ENDIF
  IF nextPh(isPause2) THEN
    FMT(g/g_) addWav(x/g_)
  ENDIF
  FMT(g/g) addWav(x/g2, 150)
endphoneme

//====================================================
// CONSONANTS SHARED WITH OTHER LANGUAGES
//====================================================

phoneme p
  vls blb stp
  voicingswitch b
  lengthmod 2
  ipa p
  Vowelin  f1=0  f2=1000 -50  -100  f3=-200 80 amp=11
  Vowelout f1=0  f2=1000 -500 -350  f3=-300 80 rms=22
  WAV(ustop/p)
endphoneme

phoneme b
  vcd blb stp
  voicingswitch p
  lengthmod 5
  ipa b
  Vowelin  f1=2  f2=1000 -500 -300  f3=-300 80
  Vowelout f1=2  f2=1000 -500 -300  f3=-300 80 brk
  IF PreVoicing THEN
    FMT(b/xb)
  ENDIF
  IF nextPh(isPause2) THEN
    FMT(b/b_) addWav(x/b_)
  ENDIF
  FMT(b/b) addWav(x/b)
endphoneme

phoneme t
  vls alv stp
  voicingswitch d
  lengthmod 2
  ipa t
  Vowelin f1=0  f2=1700 -300 300  f3=-100 80
  Vowelout f1=0 f2=1700 -300 250  f3=-100 80  rms=20
  WAV(ustop/t)
endphoneme

phoneme d
  vcd alv stp
  voicingswitch t
  lengthmod 5
  ipa d
  Vowelin f1=1  f2=1700 -300 300  f3=-100 80
  Vowelout f1=1 f2=1700 -300 300  f3=-100 80 brk
  IF PreVoicing THEN
    FMT(d/xd)
  ENDIF
  IF nextPh(isPause2) THEN
    FMT(d/d_) addWav(x/d_)
  ENDIF
  FMT(d/d) addWav(x/d)
endphoneme

phoneme k
  vls vel stp
  voicingswitch g
  lengthmod 2
  ipa k
  Vowelin f1=0  f2=2300 200 300  f3=-200 80
  Vowelout f1=0 f2=2300 300 400  f3=-200 80  rms=20
  IF nextPh(isPause2) THEN
    WAV(ustop/k_)
  ENDIF
  WAV(ustop/k)
endphoneme

phoneme tS
  // چ in Pashto - voiceless post-alveolar affricate
  vls pla afr sib
  voicingswitch dZ
  lengthmod 2
  ipa t͡ʃ
  Vowelin f1=0  f2=2300 200 400  f3=-100 80
  Vowelout f1=0 f2=2300 300 400  f3=-100 80
  WAV(ustop/tsh)
endphoneme

phoneme dZ
  // ج in Pashto - voiced post-alveolar affricate
  vcd pla afr sib
  voicingswitch tS
  lengthmod 5
  ipa d͡ʒ
  Vowelin f1=2  f2=2300 200 400  f3=-100 80
  Vowelout f1=2 f2=2300 250 300  f3=-100 80 brk
  IF PreVoicing THEN
    FMT(dzh/xdzh)
  ENDIF
  IF nextPh(isPause2) THEN
    FMT(dzh/dzh_) addWav(x/dzh_)
  ENDIF
  FMT(dzh/dzh) addWav(x/dzh)
endphoneme

phoneme f
  vls lbd frc
  voicingswitch v
  lengthmod 3
  ipa f
  Vowelin  f1=0  f2=1000 -500 -350  f3=-200 80
  Vowelout f1=0  f2=1000 -500 -350  f3=-200 80
  WAV(ufric/f)
endphoneme

phoneme v
  vcd lbd frc
  voicingswitch f
  lengthmod 6
  ipa v
  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_) addWav(vocw/v)
  ENDIF
  FMT(voc/v) addWav(vocw/v)
endphoneme

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

phoneme z
  vcd alv frc sib
  voicingswitch s
  lengthmod 6
  ipa z
  Vowelin  f1=0  f2=1700 -300 300  f3=-100 80
  Vowelout f1=0 f2=1700 -300 300  f3=-100 80 brk
  IF nextPh(isPause2) THEN
    FMT(voc/z_) addWav(ufric/s_, 70)
  ENDIF
  FMT(voc/z) addWav(ufric/s_, 85)
endphoneme

phoneme S
  vls pla frc sib
  voicingswitch Z
  lengthmod 3
  ipa ʃ
  Vowelin  f1=0  f2=2100 100 300  f3=-100 80
  Vowelout f1=0  f2=2100 100 300  f3=-100 80
  WAV(ufric/sh)
endphoneme

phoneme x
  vls vel frc
  voicingswitch Q
  lengthmod 3
  ipa x
  Vowelin  f1=0  f2=2300 200 400  f3=-200 80
  Vowelout f1=0  f2=2300 300 400  f3=-200 80
  WAV(ufric/x_hr, 30)  // Increased amplitude for better clarity
endphoneme

phoneme h
  vls glt frc
  lengthmod 3
  ipa h
  Vowelin  f1=0  f2=2300 200 400  f3=-200 80  // Added Vowelin parameters
  Vowelout f1=0  f2=2300 300 400  f3=-200 80
  IF nextPh(#@) THEN
    WAV(h/h@)
  ELIF nextPh(#a) THEN
    WAV(h/ha)
  ELIF nextPh(#e) THEN
    WAV(h/he)
  ELIF nextPh(#i) THEN
    WAV(h/hi)
  ELIF nextPh(#o) THEN
    WAV(h/ho)
  ELIF nextPh(#u) THEN
    WAV(h/hu)
  ENDIF
  WAV(h/h_, 70)
endphoneme

phoneme m
  vcd blb nas
  lengthmod 4
  ipa m
  Vowelin  f1=0  f2=1000 -50 -200  f3=-200 80  // Moved Vowelin before Vowelout for consistency
  Vowelout f1=2  f2=1000 -500 -350  f3=-200 80 brk
  
  IF KlattSynth THEN
    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_)
  ENDIF
endphoneme

phoneme n
  vcd alv nas
  lengthmod 4
  ipa n
  Vowelin f1=0 f2=1500 -200 200 f3=0 80  // Moved Vowelin before Vowelout for consistency
  Vowelout f1=2 f2=1500 -300 250  f3=-100 80  rms=20 brk

  IF KlattSynth THEN
    FMT(klatt/n)
  ENDIF

  NextVowelStarts
    VowelStart(n/n@)
    VowelStart(n/na)
    VowelStart(n/ne)
    VowelStart(n/ni)
    VowelStart(n/no)
    VowelStart(n/nu)
  EndSwitch

  IF prevPh(isNotVowel) AND nextPhW(isLiquid) THEN
    FMT(n/nj)
  ELIF prevPh(isPause) OR prevPh(n) THEN
    FMT(n/_n)
  ELIF nextPh(isNotVowel) THEN
    FMT(n/n_)
  ENDIF
endphoneme

phoneme N
  vcd vel nas
  lengthmod 8
  ipa ŋ
  Vowelin f1=0 f2=2100 50 300 f3=0 80  // Moved Vowelin before Vowelout for consistency
  Vowelout f1=3 f2=2300 300 400  f3=-200 80  len=40 rms=20 brk

  IF KlattSynth THEN
    IF nextPh(isPause2) THEN
      FMT(klatt/nn_)
    ENDIF
    FMT(klatt/nn)
  ENDIF

  NextVowelStarts
    VowelStart(nn/nn@)
    VowelStart(nn/nna)
    VowelStart(nn/nne)
    VowelStart(nn/nni)
    VowelStart(nn/nno)
    VowelStart(nn/nnu)
  EndSwitch

  IF prevPh(#i) THEN
    VowelEnding(nn/inn, -40)
  ENDIF

  IF prevPh(isNotVowel) AND nextPhW(isLiquid) THEN
    FMT(nn/nnj)
  ELIF prevPh(isPause) THEN
    FMT(nn/_nn)
  ELIF nextPh(isNotVowel) THEN
    FMT(nn/nn_)
  ENDIF
endphoneme

phoneme l
  liquid
  lengthmod 7
  ipa l

  IF nextPh(isNotVowel) THEN
    ChangePhoneme(l/)
  ENDIF

  CALL vowelstart_l

  IF prevPh(#@) THEN
    VowelEnding(l/xl, -50)
  ELIF prevPh(isVowel) THEN
    VowelEnding(l/xl, -40)
  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/
  liquid
  lengthmod 7
  ipa l̥ 

  IF nextPh(isVowel) THEN
    ChangePhoneme(l)
  ENDIF

  PrevVowelEndings
    VowelEnding(l/L1_@L, -60)
    VowelEnding(l/L1_aL, -40)
    VowelEnding(l/L1_eL, -30)
    VowelEnding(l/L1_iL, -30)
    VowelEnding(l/L1_oL, -40)
    VowelEnding(l/L1_uL, -40)
  EndSwitch

  IF prevPhW(j) THEN
    FMT(l/L1_eL)
  ENDIF
  IF prevPhW(w) THEN
    FMT(l/L1_eL)
  ENDIF

  FMT(l/l_)
endphoneme

phoneme r
  liquid rhotic
  lengthmod 7
  ipa r

  IF nextPh(isNotVowel) THEN
    ChangePhoneme(r/)
  ENDIF

  NextVowelStarts
    VowelStart(r/r@, -15)
    VowelStart(r/ra, -15)
    VowelStart(r/re, -15)
    VowelStart(r/ri, -15)
    VowelStart(r/ro, -15)
    VowelStart(r/ru, -15)
  EndSwitch

  IF prevPh(isVowel) THEN
    VowelEnding(r/xr, -50)
  ENDIF

  IF prevPh(isPause) THEN
    FMT(r/_r)
  ELIF prevPh(t) OR prevPh(p) OR prevPh(k) THEN
    FMT(r/tr)
  ENDIF

  FMT(r/r)
endphoneme

phoneme r/
  liquid rhotic
  lengthmod 2
  ipa r̥

  IF prevPh(t) OR prevPh(p) OR prevPh(k) THEN
    FMT(r/trr)
  ENDIF

  IF prevPh(isNotVowel) THEN
    FMT(r/rr)
  ENDIF

  FMT(r3/r_) addWav(r3/rx)
endphoneme

phoneme j
  liquid pal starttype #i
  lengthmod 7
  ipa j

  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, -30)

    IF prevPh(isPause) THEN
      FMT(j/_j)
    ENDIF
  ELSE
    // no vowel follows
    Vowelout len=70
    FMT(j/j_)
  ENDIF
endphoneme

phoneme w
  liquid
  lengthmod 7
  starttype #u
  ipa w
  
  IF nextPh(isVowel) THEN
    NextVowelStarts
      VowelStart(w/w@)
      VowelStart(w/wa)
      VowelStart(w/we)
      VowelStart(w/wi)
      VowelStart(w/wo)
      VowelStart(w/wu)
    EndSwitch

    VowelEnding(w/xw, -30)

    IF prevPhW(isNasal) THEN
      FMT(w/w)
    ELSEIF prevPhW(h) THEN
      // none,  [hw]
    ELSE
      FMT(w/_w)
    ENDIF
  ELSE
    // no vowel follows
    Vowelout len=50
    IF prevPh(#i) THEN
      FMT(w/iw_)
    ENDIF
    FMT(w/w_)
  ENDIF
endphoneme

phoneme q
  vls uvl stp
  lengthmod 2
  ipa q
  Vowelin f1=1  f2=1700 0 200  f3=-300 80 gpaus f4 rms=30
  Vowelout f1=1 f2=1700 -100 200  f3=-300 80  f4 rms=35

  IF nextPh(isPause2) THEN
    WAV(ustop/q, 40)
  ELIF nextPh(#u) THEN
    WAV(ustop/q_u, 80)
  ENDIF
  WAV(ustop/q, 48)
endphoneme

phoneme ?
  vls glt stp
  lengthmod 3
  ipa ʔ
  nolink
  Vowelin  glstop
  Vowelout glstop
  WAV(ustop/null)
endphoneme