home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / narrator / full_narrator.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  19KB  |  614 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  ***************************************************************************
  27.  *
  28.  * Full_Narrator.c
  29.  *
  30.  * This example program sends a string of phonetic text to the narrator
  31.  * device and, while it is speaking, highlights, word-by-word, a
  32.  * corresponding English string.  In addition, mouth movements are drawn
  33.  * in a separate window.
  34.  *
  35.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  36.  *
  37.  * Requires Kickstart V37 or greater.
  38.  */
  39.  
  40. #include <exec/types.h>
  41. #include <exec/memory.h>
  42. #include <exec/libraries.h>
  43. #include <dos/dos.h>
  44. #include <intuition/intuition.h>
  45. #include <ctype.h>
  46. #include <exec/exec.h>
  47. #include <fcntl.h>
  48. #include <devices/narrator.h>
  49.  
  50. #include <clib/exec_protos.h>
  51. #include <clib/alib_protos.h>
  52. #include <clib/intuition_protos.h>
  53. #include <clib/graphics_protos.h>
  54. #include <clib/dos_protos.h>
  55.  
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include <stdio.h>
  59.  
  60. #ifdef LATTICE
  61. int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  62. int chkabort(void) { return(0); }  /* really */
  63. #endif
  64.  
  65.  
  66. /*
  67.  *  Due to an omission, the sync field defines were not included in older
  68.  *  versions of the narrator device include files.  So, if they haven't
  69.  *  already been defined, do so now.
  70.  */
  71.  
  72. #ifndef NDF_READMOUTH                        /* Already defined ? */
  73. #define NDF_READMOUTH   0x01                 /* No, define here   */
  74. #define NDF_READWORD    0x02
  75. #define NDF_READSYL     0x04
  76. #endif
  77.  
  78. #define PEN3    3                            /* Drawing pens */
  79. #define PEN2    2
  80. #define PEN1    1
  81. #define PEN0    0
  82.  
  83.  
  84. BOOL FromCLI = TRUE;
  85. BYTE chans[4] = {3, 5, 10, 12};
  86.  
  87.  
  88. LONG EyesLeft;                               /* Left edge of left eye     */
  89. LONG EyesTop;                                /* Top of eyes box           */
  90. LONG EyesBottom;                             /* Bottom of eyes box        */
  91. LONG YMouthCenter;                           /* Pixels from top edge      */
  92. LONG XMouthCenter;                           /* Pixels from left edge     */
  93. LONG LipWidth, LipHeight;                    /* Width and height of mouth */
  94.  
  95.  
  96. struct TextAttr MyFont = {"topaz.font", TOPAZ_SIXTY, FS_NORMAL, FPF_ROMFONT,};
  97.  
  98. extern struct Library   *SysBase;   /* Used to check the OS version number */
  99.  
  100. struct  IntuitionBase   *IntuitionBase = NULL;
  101. struct  GfxBase         *GfxBase = NULL;
  102.  
  103. struct  MsgPort         *VoicePort = NULL;
  104. struct  MsgPort         *MouthPort = NULL;
  105.  
  106. struct  narrator_rb     *VoiceIO = NULL;
  107. struct  mouth_rb        *MouthIO = NULL;
  108.  
  109. struct  IntuiText  HighLight;
  110. struct  NewWindow  NewWindow;
  111. struct  Window    *TextWindow;
  112. struct  Window    *FaceWindow;
  113. struct  RastPort  *FaceRast;
  114.  
  115.  
  116. void main(int argc, char **argv)
  117. {
  118. LONG     i;
  119. LONG     sentence;
  120. LONG     Offset;
  121. LONG     CharsLeft;
  122. LONG     ScreenPos;
  123. LONG     WordLength;
  124. LONG     LineNum;
  125. UBYTE    *Tempptr;
  126. UBYTE    *English;
  127. UBYTE    *OldEnglish;
  128. UBYTE     c;
  129.  
  130. UBYTE    *PhonPtr;              /* Pointer to phonetic text     */
  131. LONG     PhonSize;              /* Size of phonetic text        */
  132. UBYTE    *PhonStart[100];       /* Start of phonetic sentences  */
  133. LONG     NumPhonStarts;         /* Number of phonetic sentences */
  134.  
  135. UBYTE    *EngPtr;               /* Pointer to English text      */
  136. LONG     EngSize;               /* Size of English text         */
  137. UBYTE    *EngStart[100];        /* Start of English sentences   */
  138. LONG     NumEngStarts;          /* Number of English sentences  */
  139.  
  140. UBYTE    *EngLine[24];          /* Start of line on screen      */
  141. LONG     EngBytes[24];          /* Bytes per line on screen     */
  142. LONG     NumEngLines;           /* Number of lines on screen    */
  143.  
  144.  
  145. extern  void  Cleanup(UBYTE *errmsg);
  146. extern  void  ClearWindow(struct Window *TextWindow);
  147. extern  void  DrawFace(void);
  148. extern  void  UpdateFace(void);
  149.  
  150.  
  151. /*
  152.  *  (0)   Note whether the program was started from the CLI or from
  153.  *        Workbench.
  154.  */
  155.  
  156. if (argc == 0)
  157.     FromCLI = FALSE;
  158.  
  159. /*
  160.  *  (1)   Setup the phonetic text to be spoken.  If there are any non-
  161.  *        alphabetic characters in the text (such as NEWLINES or TABS)
  162.  *        replace them with spaces.  Then break up the text into sentences,
  163.  *        storing the start of each sentence in PhonStart array elements.
  164.  */
  165.  
  166. PhonPtr = "KAA1RDIYOWMAYAA5PAXTHIY.  AY /HAED NEH1VER /HER4D AXV IHT "
  167.           "BIXFOH5R, BAHT DHEH5R IHT WAHZ - LIH4STIXD AEZ (DHAX FOH5RM "
  168.           "AXV /HAA5RT DIHZIY5Z) DHAET FEH4LD (NAAT WAH5N OHR TUW5) - "
  169.           "BAHT (AO7L THRIY5 AXV DHAX AA5RTAXFIHSHUL /HAA5RTQ "
  170.           "RIXSIH5PIYINTS).  (AH LIH5TUL RIXSER5CH) PROHDUW5ST (SAHM "
  171.           "IH5NTRIHSTIHNX RIXZAH5LTS). AHKOH5RDIHNX TUW (AEN AA5RTIHKUL "
  172.           "IHN DHAX NOWVEH5MBER EY2THQX NAY5NTIYNEYTIYFOH1R NUW IY5NXGLIND "
  173.           "JER5NUL AXV MEH5DIXSIN), (SIH5GEREHT SMOW5KIHNX) KAO4ZIHZ "
  174.           "(DHIHS LIY5THUL DIHZIY5Z) DHAET WIY4KINZ (DHAX /HAA5RTS "
  175.           "PAH4MPIHNX PAW2ER).  WAYL (DHIY IHGZAE5KT MEH5KINIXZUM) IHZ "
  176.           "NAAT KLIY5R, DAA5KTER AA5RTHER JEY2 /HAARTS SPEH5KYULEYTIHD "
  177.           "DHAET NIH4KAXTIY2N- OHR KAA5RBIN MUNAA5KSAYD IHN DHAX SMOW5K- "
  178.           "SAH5M/HAW1 POY4ZINZ DHAX /HAA5RT, AEND LIY4DZ TUW (/HAA5RT "
  179.           "FEY5LYER).";
  180.  
  181. PhonSize = strlen(PhonPtr);
  182. NumPhonStarts = 0;
  183. PhonStart[NumPhonStarts++] = PhonPtr;
  184. for (i = 0;  i < PhonSize;  ++i)
  185.      {
  186.      if (isspace((int)(c = *PhonPtr++)))
  187.          *(PhonPtr-1) = ' ';
  188.      if ((c == '.') || (c == '?'))
  189.          {
  190.          *PhonPtr = '\0';
  191.          PhonStart[NumPhonStarts++] = ++PhonPtr;
  192.          }
  193.      }
  194.  
  195. /*
  196.  *  (2)  Create the English text corresponding to the phonetic text above.
  197.  *       As before, insure that there are no TABS or NEWLINES in the text.
  198.  *       Break the text up into sentences and store the start of each
  199.  *       sentence in EngStart array elements.
  200.  */
  201.  
  202. EngPtr = "Cardiomyopathy. I had never heard of it before, but there it was "
  203.          "listed as the form of heart disease that felled not one or two but "
  204.          "all three of the artificial heart recipients. A little research "
  205.          "produced some interesting results. According to an article in the "
  206.          "November 8, 1984, New England Journal of Medicine, cigarette smoking "
  207.          "causes this lethal disease that weakens the heart's pumping power.   "
  208.          "While the exact mechanism is not clear, Doctor Arthur J Hartz "
  209.          "speculated that nicotine or carbon monoxide in the smoke somehow "
  210.          "poisons the heart and leads to heart failure.";
  211.  
  212. EngSize = strlen(EngPtr);
  213. NumEngStarts = 0;
  214. EngStart[NumEngStarts++] = EngPtr;
  215. for (i = 0;  i < EngSize;  ++i)
  216.      {
  217.      if (isspace((int)(c = *EngPtr++)))
  218.          *(EngPtr-1) = ' ';
  219.      if ((c == '.') || (c == '?'))
  220.          {
  221.          *EngPtr = '\0';
  222.          EngStart[NumEngStarts++] = ++EngPtr;
  223.          }
  224.      }
  225.  
  226. /*
  227.  *  (3)   Open Intuition and Graphics libraries.
  228.  */
  229.  
  230. if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  231.     Cleanup("c