(FILECREATED "31-Jul-84 09:39:48" {ERIS}<SPEECH>HALVORSEN>BUFFER.FPKG;1 6478   

      changes to:  (FNS SPEECH.GLUE)

      previous date: "30-May-84 11:21:51" {PHYLUM}<SPEECH>BUFFER.FPKG;1)


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

(PRETTYCOMPRINT BUFFERCOMS)

(RPAQQ BUFFERCOMS ((RECORDS SPOINT2 SPOINT)
		   (FNS SPEECH.GLUE SPEECH.OVERLAY SPEECH.OVERLAY1 SPEECH.INTERPOLATE)))
[DECLARE: EVAL@COMPILE 

(RECORD SPOINT2 (TIME VALUE))

(RECORD SPOINT (TIME VALUE M B))
]
(DEFINEQ

(SPEECH.GLUE
  [LAMBDA (C1 V C2)                                          (* pkh: "30-Jul-84 17:05")
    (PROG (DEFAULT DELTA TRAJ ANSWER)
          [SETQ ANSWER (create PVECTOR
			       TYPE ← 'TRAJ
			       SOUND ← (PACK* (fetch (PVECTOR SOUND) of C1)
					      (fetch (PVECTOR SOUND) of V)
					      (fetch (PVECTOR SOUND) of C2))
			       CV ← 'CVC
			       COMMENT ← `

          (* Concatenation of (\COMMA (fetch (PVECTOR SOUND) of C1)) (\COMMA (fetch (PVECTOR SOUND) of V)) 
	  (\COMMA (fetch (PVECTOR SOUND) of C2)) *)

]
          [for PNAME in PVECTOR.PNAMES
	     do (SETQ DEFAULT (PVECTOR.GET PVECTOR.DEFAULT PNAME))
		(PVECTOR.PUT ANSWER PNAME (LIST (create SPOINT2
							TIME ← 0
							VALUE ← DEFAULT)
						(create SPOINT2
							TIME ← 700
							VALUE ← DEFAULT]
          (SPEECH.OVERLAY ANSWER V)
          (SPEECH.OVERLAY ANSWER C1)                         (* Adjust C2 to begin at the logic end of V.
							     *)
          (SETQ C2 (COPYALL C2))
          (SETQ DELTA (IDIFFERENCE [fetch (SPOINT TIME) of (CAR (LAST (PVECTOR.GET V 'AV]
				   400))
          [for PNAME in PVECTOR.PNAMES
	     do (SETQ TRAJ (PVECTOR.GET C2 PNAME))
		(for POINT in TRAJ when (NOT (IEQP (fetch (SPOINT TIME) of POINT)
						   700))
		   do (replace (SPOINT TIME) of POINT with (IPLUS (fetch (SPOINT TIME) of POINT)
								  DELTA]
                                                             (* Now overlay C2. *)
          (SPEECH.OVERLAY ANSWER C2)
          (RETURN ANSWER])

(SPEECH.OVERLAY
  (LAMBDA (BUFFER S)                                         (* pkh: "30-May-84 11:21")
                                                             (* Overlay BUFFER with segment S.
							     *)
    (PROG NIL
          (FOR PNAME IN PVECTOR.PNAMES WHEN (NOT (EQ PNAME 'SWITCH)) DO (SPEECH.OVERLAY1 BUFFER S 
											 PNAME)))))

(SPEECH.OVERLAY1
  (LAMBDA (BUFFER S PNAME)                                   (* pkh: "30-May-84 11:21")
                                                             (* Overlay BUFFER PNAME traj with S PNAME traj.
							     *)
    (PROG (BTRAJ STRAJ BTIME ETIME TRAJ)
          (SETQ BTRAJ (PVECTOR.GET BUFFER PNAME))
          (SETQ STRAJ (PVECTOR.GET S PNAME))
          (COND
	    ((NULL STRAJ)
	      (RETURN)))
          (SETQ BPOINT (CAR STRAJ))
          (SETQ EPOINT (CAR (LAST STRAJ)))
          (SETQ BTIME (fetch (SPOINT TIME) of BPOINT))
          (SETQ ETIME (fetch (SPOINT TIME) of EPOINT))       (* Points before overlay. *)
          (FOR POINT IN BTRAJ WHILE (ILESSP (fetch (SPOINT TIME) of POINT)
					    (SUB1 BTIME))
	     DO (PUSH TRAJ POINT))                           (* Discontinuity *)
          (COND
	    ((AND (NOT (IEQP BTIME 0))
		  (OR (NULL (fetch (SPOINT M) of BPOINT))
		      (NOT (FEQP (fetch (SPOINT M) of BPOINT)
				 1.0))
		      (NOT (FEQP (fetch (SPOINT B) of BPOINT)
				 0.0))))
	      (PUSH TRAJ (CREATE SPOINT2
				 TIME ←(SUB1 BTIME)
				 VALUE ←(SPEECH.INTERPOLATE BTRAJ (SUB1 BTIME))))))
                                                             (* Overlaying points. *)
          (FOR POINT IN STRAJ DO (COND
				   ((NULL (fetch (SPOINT M) of POINT))
                                                             (* No equation. *)
				     (PUSH TRAJ POINT))
				   (T                        (* Equation *)
				      (SETQ VALUE (SPEECH.INTERPOLATE BTRAJ (fetch (SPOINT TIME)
									       of POINT)))
				      (SETQ VALUE (FPLUS (FTIMES (fetch (SPOINT M) of POINT)
								 VALUE)
							 (fetch (SPOINT B) of POINT)))
				      (PUSH TRAJ (CREATE SPOINT2
							 TIME ←(fetch (SPOINT TIME) of POINT)
							 VALUE ← VALUE)))))
                                                             (* Discontinuity *)
          (COND
	    ((AND (NOT (IEQP ETIME 700))
		  (OR (NULL (fetch (SPOINT M) of EPOINT))
		      (NOT (FEQP (fetch (SPOINT M) of EPOINT)
				 1.0))
		      (NOT (FEQP (fetch (SPOINT B) of EPOINT)
				 0.0))))
	      (PUSH TRAJ (CREATE SPOINT2
				 TIME ←(ADD1 ETIME)
				 VALUE ←(SPEECH.INTERPOLATE BTRAJ (ADD1 ETIME))))))
                                                             (* Points after overlay. *)
          (FOR POINT IN BTRAJ WHEN (IGREATERP (fetch (SPOINT TIME) of POINT)
					      (ADD1 ETIME))
	     DO (PUSH TRAJ POINT))
          (SETQ TRAJ (DREVERSE TRAJ))
          (PVECTOR.PUT BUFFER PNAME TRAJ))))

(SPEECH.INTERPOLATE
  (LAMBDA (TRAJ TIME)                                        (* pkh: "30-May-84 11:21")
    (PROG (LEFTPOINT RIGHTPOINT LTIME RTIME LVALUE RVALUE K VALUE)
          (FOR L IN TRAJ AS R IN (CDR TRAJ) WHEN (AND (ILEQ (fetch (SPOINT TIME) of L)
							    TIME)
						      (IGEQ (fetch (SPOINT TIME) of R)
							    TIME))
	     DO (SETQ LEFTPOINT L)
		(SETQ RIGHTPOINT R)
		(RETURN))
          (COND
	    ((OR (NULL LEFTPOINT)
		 (NULL RIGHTPOINT))
	      (PRINT '(Interpolation out of range))
	      (SHOULDNT)))
          (SETQ LTIME (fetch (SPOINT TIME) of LEFTPOINT))
          (SETQ RTIME (fetch (SPOINT TIME) of RIGHTPOINT))
          (SETQ LVALUE (fetch (SPOINT VALUE) of LEFTPOINT))
          (SETQ RVALUE (fetch (SPOINT VALUE) of RIGHTPOINT))
          (SETQ K (FQUOTIENT (FDIFFERENCE TIME LTIME)
			     (FDIFFERENCE RTIME LTIME)))
          (SETQ VALUE (FPLUS (FTIMES K RVALUE)
			     (FTIMES (FDIFFERENCE 1.0 K)
				     LVALUE)))
          (RETURN VALUE))))
)
(PUTPROPS BUFFER.FPKG COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (516 6396 (SPEECH.GLUE 526 . 2177) (SPEECH.OVERLAY 2179 . 2564) (SPEECH.OVERLAY1 2566 . 
5321) (SPEECH.INTERPOLATE 5323 . 6394)))))
STOP