(FILECREATED " 4-Aug-84 18:49:04" {ERIS}<SPEECH>HANDSY.FPKG;22 5630   

      changes to:  (FNS SPEECH.INIT)

      previous date: "13-Jul-84 02:49:37" {ERIS}<SPEECH>HANDSY.FPKG;21)


(* Copyright (c) 1984 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT HANDSYCOMS)

(RPAQQ HANDSYCOMS ((FNS SPEECH.INIT SPEECH.TEST SPEECH.SHORTCUT SPEECH.PLAY SPEECH.DISPLAY.FILE 
			SPEECH.DISPLAY.FILE.REPAINTFN)
		   (INITVARS (SPEECH.*MEMORY* NIL)
			     (SPEECH.*PARAM* NIL)
			     (SPEECH.*COEFF* NIL)
			     (SPEECH.*WAVE* NIL))))
(DEFINEQ

(SPEECH.INIT
  [LAMBDA (ASIZE NEWFLG TRACED.SIGNAL)                       (* pkh: " 3-Aug-84 11:59")
    (PROG NIL
          [COND
	    ((OR NEWFLG (NULL SPEECH.*MEMORY*))
	      (SETQ SPEECH.*MEMORY* (SPEECH.CREATE.MEMORY]
          [COND
	    ((OR NEWFLG (NULL SPEECH.*COEFF*))
	      (SETQ SPEECH.*COEFF* (SPEECH.CREATE.COEFF]
          [COND
	    ((OR NEWFLG (NULL SPEECH.*WAVE*))
	      (SETQ SPEECH.*WAVE* (ARRAY (COND
					   (ASIZE ASIZE)
					   (T 40000))
					 'POINTER 0]
          (SCOPE.SETUP -128 128 NEWFLG)
          (USER.INIT NEWFLG)
          (ATTACHWINDOW USER.WINDOW SCOPE.WINDOW 'TOP 'JUSTIFY)
          (SPEECH.SR 10000)
          (SETQ SPEECH.*PVECTOR* (SPEECH.CREATE.PVECTOR))
          (SPEECH.INIT.COEFF SPEECH.*PVECTOR* SPEECH.*COEFF*)
          (SPEECH.INIT.MEMORY SPEECH.*MEMORY*)
          (SPEECH.TRACE (COND
			  (TRACED.SIGNAL TRACED.SIGNAL)
			  (T 'OUTPUT])

(SPEECH.TEST
  [LAMBDA (TESTEND)                                          (* pkh: " 2-Jul-84 19:28")
    (PROG [(ENDPOINT (MIN (ARRAYSIZE SPEECH.*WAVE*)
			  (USER.DURATION USER.TRAJS)
			  (COND
			    ((FIXP TESTEND)
			      TESTEND)
			    (T (MIN]
          (SCALED.WINDOW.CLEARW SCOPE.WINDOW)
          (WINDOWPROP SCOPE.WINDOW 'FILE SPEECH.*WAVE*)
          (SETQ SCOPE.U 0)
          (SPEECH.INIT.COEFF SPEECH.*PVECTOR* SPEECH.*COEFF*)
          (SPEECH.INIT.MEMORY SPEECH.*MEMORY*)
          (for (OFFSET ← 0) by (IPLUS OFFSET NWS) while (ILESSP OFFSET ENDPOINT)
	     do (USER.INTERPOLATE SPEECH.*PVECTOR* OFFSET USER.TRAJS)
		(SPEECH.PVECTOR.TO.COEFF SPEECH.*PVECTOR* SPEECH.*COEFF*)
		(SPEECH.COEFF.TO.WAVE SPEECH.*MEMORY* SPEECH.*COEFF* SPEECH.*WAVE* OFFSET NWS])

(SPEECH.SHORTCUT
  [LAMBDA (ARRAYSIZE)                                        (* pkh: " 2-Jul-84 18:56")
    (PROG (PERIOD)
          (SETQ SPEECH.*WAVE* (ARRAY (COND
				       (ARRAYSIZE ARRAYSIZE (T 40000)))
				     'POINTER 0))
          (SCOPE.CLEAR)
          (SPEECH.INIT.COEFF SPEECH.*PVECTOR* SPEECH.*COEFF*)
          (SPEECH.INIT.MEMORY SPEECH.*MEMORY*)               (* Make sure we associate the array where the resulting 
							     wave is put with the SCOPE window)
          (WINDOWPROP SCOPE.WINDOW 'FILE SPEECH.*WAVE*)      (* PERIOD = glottal period. *)
          (SETQ PERIOD (IQUOTIENT SR (fetch (PVECTOR F0) of SPEECH.*PVECTOR*)))
          (for (OFFSET ← 0) by (IPLUS OFFSET PERIOD) as I from 1 to 4
	     do (SPEECH.PVECTOR.TO.COEFF SPEECH.*PVECTOR* SPEECH.*COEFF*)
		(SPEECH.COEFF.TO.WAVE SPEECH.*MEMORY* SPEECH.*COEFF* SPEECH.*WAVE* OFFSET PERIOD))
          (for I from (ITIMES 4 PERIOD) to ARRAYSIZE do (SETA SPEECH.*WAVE* I
							      (ELT SPEECH.*WAVE*
								   (IPLUS (ITIMES 3 PERIOD)
									  (IREMAINDER I PERIOD])

(SPEECH.PLAY
  [LAMBDA NIL                                                (* kbr: "16-May-84 13:49")
    (PROG (STREAM)
          (SETQ STREAM (OPENSTREAM '{CORE}SPEECH.PCM 'OUTPUT 'OLD/NEW))
          (for I from 1 to (ARRAYSIZE SPEECH.*WAVE*) do (BOUT STREAM (ELT SPEECH.*WAVE* I)))
          (CLOSEF STREAM)
          (AUDIO.PLAY.FILE '{CORE}SPEECH.PCM])

(SPEECH.DISPLAY.FILE
  [LAMBDA (FILE PTR)                                         (* pkh: "27-Jun-84 11:50")
                                                             (* Alternative to SPEECH.DISPLAY.FILE for displaying a 
							     waveform; gives you a scrollable window)
    (COND
      ((NULL PTR)
	(SETQ PTR 0)))
    (PROG (STARTX STARTY WIDTH HEIGHT WINDOW)
          (SETQ FILE (FULLNAME FILE 'OLD))
          (SETQ WINDOW (CREATEW NIL FILE))
          (SETQ STARTX (DSPXPOSITION NIL WINDOW))
          (SETQ STARTY (DSPYPOSITION NIL WINDOW))
          (WINDOWPROP WINDOW 'FILE FILE)
          (SCALED.WINDOW.SETUP WINDOW -128 128 30 30 'PRINT.SPEECH.FILE)
          [WINDOWPROP WINDOW 'EXTENT
		      (create REGION
			      LEFT ← STARTX
			      BOTTOM ← STARTY
			      HEIGHT ← -1
			      WIDTH ← (GETFILEINFO FILE 'LENGTH]
          (SCALED.WINDOW.RESHAPEFN WINDOW])

(SPEECH.DISPLAY.FILE.REPAINTFN
  [LAMBDA (WINDOW REGION)                                    (* pkh: "10-Jul-84 22:09")
    (PROG (HEIGHT X Y Y0 STREAM)
          (SETQ HEIGHT (WINDOWPROP WINDOW 'HEIGHT))
          (SETQ Y0 (WINDOWPROP WINDOW 'Y0))
          (SETQ STREAM (OPENSTREAM (WINDOWPROP WINDOW 'FILE)
				   'INPUT
				   'OLD))
          (SETFILEPTR STREAM (REGION.LEFT REGION))
          (while (NOT (EOFP STREAM)) as X from 1 to (REGION.WIDTH REGION)
	     do (SETQ Y (\BIN STREAM))
		[COND
		  ((ILESSP Y 128)
		    (SETQ Y (IPLUS Y 128)))
		  (T (SETQ Y (IDIFFERENCE 256 Y]
		(SETQ Y (IQUOTIENT (ITIMES HEIGHT Y)
				   255))
		(DRAWLINE X Y0 X Y 1 'PAINT WINDOW))
          (CLOSEF STREAM])
)

(RPAQ? SPEECH.*MEMORY* NIL)

(RPAQ? SPEECH.*PARAM* NIL)

(RPAQ? SPEECH.*COEFF* NIL)

(RPAQ? SPEECH.*WAVE* NIL)
(PUTPROPS HANDSY.FPKG COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (545 5420 (SPEECH.INIT 555 . 1457) (SPEECH.TEST 1459 . 2259) (SPEECH.SHORTCUT 2261 . 
3386) (SPEECH.PLAY 3388 . 3769) (SPEECH.DISPLAY.FILE 3771 . 4676) (SPEECH.DISPLAY.FILE.REPAINTFN 4678
 . 5418)))))
STOP