summaryrefslogtreecommitdiff
path: root/src/lib/sounds/sounds.ml
blob: aad7cf0e168509134827c4a059b66d058c54c919 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
module Sig = Sig

type kind =
  | None
  | Voyel
  | SemiVoyel

type code =
  | None
  | Space of string
  | SZ (* This is a possible Z if followed by a voyel *)
  | Voyel_A
  | Voyel_E
  | E_Opened
  | E_Closed
  | Voyel_I
  | Voyel_O
  | Voyel_U (* OU like in Ouvrir *)
  | Voyel_Y (* U like in Unique *)
  | Voyel_AI
  | Voyel_EU_Closed
  | Voyel_EU_Opened
  | SemiVoyel_W
  | SemiVoyel_Y
  | SemiVoyel_U
  | Consonant_P
  | Consonant_B
  | Consonant_T
  | Consonant_D
  | Consonant_K
  | Consonant_G
  | Consonant_F
  | Consonant_V
  | Consonant_S
  | Consonant_Z
  | Consonant_X
  | Consonant_J

  | Consonant_M
  | Consonant_N
  | Consonant_GN
  | Consonant_L
  | Consonant_R
  | Diphtonge of t * t
  | Muted of t

and t =
  { code : code
  ; mutable_: bool (* Can the sound be muted ? *)
  ; kind : kind
  ; nasal : bool
  }

let is_voyel t =
  t.kind = Voyel
  || t.kind = SemiVoyel

let is_nasal t = t.nasal

let none =
  { mutable_ = true
  ; kind = None
  ; nasal = false
  ; code = None }

let space s =
  { none with code = Space s }

let voyel =
  { none with kind = Voyel }


let diphtongue v1 v2 =
  { voyel with
    code = Diphtonge (v1, v2)
  }

let a =
  { voyel with
    code = Voyel_A
  }

let voyel_ai =
  { voyel with
    code = Voyel_AI
  }

let e = function
  | `Closed -> { voyel with code = E_Closed }
  | `Opened -> { voyel with code = E_Opened }

let eu = function
  | `Closed -> { voyel with code = Voyel_EU_Closed }
  | `Opened -> { voyel with code = Voyel_EU_Opened }


let schwa =
  { voyel with
    code = Voyel_E }

let o =
  { voyel with
    code = Voyel_O }

let i =
  { voyel with
    code = Voyel_I }

let voyel_y =
  { voyel with
    code = Voyel_Y }

let voyel_u =
  { voyel with
    code = Voyel_U }

let p =
  { none with
    code = Consonant_P }

let b =
  { none with
    code = Consonant_B }

let t =
  { none with
    code = Consonant_T
  }

let d =
  { none with
    code = Consonant_D }

let k =
  { none with
    code = Consonant_K
  ; mutable_ = false }

let g =
  { none with
    code = Consonant_G }

(** f is alway pronounend in ending consonant. Know exeception are :
    - cerf
    - clef
    - nerf
    - serf *)
let f =
  { none with
    code = Consonant_F
  ; mutable_ = false
  }

let v =
  { none with
    code = Consonant_V }

let s =
  { none with
    code = Consonant_S }

let sz =
  { s with code = SZ }

let z =
  { none with
    code = Consonant_Z }

let ch =
  { none with
    code = Consonant_X
  ; mutable_ = false }

let j =
  { none with
    code = Consonant_J
  ; mutable_ = false }

let gn =
  { none with
    code = Consonant_GN
  ; nasal = true }

let n =
  { none with
    code = Consonant_N
  ; nasal = true }

let m =
  { none with
    code = Consonant_M
  ; nasal = true }

let l =
  { none with
    code = Consonant_L
  ; mutable_ = false }

let r =
  { none with
    code = Consonant_R }

let semi_voyel_w =
  { none with
    kind = SemiVoyel
  ; code = SemiVoyel_W}

let semi_voyel_y =
  { none with
    kind = SemiVoyel
  ; code = SemiVoyel_Y}

let semi_voyel_u =
  { none with
    kind = SemiVoyel
  ; code = SemiVoyel_U}

let rec nasal t =

  match t.kind, t.code with
  | Voyel, Diphtonge (s1, s2) ->
    begin match s1.code, s2.code with
      | (SemiVoyel_Y, Voyel_E) ->
        (* The only case we could have the nasalisation of such diphtongue, is
           the case I E, N -> wich is transformed into I, I N. *)
        Some ( diphtongue s1 { i with nasal = true } )
      | _ -> Option.map (fun s -> diphtongue s1 s) (nasal s2)
    end
  | Voyel, _ -> Some { t with nasal = true }
  | _ -> None

let is_muted t =
  match t.code with
  | Muted _ -> true
  | _ -> false

let mute f =
  match f.mutable_ with
  | false -> f
  | true ->
    { none with
      code = Muted f }

let unmute t =
  match t.code with
  | Muted t -> t
  | _ -> t

let repr
  : (module Sig.REPR) -> t list -> string
  = fun m letters ->
    let module Repr = (val m:Sig.REPR) in

    let rec _repr letter =

      match letter.code, letter.nasal with

      | None            , _     -> Repr.none
      | Space s         , _     -> Repr.space s
      | Voyel_A         , false -> Repr.a
      | Voyel_A         , true  -> Repr.a_nasal
      | Voyel_AI        , false -> Repr.e_opened
      | Voyel_AI        , true  -> Repr.i_nasal
      | E_Closed        , _     -> Repr.e_closed
      | E_Opened        , false -> Repr.e_opened
      | E_Opened        , true
      | Voyel_E         , true  -> Repr.a_nasal
      | Voyel_E         , false -> Repr.schwa
      | Voyel_I         , false -> Repr.i
      | Voyel_I         , true  -> Repr.i_nasal
      | Voyel_O         , true  -> Repr.o_nasal
      | Voyel_O         , false -> Repr.o
      | Voyel_U         , _     -> Repr.u
      | Voyel_Y         , false -> Repr.y
      | Voyel_Y         , true  -> Repr.y_nasal
      | Voyel_EU_Closed , _     -> Repr.eu_closed
      | Voyel_EU_Opened , _     -> Repr.eu_opened

      | SemiVoyel_W     , _     -> Repr.semi_voyel_w
      | SemiVoyel_Y     , _     -> Repr.semi_voyel_y
      | SemiVoyel_U     , _     -> Repr.semi_voyel_u

      | Consonant_P     , _     -> Repr.p
      | Consonant_B     , _     -> Repr.b
      | Consonant_T     , _     -> Repr.t
      | Consonant_D     , _     -> Repr.d
      | Consonant_K     , _     -> Repr.k
      | Consonant_G     , _     -> Repr.g
      | Consonant_F     , _     -> Repr.f
      | Consonant_V     , _     -> Repr.v
      | SZ              , _
      | Consonant_S     , _     -> Repr.s
      | Consonant_Z     , _     -> Repr.z

      | Consonant_X     , _     -> Repr.ch
      | Consonant_J     , _     -> Repr.j

      | Consonant_M     , _     -> Repr.m
      | Consonant_N     , _     -> Repr.n
      | Consonant_GN    , _     -> Repr.gn
      | Consonant_L     , _     -> Repr.l
      | Consonant_R     , _     -> Repr.r
      | Muted t         , _     -> Repr.muted (_repr t)
      | Diphtonge (l1, l2), _   -> Repr.diphtongue (_repr l1) (_repr l2)

    in

    List.map _repr letters
    |> Repr.fold