(FILECREATED "15-JUN-84 16:56:51" {ERIS}<SPEECH>AUDIO.FPKG;1 9575   

      changes to:  (RECORDS AUDIOBLK)
		   (FNS AUDIO.RESET AUDIO.INIT AUDIO.PLAY.FILE AUDIO.PLAY.ARRAY AUDIO.REPEAT.ARRAY 
			AUDIO.RECORD DEFAULTRECORDONFN \AUDIO))


(PRETTYCOMPRINT AUDIOCOMS)

(RPAQQ AUDIOCOMS [(PROPS (PAGEOFFSET MACRO)
			 (ZEROPAGEOFFSET MACRO)
			 (.AUDIO. DOPVAL))
		  (INITVARS (AUDIO.BUFFER NIL)
			    (AUDIO.BUFFER.SIZE 9)
			    (DEFAULTRECORDONFNCLK NIL))
		  (RECORDS AUDIOBLK)
		  (FNS AUDIO.RESET AUDIO.INIT AUDIO.PLAY.FILE AUDIO.PLAY.ARRAY AUDIO.REPEAT.ARRAY 
		       AUDIO.RECORD DEFAULTRECORDONFN \AUDIO)
		  (P (OR AUDIO.BUFFER (AUDIO.INIT))
		     (COND ([NOT (CCODEP (GETD '\AUDIO]
			    (COMPILE '\AUDIO])

(PUTPROPS PAGEOFFSET MACRO ((BASE NPAGES)
			    (\ADDBASE BASE (LLSH NPAGES 8))))

(PUTPROPS ZEROPAGEOFFSET MACRO [OPENLAMBDA (B P)
					   (PROG (PP)
					         (SETQ PP (LLSH P 8))
					         (\ZEROWORDS (\ADDBASE B PP)
							     (\ADDBASE B (IPLUS PP 255])

(PUTPROPS .AUDIO. DOPVAL (1 AUDIO))

(RPAQ? AUDIO.BUFFER NIL)

(RPAQ? AUDIO.BUFFER.SIZE 9)

(RPAQ? DEFAULTRECORDONFNCLK NIL)
[DECLARE: EVAL@COMPILE 

(BLOCKRECORD AUDIOBLK ((OUT0 WORD)
		       (OUTN WORD)
		       (MCPAGE BYTE)
		       (MCWORD BYTE)
		       (INDELTA WORD)))
]
(DEFINEQ

(AUDIO.RESET
  [LAMBDA NIL                                                (* edited: "15-JUN-84 16:56")
    (PROG (N)
          (SETQ N (SUB1 (ITIMES 256 AUDIO.BUFFER.SIZE)))
          (\ZEROWORDS AUDIO.BUFFER (\ADDBASE AUDIO.BUFFER N))
          (replace (AUDIOBLK OUT0) of AUDIO.BUFFER with 256)
          (replace (AUDIOBLK OUTN) of AUDIO.BUFFER with N)
          (replace (AUDIOBLK MCPAGE) of AUDIO.BUFFER with 1)
          (replace (AUDIOBLK MCWORD) of AUDIO.BUFFER with 0)
          (replace (AUDIOBLK INDELTA) of AUDIO.BUFFER with 0])

(AUDIO.INIT
  [LAMBDA NIL                                                (* edited: "15-JUN-84 16:56")
    (PROG NIL
          (SETQ AUDIO.BUFFER (\VAG2 63 0))
          (FOR I FROM 0 TO (SUB1 AUDIO.BUFFER.SIZE) DO (\NEWPAGE (PAGEOFFSET AUDIO.BUFFER I)))
          (\LOCKPAGES AUDIO.BUFFER AUDIO.BUFFER.SIZE)
          (AUDIO.RESET])

(AUDIO.PLAY.FILE
  [LAMBDA (FILE)                                             (* edited: "15-JUN-84 16:56")
                                                             (* Play FILE. For good results%, FILE should be on 
							     {CORE}. *)
    (PROG (STREAM FILEPN MYPTR PAGECOUNT)
          (SETQ STREAM (OPENSTREAM FILE 'INPUT))
          (AUDIO.RESET)
          (SETQ PAGECOUNT (IQUOTIENT (IPLUS (GETEOFPTR STREAM)
					    511)
				     512))
          [COND
	    ((IGREATERP PAGECOUNT AUDIO.BUFFER.SIZE)
	      (\READPAGES STREAM (SUB1 PAGECOUNT)
			  (PAGEOFFSET AUDIO.BUFFER 1))       (* cause entire page map to be created.)
	      (SETQ FILEPN (SUB1 AUDIO.BUFFER.SIZE))
	      (SETQ MYPTR 1))
	    (T (SETQ FILEPN PAGECOUNT)
	       (SETQ MYPTR (ADD1 PAGECOUNT]
          (FOR I TO FILEPN DO (\READPAGES STREAM (SUB1 I)
					  (PAGEOFFSET AUDIO.BUFFER I)))
          [RESETFORM (\AUDIO AUDIO.BUFFER)
		     [FOR F FROM FILEPN TO (SUB1 PAGECOUNT)
			DO (WHILE (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
			   (\READPAGES STREAM F (PAGEOFFSET AUDIO.BUFFER MYPTR))
			   (COND
			     ((EQ MYPTR (SUB1 AUDIO.BUFFER.SIZE))
			       (SETQ MYPTR 1))
			     (T (SETQ MYPTR (ADD1 MYPTR]
		     (WHILE (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
                                                             (* Zero one last page and turn off ucode when it gets 
							     there)
		     (ZEROPAGEOFFSET AUDIO.BUFFER MYPTR)
		     (UNTIL (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER]
          (CLOSEF STREAM])

(AUDIO.PLAY.ARRAY
  [LAMBDA (ARRAY)                                            (* edited: "15-JUN-84 16:56")
                                                             (* Play ARRAY. ARRAY type BYTE origin 0.0 *)
    (PROG (BASE FILEPN MYPTR PAGECOUNT)
          (SETQ BASE (ARRAYP.BASE ARRAY))
          (AUDIO.RESET)
          (SETQ PAGECOUNT (IQUOTIENT (IPLUS (ARRAYSIZE ARRAY)
					    511)
				     512))
          [COND
	    ((IGREATERP PAGECOUNT AUDIO.BUFFER.SIZE)
	      (\MOVEWORDS (PAGEOFFSET BASE (SUB1 PAGECOUNT))
			  0
			  (PAGEOFFSET AUDIO.BUFFER 1)
			  0 256)                             (* cause entire page map to be created.)
	      (SETQ FILEPN (SUB1 AUDIO.BUFFER.SIZE))
	      (SETQ MYPTR 1))
	    (T (SETQ FILEPN PAGECOUNT)
	       (SETQ MYPTR (ADD1 PAGECOUNT]
          (FOR I TO FILEPN DO (\MOVEWORDS (PAGEOFFSET BASE (SUB1 I))
					  0
					  (PAGEOFFSET AUDIO.BUFFER I)
					  0 256))
          (RESETFORM (\AUDIO AUDIO.BUFFER)
		     [FOR F FROM FILEPN TO (SUB1 PAGECOUNT)
			DO (WHILE (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
			   (\MOVEWORDS (PAGEOFFSET BASE F)
				       0
				       (PAGEOFFSET AUDIO.BUFFER MYPTR)
				       0 256)
			   (COND
			     ((EQ MYPTR (SUB1 AUDIO.BUFFER.SIZE))
			       (SETQ MYPTR 1))
			     (T (SETQ MYPTR (ADD1 MYPTR]
		     (WHILE (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
                                                             (* Zero one last page and turn off ucode when it gets 
							     there)
		     (ZEROPAGEOFFSET AUDIO.BUFFER MYPTR)
		     (UNTIL (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER])

(AUDIO.REPEAT.ARRAY
  [LAMBDA (ARRAY)                                            (* edited: "15-JUN-84 16:56")
                                                             (* Play ARRAY. ARRAY type BYTE origin 0.0 *)
    (PROG (BASE FILEPN MYPTR PAGECOUNT)
          (SETQ BASE (ARRAYP.BASE ARRAY))
          (AUDIO.RESET)
          (SETQ PAGECOUNT (IQUOTIENT (IPLUS (ARRAYSIZE ARRAY)
					    511)
				     512))
          [COND
	    ((IGREATERP PAGECOUNT AUDIO.BUFFER.SIZE)
	      (\MOVEWORDS (PAGEOFFSET BASE (SUB1 PAGECOUNT))
			  0
			  (PAGEOFFSET AUDIO.BUFFER 1)
			  0 256)                             (* cause entire page map to be created.)
	      (SETQ FILEPN (SUB1 AUDIO.BUFFER.SIZE))
	      (SETQ MYPTR 1))
	    (T (SETQ FILEPN PAGECOUNT)
	       (SETQ MYPTR (ADD1 PAGECOUNT]
          (FOR I TO FILEPN DO (\MOVEWORDS (PAGEOFFSET BASE (SUB1 I))
					  0
					  (PAGEOFFSET AUDIO.BUFFER I)
					  0 256))
          (RESETFORM (\AUDIO AUDIO.BUFFER)
		     [FOR F FROM FILEPN TO (SUB1 PAGECOUNT)
			DO (WHILE (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
			   (\MOVEWORDS (PAGEOFFSET BASE F)
				       0
				       (PAGEOFFSET AUDIO.BUFFER MYPTR)
				       0 256)
			   (COND
			     ((EQ MYPTR (SUB1 AUDIO.BUFFER.SIZE))
			       (SETQ MYPTR 1))
			     (T (SETQ MYPTR (ADD1 MYPTR]
		     (DO (FOR F FROM 1 TO (SUB1 PAGECOUNT)
			    DO (WHILE (EQ MYPTR (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
			       (\MOVEWORDS (PAGEOFFSET BASE F)
					   0
					   (PAGEOFFSET AUDIO.BUFFER MYPTR)
					   0 256)
			       (COND
				 ((EQ MYPTR (SUB1 AUDIO.BUFFER.SIZE))
				   (SETQ MYPTR 1))
				 (T (SETQ MYPTR (ADD1 MYPTR])

(AUDIO.RECORD
  [LAMBDA (FILE NSEC RECORDONFN)                             (* edited: "15-JUN-84 16:56")
    (COND
      ((NULL NSEC)
	(SETQ NSEC 5)))
    [COND
      ((NULL RECORDONFN)
	(SETQ RECORDONFN 'DEFAULTRECORDONFN]
    (PROG (STREAM COP)
          (SETQ STREAM (OPENSTREAM FILE 'OUTPUT))
          (AUDIO.RESET)
          (SETQ COP 1)
          (OR (EQ NSEC T)
	      (\TRUNCATEFILE STREAM (ITIMES 16 NSEC)
			     0))                             (* Preallocate space)
          (APPLY* RECORDONFN T)                              (* Wait for user to tell you to start)
          [RESETFORM (\AUDIO AUDIO.BUFFER)
		     (FOR F FROM 0 WHILE (APPLY* RECORDONFN NIL)
			DO (WHILE (EQ COP (fetch (AUDIOBLK MCPAGE) of AUDIO.BUFFER)))
			   (\WRITEPAGES STREAM F (PAGEOFFSET AUDIO.BUFFER COP))
			   (ZEROPAGEOFFSET AUDIO.BUFFER COP)
			   [COND
			     ((EQ COP (SUB1 AUDIO.BUFFER.SIZE))
			       (SETQ COP 1))
			     (T (SETQ COP (ADD1 COP]
			FINALLY (SETQ COP (LLSH F 9]
          (\SETEOFPTR STREAM COP)
          (CLOSEF FILE])

(DEFAULTRECORDONFN
  [LAMBDA (STARTP)
    (DECLARE (GLOBALVARS DEFAULTRECORDONFNCLK))              (* edited: "15-JUN-84 16:56")
    (PROG NIL
          (COND
	    (STARTP (PROMPTPRINT "Press and hold CTRL key to record.")
		    (UNTIL (KEYDOWNP 'CTRL))
		    (PROMPTPRINT "Recording in progress...")
		    (SETQ DEFAULTRECORDONFNCLK (CLOCK)))
	    ((KEYDOWNP 'CTRL)                                (* Continue to record. *)
	      (RETURN T))
	    (T (PROMPTPRINT "Recording complete. Duration: ")
	       (PRINTOUT PROMPTWINDOW (FQUOTIENT (CLOCKDIFFERENCE DEFAULTRECORDONFNCLK)
						 1000.0))
	       " seconds." T])

(\AUDIO
  [LAMBDA (BUF)                                              (* edited: "15-JUN-84 16:56")
                                                             (* Any odd pointer turns off the audio ucode)
    (OR (.AUDIO. (OR BUF (\ADDBASE AUDIO.BUFFER 1)))
	(SHOULDNT "No audio microcode"))
    (\ADDBASE AUDIO.BUFFER 1])
)
(OR AUDIO.BUFFER (AUDIO.INIT))
[COND ([NOT (CCODEP (GETD '\AUDIO]
       (COMPILE '\AUDIO]
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1306 9462 (AUDIO.RESET 1316 . 1925) (AUDIO.INIT 1927 . 2288) (AUDIO.PLAY.FILE 2290 . 
3933) (AUDIO.PLAY.ARRAY 3935 . 5645) (AUDIO.REPEAT.ARRAY 5647 . 7384) (AUDIO.RECORD 7386 . 8479) (
DEFAULTRECORDONFN 8481 . 9123) (\AUDIO 9125 . 9460)))))
STOP