home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / crit / speech.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-08-16  |  6.8 KB  |  251 lines  |  [TEXT/????]

  1.  /*
  2.   * macintalk driver
  3.   */
  4.  #define _DRIVER
  5.  #include <memory.h>
  6.  #include <pb.h>
  7.  #include <resource.h>
  8.  #include "speech.h"
  9.  
  10.  #define NULL    0L
  11.  
  12.  struct pbRec {
  13.          struct ParamBlkRec *    ioLink;
  14.          short                   ioType;
  15.          short                   ioTrap;
  16.          Ptr                     ioCmdAddr;
  17.          ProcPtr                 ioCompletion;
  18.          short                   ioResult;
  19.          char *                  ioNamePtr;
  20.          short                   ioVRefNum;
  21.          union {
  22.                  struct ioParam          iop;
  23.                  struct cntrlParam       cp;
  24.          } u;
  25.  };
  26.  
  27.  /*
  28.   *      Internal format of the SpeechRecord structure
  29.   */
  30.  struct iSpeechRecord {
  31.          struct pbRec            pb;             /* 50 bytes */
  32.          int                     junk0;          /* 50 */
  33.          ProcPtr *               rdrH0;          /* 52 */
  34.          long                    junk4;          /* 56 */
  35.          Str255 *                ExcpFile;       /* 60 */
  36.          int                     junk6;          /* 64 */
  37.          ProcPtr *               rdrHandle;      /* 66 */
  38.          int                     DrvrRefNum;     /* 70 */
  39.          int                     junk2;          /* 72 */
  40.          int                     ExcpRefNum;     /* 74 */
  41.          char                    junk1[24];      /* 76 */
  42.  };
  43.  typedef struct iSpeechRecord    iSpeechRecord;
  44.  typedef iSpeechRecord *         iSpeechPtr;
  45.  typedef iSpeechPtr *            iSpeechHandle;
  46.  
  47.  /* Driver Control Codes */
  48.  #define MODE_CODE               0
  49.  /* Code 1 for language maybe? */
  50.  #define RATE_CODE               2
  51.  #define SEX_CODE                3
  52.  #define PITCH_CODE              4
  53.  
  54.  
  55.  #define uTableBase              ((long*)0x011c)
  56.  
  57.  SpeechErr SpeechOn( ExcpsFile, ptheSpeech )
  58.  Str255 * ExcpsFile;
  59.  SpeechHandle * ptheSpeech;
  60.  {
  61.          static char * DrvrName = "\P.SPEECH";
  62.          static char * DrvrFile = "\PMacinTalk";
  63.          register iSpeechHandle theSpeech;
  64.          register iSpeechPtr isp;
  65.          register int refNum;
  66.          register Handle h;
  67.          register long * utp;
  68.          register int id;
  69.          register OSErr err;
  70.  
  71.  
  72.          * ptheSpeech = theSpeech
  73.                  = NewHandle(( Size )( sizeof( iSpeechRecord )));
  74.          if( err = MemError())
  75.                  return err;
  76.          HLock( theSpeech );
  77.          isp = *theSpeech;
  78.          setmem( isp, sizeof( iSpeechRecord ), 0 );
  79.          if(( refNum = OpenResFile( DrvrFile )) < 0 )
  80.                  return ResError();
  81.          isp->ExcpRefNum = refNum;
  82.          SetResLoad( FALSE );
  83.          h = GetNamedResource( 'DRVR', DrvrName );
  84.          if( err = ResError())
  85.                  return err;
  86.          SetResLoad( TRUE );
  87.  
  88.          utp = uTableBase;
  89.          utp = &(utp[32]);
  90.          id = 32;
  91.          do {
  92.                  --id;
  93.                  if( id<= 18 )
  94.                          return fullUnitT;
  95.          } while( *--utp );
  96.          isp->DrvrRefNum = -(id+1);
  97.  
  98.          SetResInfo( h, id, NULL );
  99.          LoadResource( h );
  100.          /* err = ResError(); */
  101.          HLock( h );
  102.  
  103.          isp->ExcpFile = ExcpsFile;
  104.          isp->pb.ioNamePtr = DrvrName;
  105.          isp->pb.ioVRefNum = 0;
  106.          isp->pb.u.iop.ioVersNum = 0;
  107.          isp->pb.u.iop.ioPermssn = 0;
  108.          isp->pb.u.iop.ioMisc = NULL;
  109.          PBOpen( isp, FALSE );
  110.          err = isp->pb.ioResult;
  111.          isp->rdrHandle = isp->rdrH0;
  112.          HUnlock( theSpeech );
  113.          return err;
  114.  }
  115.  
  116.  
  117.  void SpeechOff( theSpeech )
  118.  SpeechHandle theSpeech;
  119.  {
  120.          register iSpeechPtr isp;
  121.          register int excpRef;
  122.  
  123.          HLock( theSpeech );
  124.          isp = *( iSpeechHandle )theSpeech;
  125.          PBClosei( isp );
  126.          if( excpRef = isp->ExcpRefNum )
  127.                  CloseResFile( excpRef );
  128.          HUnlock( theSpeech );
  129.          DisposHandle( theSpeech );
  130.  }
  131.  
  132.  
  133.  void SpeechRate( theSpeech, theRate )
  134.  SpeechHandle theSpeech;
  135.  int theRate;
  136.  {
  137.          register iSpeechPtr isp;
  138.  
  139.  
  140.          HLock( theSpeech );
  141.          isp = *( iSpeechHandle )theSpeech;
  142.          isp->pb.u.cp.csRefNum = isp->DrvrRefNum;
  143.          isp->pb.u.cp.csCode = RATE_CODE;
  144.          isp->pb.u.cp.csParam.conCtl.sg_flags = theRate;
  145.          PBCntli( isp );
  146.          HUnlock( theSpeech );
  147.  }
  148.  
  149.  void SpeechPitch( theSpeech, thePitch, theMode )
  150.  SpeechHandle theSpeech;
  151.  int thePitch;
  152.  FOMode theMode;
  153.  {
  154.          register iSpeechPtr isp;
  155.  
  156.  
  157.          HLock( theSpeech );
  158.          isp = *( iSpeechHandle )theSpeech;
  159.          isp->pb.u.cp.csRefNum = isp->DrvrRefNum;
  160.          isp->pb.u.cp.csCode = MODE_CODE;
  161.          isp->pb.u.cp.csParam.conCtl.sg_flags = theMode;
  162.          PBCntli( isp );
  163.          isp->pb.u.cp.csCode = PITCH_CODE;
  164.          isp->pb.u.cp.csParam.conCtl.sg_flags = thePitch;
  165.          PBCntli( isp );
  166.          HUnlock( theSpeech );
  167.  
  168.  }
  169.  
  170.  
  171.  void SpeechSex( theSpeech, theSex )
  172.  SpeechHandle theSpeech;
  173.  Sex theSex;
  174.  {
  175.          register iSpeechPtr isp;
  176.  
  177.  
  178.          HLock( theSpeech );
  179.          isp = *( iSpeechHandle )theSpeech;
  180.          isp->pb.u.cp.csRefNum = isp->DrvrRefNum;
  181.          isp->pb.u.cp.csCode = SEX_CODE;
  182.          isp->pb.u.cp.csParam.conCtl.sg_flags = theSex;
  183.          PBCntli( isp );
  184.          HUnlock( theSpeech );
  185.  
  186.  }
  187.  
  188.  
  189.  SpeechErr Reader( theSpeech, EnglishInput, InputLength, PhoneticOutput )
  190.  SpeechHandle theSpeech;
  191.  Ptr EnglishInput;
  192.  long InputLength;
  193.  Handle PhoneticOutput;
  194.  {
  195.          register iSpeechPtr isp;
  196.          register ProcPtr * rdr;
  197.          pascal SpeechErr DummyReader();
  198.  
  199.  
  200.          HLock( theSpeech );
  201.          isp = *( iSpeechHandle )theSpeech;
  202.          rdr = isp->rdrHandle;
  203.          HLock( rdr );
  204.          return DummyReader( EnglishInput, InputLength, PhoneticOutput, *rdr );
  205.  }
  206.  
  207.  #asm
  208.  DummyRea_:
  209.          move.l          4(sp),a0        ; a0 <- RealReader
  210.          move.l          (sp)+,(sp)      ; RealReader spot <- ret address
  211.          jmp             (a0)            ; Branch to real reader
  212.  #endasm
  213.  
  214.  
  215.      
  216.  SpeechErr MacinTalk( theSpeech, Phonemes )
  217.  SpeechHandle theSpeech;
  218.  Handle Phonemes;
  219.  {
  220.          register Size PhonemeSize;
  221.          register iSpeechPtr isp;
  222.          register OSErr err;
  223.  
  224.          HLock( theSpeech );
  225.          PhonemeSize = GetHandleSIze( Phonemes );
  226.          isp = *( iSpeechHandle )theSpeech;
  227.          isp->pb.u.iop.ioRefNum = isp->DrvrRefNum;
  228.          isp->pb.u.iop.ioBuffer = Phonemes;
  229.          isp->pb.u.iop.ioReqCount = PhonemeSize;
  230.          err = PBWritei( isp );
  231.          HUnlock( theSpeech );
  232.          return err;
  233.  }
  234.  
  235.  #asm
  236.  PBClosei_:
  237.          move.l          4(sp),a0        ; isp -> a0
  238.          dc.w            $a201           ; _Close, Immed
  239.          rts
  240.  
  241.  PBWritei_:
  242.          move.l          4(sp),a0        ; isp -> a0
  243.          dc.w            $a203           ; _Write, Immed
  244.          rts
  245.  
  246.  PBCntli_:
  247.          move.l          4(sp),a0        ; isp -> a0
  248.          dc.w            $a204           ; _Control, Immed
  249.          rts
  250.  #endasm
  251.