| 1 |
<html> |
| 2 |
|
| 3 |
<head> |
| 4 |
<title>Voice Synthesis Tutorial</title> |
| 5 |
</head> |
| 6 |
|
| 7 |
<body> |
| 8 |
|
| 9 |
<h1>Voice Synthesis Tutorial</h1> |
| 10 |
|
| 11 |
<p>Nyquist voice synthesis instrument by Eduardo Reck Miranda.</p> |
| 12 |
|
| 13 |
<pre>;--------------------------------------------------------------------------- |
| 14 |
; Nyquist voice synthesis instrument by Eduardo Reck Miranda |
| 15 |
; |
| 16 |
; Implements a geometrical articulator for tongue position (h p) and |
| 17 |
; lips rouding (r) |
| 18 |
; |
| 19 |
;--------------------------------------------------------------------------- |
| 20 |
; Geometrical articulator: the following FORMx functions estimates the formant |
| 21 |
; values from the positions of the three articulators p h and r, where: |
| 22 |
; p = horizontal position of the tongue: 0.0 = front and 1.0 = back |
| 23 |
; h = vertical position of the tongue: 0.0 = low and 1.0 = high |
| 24 |
; r = rounding of the lips: 0.0 = spread -> 1.0 rounded |
| 25 |
;--------------------------------------------------------------------------- |
| 26 |
; FORM1: converts p-h-r articulators to first formant frequency |
| 27 |
;--------------------------------------------------------------------------- |
| 28 |
(defmacro form1 (p h r) |
| 29 |
`(+ (* (+ (* (+ (- 392) (* 392 ,r)) (expt ,h 2)) |
| 30 |
(* (- 596 (* 668 ,r)) ,h) |
| 31 |
(+ (- 146) (* 166 ,r))) |
| 32 |
(expt ,p 2)) |
| 33 |
|
| 34 |
(* (+ (* (- 348 (* 348 ,r)) (expt ,h 2)) |
| 35 |
(* (+ (- 494) (* 606 ,r)) ,h) |
| 36 |
(- 141 (* 175 ,r))) |
| 37 |
,p) |
| 38 |
|
| 39 |
(+ (* (- 340 (* 72 ,r)) (expt ,h 2)) |
| 40 |
(* (+ (- 796) (* 108 ,r)) ,h) |
| 41 |
(- 708 (* 38 ,r))) |
| 42 |
)) |
| 43 |
|
| 44 |
;--------------------------------------------------------------------------- |
| 45 |
; FORM2: converts p-h-r articulators to second formant frequency |
| 46 |
;--------------------------------------------------------------------------- |
| 47 |
(defmacro form2 (p h r) |
| 48 |
`(+ (* (+ (* (+ (- 1200) (* 1208 ,r)) (expt ,h 2)) |
| 49 |
(* (- 1320 (* 1328 ,r)) ,h) |
| 50 |
(- 118 (* 158 ,r))) |
| 51 |
(expt ,p 2)) |
| 52 |
|
| 53 |
(* (+ (* (- 1864 (* 1488 ,r)) (expt ,h 2)) |
| 54 |
(* (+ (- 2644) (* 1510 ,r)) ,h) |
| 55 |
(+ (- 561) (* 221 ,r))) |
| 56 |
,p) |
| 57 |
|
| 58 |
(+ (* (+ (- 670) (* 490 ,r)) (expt ,h 2)) |
| 59 |
(* (- 1355 (* 697 ,r)) ,h) |
| 60 |
(- 1517 (* 117 ,r))) |
| 61 |
)) |
| 62 |
|
| 63 |
;--------------------------------------------------------------------------- |
| 64 |
; FORM3: converts p-h-r articulators to third formant frequency |
| 65 |
;--------------------------------------------------------------------------- |
| 66 |
(defmacro form3 (p h r) |
| 67 |
`(+ (* (+ (* (- 604 (* 604 ,r)) (expt ,h 2)) |
| 68 |
(* (- 1038 (* 1178 ,r)) ,h) |
| 69 |
(+ 246 (* 566 ,r))) |
| 70 |
(expt ,p 2)) |
| 71 |
|
| 72 |
(* (+ (* (+ (- 1150) (* 1262 ,r)) (expt ,h 2)) |
| 73 |
(* (+ (- 1443) (* 1313 ,r)) ,h) |
| 74 |
(- (- 317) (* 483 ,r))) |
| 75 |
,p) |
| 76 |
|
| 77 |
(+ (* (- 1130 (* 836 ,r)) (expt ,h 2)) |
| 78 |
(* (+ (- 315) (* 44 ,r)) ,h) |
| 79 |
(- 2427 (* 127 ,r))) |
| 80 |
)) |
| 81 |
|
| 82 |
|
| 83 |
;--------------------------------------------------------------------------- |
| 84 |
; FORM4: converts p-h-r articulators to fourth formant frequency |
| 85 |
;--------------------------------------------------------------------------- |
| 86 |
(defmacro form4 (p h r) |
| 87 |
`(+ (* (+ (* (+ (- 1120) (* 16 ,r)) (expt ,h 2)) |
| 88 |
(* (- 1696 (* 180 ,r)) ,h) |
| 89 |
(+ 500 (* 522 ,r))) |
| 90 |
(expt ,p 2)) |
| 91 |
|
| 92 |
(* (+ (* (+ (- 140) (* 240 ,r)) (expt ,h 2)) |
| 93 |
(* (+ (- 578) (* 214 ,r)) ,h) |
| 94 |
(- (- 692) (* 419 ,r))) |
| 95 |
,p) |
| 96 |
|
| 97 |
(+ (* (- 1480 (* 602 ,r)) (expt ,h 2)) |
| 98 |
(* (+ (- 1220) (* 289 ,r)) ,h) |
| 99 |
(- 3678 (* 178 ,r))) |
| 100 |
)) |
| 101 |
|
| 102 |
;--------------------------------------------------------------------------- |
| 103 |
; ADSR-SMOOTH: a standard ADSR envelope |
| 104 |
;--------------------------------------------------------------------------- |
| 105 |
(defun adsr-smooth (signal dur) |
| 106 |
(mult signal (env 0.1 0.2 0.5 1.0 0.8 0.4 dur))) |
| 107 |
;--------------------------------------------------------------------------- |
| 108 |
; VIBRATO: generates vibrato |
| 109 |
; vib-rate = vibrato rate in Hz |
| 110 |
; dur = duration in seconds |
| 111 |
;--------------------------------------------------------------------------- |
| 112 |
(defun vibrato (vib-rate dur) |
| 113 |
(osc (hz-to-step vib-rate) dur)) |
| 114 |
|
| 115 |
;--------------------------------------------------------------------------- |
| 116 |
; PULSE-TABLE: build table for generating a pulse signal |
| 117 |
; harm = number of harmonics |
| 118 |
;--------------------------------------------------------------------------- |
| 119 |
(defun pulse-table (harm) |
| 120 |
(abs-env ;prevent any timewarping in the following |
| 121 |
(let ((table (build-harmonic 1 2048))) |
| 122 |
(cond ((> harm 1) ;sum remaining harmonics |
| 123 |
(setf harm (- harm 1)) |
| 124 |
(dotimes (i harm) |
| 125 |
(setf table (sum table (build-harmonic (1+ i) 2048)))))) |
| 126 |
table))) |
| 127 |
|
| 128 |
;--------------------------------------------------------------------------- |
| 129 |
; PULSE-WITH-VIBRATO: generate pulse with vibrato |
| 130 |
; step = pitch in steps |
| 131 |
; duration = duration in seconds |
| 132 |
; vib-rate = vibrato rate in Hz |
| 133 |
;--------------------------------------------------------------------------- |
| 134 |
(defun pulse-with-vibrato (step duration vib-rate) |
| 135 |
(let (harm freq) |
| 136 |
(setf freq (step-to-hz step)) |
| 137 |
(setf harm (truncate (/ 22050 (* 2 freq)))) |
| 138 |
(setf table (scale (/ 1.0 harm) (pulse-table harm))) |
| 139 |
(fmosc step (vibrato vib-rate duration) (list table (hz-to-step 1) t)))) |
| 140 |
|
| 141 |
;--------------------------------------------------------------------------- |
| 142 |
; VOICING-SOURCE: generate voicing source: pulse with vibrato + LPFs |
| 143 |
; step = pitch in steps |
| 144 |
; duration = duration in seconds |
| 145 |
; vib-rate = vibrato rate in Hz |
| 146 |
;--------------------------------------------------------------------------- |
| 147 |
(defun voicing-source (step duration vib-rate) |
| 148 |
(lp |
| 149 |
(lp |
| 150 |
(pulse-with-vibrato step duration vib-rate) |
| 151 |
(* 1.414 (* 2 (step-to-hz step)))) |
| 152 |
(* 1.414 (* 4 (step-to-hz step))))) |
| 153 |
|
| 154 |
;--------------------------------------------------------------------------- |
| 155 |
; NOISE-SOURCE: generate noise source: noise + offset oscillator + LPF |
| 156 |
; step = pitch in steps |
| 157 |
; duration = duration in seconds |
| 158 |
; vib-rate = vibrato rate in Hz |
| 159 |
;--------------------------------------------------------------------------- |
| 160 |
(defun noise-source (step duration vib-rate) |
| 161 |
(lp |
| 162 |
(sum |
| 163 |
(noise duration) |
| 164 |
(fmosc step (vibrato vib-rate duration))) 8000)) |
| 165 |
|
| 166 |
;--------------------------------------------------------------------------- |
| 167 |
; SOURCE: generate source signal: voicing + noise sources |
| 168 |
; freq = fundamental frequency in Hz |
| 169 |
; duration = duration in seconds |
| 170 |
; vib-rate = vibrato rate in Hz |
| 171 |
; voicing-scale = percentage of voicing in the resulting signal (0.0 -> 1.0) |
| 172 |
; noise-scale = percentage of noise in the resulting signal (0.0 -> 1.0) |
| 173 |
;--------------------------------------------------------------------------- |
| 174 |
(defun source (freq duration vib-rate voicing-scale noise-scale) |
| 175 |
(sum |
| 176 |
(scale voicing-scale (voicing-source (hz-to-step freq) duration vib-rate)) |
| 177 |
(scale noise-scale (noise-source (hz-to-step freq) duration vib-rate)))) |
| 178 |
|
| 179 |
|
| 180 |
;--------------------------------------------------------------------------- |
| 181 |
; MAKE-SPECTRUM: formant filters |
| 182 |
; freq = fundamental frequency in Hz |
| 183 |
; dur = duration in seconds |
| 184 |
; vib-rate = vibrato rate in Hz |
| 185 |
; v-scale = amplitude scaling for the voicing source |
| 186 |
; n-scale = amplitude scaling for the noise source |
| 187 |
; p = horizontal position of the tongue (0.0 = front -> 1.0 = back) |
| 188 |
; h = vertical position of the tongue (0.0 = low -> 1.0 = high) |
| 189 |
; r = rouding of the lips (0.0 = spread -> 1.0 = rounded) |
| 190 |
;--------------------------------------------------------------------------- |
| 191 |
(defun make-spectrum (freq dur vib-rate v-scale n-scale p h r) |
| 192 |
(let ((src (source freq dur vib-rate v-scale n-scale))) |
| 193 |
(setf spectrum |
| 194 |
(sim |
| 195 |
(reson src (form1 p h r) 50 1) |
| 196 |
(reson (scale-db (- 10) src) (form2 p h r) 70 1) |
| 197 |
(reson (scale-db (- 14) src) (form3 p h r) 110 1) |
| 198 |
(reson (scale-db (- 20) src) (form4 p h r) 250 1))))) |
| 199 |
|
| 200 |
;--------------------------------------------------------------------------- |
| 201 |
; SYNTHESISE: the synthesise function |
| 202 |
; Simplified version of the instrument used by the agents discussed in Chapter 6. |
| 203 |
; f0 = pitch frequency |
| 204 |
; w1 = amplitude of voicing source (min = 0.0 max = 1.0) |
| 205 |
; w2 = amplitude of noise source (min = 0.0 max = 1.0) |
| 206 |
; a = horizontal position of the tongue (0.0 = front -> 1.0 = back) |
| 207 |
; b = vertical position of the tongue (0.0 = low -> 1.0 = high) |
| 208 |
; c = rouding of the lips (0.0 = spread -> 1.0 = rounded) |
| 209 |
; fm = vibrato rate (in Hz) |
| 210 |
; h = duration in seconds |
| 211 |
;--------------------------------------------------------------------------- |
| 212 |
(defun synthesise (f0 w1 w2 a b c fm h) |
| 213 |
(adsr-smooth (make-spectrum f0 h fm w1 w2 a b c) h)) |
| 214 |
|
| 215 |
;=== The code for the instrument ends here === |
| 216 |
|
| 217 |
;--------------------------------------------------------------------------- |
| 218 |
; Test the SYNTHESISE function with different positions of the articulators |
| 219 |
; |
| 220 |
; Running steps: |
| 221 |
; 1 - run Nyquist |
| 222 |
; 2 - load "articulator.lsp" |
| 223 |
; 3 - type (play (vowel-1)) to synthesise the first test, and so on |
| 224 |
;--------------------------------------------------------------------------- |
| 225 |
(defun vowel-1 () |
| 226 |
(synthesise 220 1.0 0.005 0.0 0.0 0.0 5.6 1.0)) |
| 227 |
|
| 228 |
(defun vowel-2 () |
| 229 |
(synthesise 220 1.0 0.005 0.0 0.0 1.0 5.6 1.0)) |
| 230 |
|
| 231 |
(defun vowel-3 () |
| 232 |
(synthesise 220 1.0 0.005 0.5 0.0 0.0 5.6 1.0)) |
| 233 |
|
| 234 |
(defun vowel-4 () |
| 235 |
(synthesise 220 1.0 0.005 0.5 0.0 1.0 5.6 1.0)) |
| 236 |
|
| 237 |
(defun vowel-5 () |
| 238 |
(synthesise 220 1.0 0.005 1.0 0.0 0.0 5.6 1.0)) |
| 239 |
|
| 240 |
(defun vowel-6 () |
| 241 |
(synthesise 220 1.0 0.005 1.0 0.0 1.0 5.6 1.0)) |
| 242 |
|
| 243 |
(defun vowel-7 () |
| 244 |
(synthesise 220 1.0 0.005 0.0 0.5 0.0 5.6 1.0)) |
| 245 |
|
| 246 |
(defun vowel-8 () |
| 247 |
(synthesise 220 1.0 0.005 0.0 0.5 1.0 5.6 1.0)) |
| 248 |
|
| 249 |
(defun vowel-9 () |
| 250 |
(synthesise 220 1.0 0.005 0.5 0.5 0.0 5.6 1.0)) |
| 251 |
|
| 252 |
(defun vowel-10 () |
| 253 |
(synthesise 220 1.0 0.005 0.5 0.5 1.0 5.6 1.0)) |
| 254 |
|
| 255 |
(defun vowel-11 () |
| 256 |
(synthesise 220 1.0 0.005 1.0 0.5 0.0 5.6 1.0)) |
| 257 |
|
| 258 |
(defun vowel-12 () |
| 259 |
(synthesise 220 1.0 0.005 1.0 0.5 1.0 5.6 1.0)) |
| 260 |
|
| 261 |
(defun vowel-13 () |
| 262 |
(synthesise 220 1.0 0.005 0.0 1.0 0.0 5.6 1.0)) |
| 263 |
|
| 264 |
(defun vowel-14 () |
| 265 |
(synthesise 220 1.0 0.005 0.0 1.0 1.0 5.6 1.0)) |
| 266 |
|
| 267 |
(defun vowel-15 () |
| 268 |
(synthesise 220 1.0 0.005 0.5 1.0 0.0 5.6 1.0)) |
| 269 |
|
| 270 |
(defun vowel-16 () |
| 271 |
(synthesise 220 1.0 0.005 0.5 1.0 1.0 5.6 1.0)) |
| 272 |
|
| 273 |
(defun vowel-17 () |
| 274 |
(synthesise 220 1.0 0.005 1.0 1.0 0.0 5.6 1.0)) |
| 275 |
|
| 276 |
(defun vowel-18 () |
| 277 |
(synthesise 220 1.0 0.005 1.0 1.0 1.0 5.6 1.0)) |
| 278 |
|
| 279 |
;; play everything |
| 280 |
(defun vowel-n (n) (funcall (intern (format nil "VOWEL-~A" n)))) |
| 281 |
|
| 282 |
(defun play-all-vowels () |
| 283 |
(autonorm-off) |
| 284 |
(dotimes (i 18) (play (scale 20 (vowel-n (1+ i))))) |
| 285 |
(autonorm-on)) |
| 286 |
|
| 287 |
; (play-all-vowels) will play everything in sequence |
| 288 |
</pre> |
| 289 |
</body> |
| 290 |
</html> |