home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Speech / speech.c next >
Encoding:
Text File  |  1986-04-19  |  7.2 KB  |  264 lines  |  [TEXT/MACA]

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