home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / MUI / MUISpeak.lha / muispeak / src / dt / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-08  |  7.4 KB  |  346 lines

  1. #include <intuition/intuition.h>
  2.  
  3. #include <libraries/mui.h>
  4. #include <libraries/locale.h>
  5. #include <libraries/gadtools.h>
  6. #include <libraries/translator.h>
  7. #include <proto/uebersetzer.h>
  8.  
  9. #include <clib/locale_protos.h>
  10. #include <clib/muimaster_protos.h>
  11. #include <clib/alib_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <devices/narrator.h>
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18.  
  19. #include "speak.h"
  20.  
  21.  
  22. #define CATCOMP_BLOCK
  23. #include "speakstrings_cat.h"
  24.  
  25. #undef CATCOMP_BLOCK
  26.  
  27. #define DEFAULT_STR        "Hello. This is Amiga speaking."
  28.  
  29. BYTE audio_chn[3][4] ={ {1,8,0,0},  {2,4,0,0}, {3,5,10,12} };
  30.  
  31. struct Library *        TranslatorBase;
  32. struct Library *        UebersetzerBase;
  33. struct LocaleBase *     LocaleBase;
  34. struct Library *         MUIMasterBase;
  35. struct MsgPort *        SpeakMP;
  36.  
  37. struct Locale *            locale = NULL;
  38. struct Catalog *        Catalog = NULL;
  39.  
  40. struct narrator_rb *     SpeakIO;
  41. struct ObjApp *         App    = NULL;
  42.  
  43. int PITCH    = 120;
  44. int SPEED    = 120;
  45. int VOLUME    = 64;
  46. int SEX        = MALE;
  47. int KIND    = ROBOTICF0;
  48. int ENTHU   = 0;
  49. int PERTUB  = 0;
  50. int OUTPUT_CHANNEL =2;
  51. int F1ADJ    = 0;
  52. int F2ADJ    = 0;
  53. int F3ADJ    = 0;
  54. int A1ADJ    = 0;
  55. int A2ADJ    = 0;
  56. int A3ADJ    = 0;
  57. int ARTIC    = 0;
  58. int AVBIAS    = 0;
  59. int AFBIAS    = 0;
  60. int CENT    = 0;
  61.  
  62. /****************************************************************/
  63.  
  64. void main(int argc,char **argv);
  65.  
  66. /****************************************************************/
  67.  
  68. int wbmain(struct WBStartup *wb_startup)
  69. {
  70.  
  71.     main(0, NULL);
  72. }
  73.  
  74.  
  75. /****************************************************************/
  76.  
  77. char * MyTranslate(char * str)
  78. {
  79.     char ph_buf[255];
  80.  
  81.     TranslateGerman(str , strlen(str) , (APTR) ph_buf , 255);
  82.         
  83.     return ph_buf;
  84. }
  85.  
  86. /****************************************************************/
  87.  
  88. void Speak(char *str)
  89. {
  90.     static char ph_buf[255];
  91.  
  92.     Translate(str , strlen(str) , (APTR) ph_buf , 255);
  93.  
  94.     set( App->TX_PHONEME , MUIA_Text_Contents,ph_buf);
  95.  
  96.     set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  97.  
  98.  
  99.     SpeakIO->message.io_Command    = CMD_WRITE;
  100.     SpeakIO->message.io_Offset    = 0;
  101.     SpeakIO->message.io_Data    = ph_buf;
  102.     SpeakIO->message.io_Length    = strlen( ph_buf );
  103.  
  104.     SpeakIO->ch_masks            = audio_chn[OUTPUT_CHANNEL];
  105.     SpeakIO->nm_masks            = sizeof(audio_chn)/3;
  106.     SpeakIO->rate                = SPEED;
  107.     SpeakIO->pitch                = PITCH;
  108.     SpeakIO->volume                = VOLUME;
  109.     SpeakIO->sex                = SEX;
  110.     SpeakIO->mode                = KIND;
  111.     SpeakIO->F0enthusiasm        = ENTHU;
  112.     SpeakIO->F0perturb            = PERTUB;
  113.  
  114.     SpeakIO->F1adj                = F1ADJ;
  115.     SpeakIO->F1adj                = F2ADJ;
  116.     SpeakIO->F1adj                = F3ADJ;
  117.     SpeakIO->A1adj                = A1ADJ;
  118.     SpeakIO->A2adj                = A2ADJ;
  119.     SpeakIO->A3adj                = A3ADJ;
  120.     SpeakIO->articulate            = ARTIC;
  121.     SpeakIO->AVbias                = AVBIAS;
  122.     SpeakIO->AFbias                = AFBIAS;
  123.     SpeakIO->centralize            = CENT;
  124.     
  125.     DoIO((struct IORequest *) SpeakIO);
  126. }
  127.  
  128. /****************************************************************/
  129.  
  130. void init(void)
  131. {
  132.     if (!(MUIMasterBase =  OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  133.     {
  134.         printf("Can't open muimaster.library V %d+\n",MUIMASTER_VMIN);
  135.         exit(0);
  136.     }
  137.     
  138.  
  139.     if (!(UebersetzerBase = OpenLibrary("uebersetzer.library",0)))
  140.     {
  141.         printf("Can't open uebersetzer.library\n");
  142.         CloseLibrary(MUIMasterBase);
  143.         exit(0);
  144.     }
  145.  
  146.  
  147.     if (!(TranslatorBase = OpenLibrary("translator.library",0)))
  148.     {
  149.         printf("Can't open translator.library\n");
  150.         CloseLibrary(MUIMasterBase);
  151.         exit(0);
  152.     }
  153.  
  154.  
  155.     SpeakMP = CreateMsgPort();
  156.     SpeakIO = (struct narrator_rb *) CreateExtIO(SpeakMP,sizeof(struct narrator_rb));
  157.     SpeakIO->flags = NDF_NEWIORB;
  158.                 
  159.     OpenDevice("narrator.device",0,(struct IORequest *) SpeakIO,NULL);
  160. }
  161.  
  162. /****************************************************************/
  163.  
  164. void main(int argc,char **argv)
  165. {
  166.     BOOL    running = TRUE;
  167.     ULONG    signal;
  168.  
  169.  
  170.     LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library",37);
  171.  
  172.     if (LocaleBase != NULL)
  173.     {
  174.         struct TagItem tags[3];
  175.     
  176.         locale = OpenLocale(NULL);
  177.  
  178.         if (strcmp(locale->loc_LanguageName,"deutsch.language"))   // Builtin language != locale Language
  179.         {
  180.             tags[0].ti_Tag  = OC_BuiltInLanguage;
  181.             tags[0].ti_Data = (ULONG) "deutsch";    
  182.  
  183.             tags[1].ti_Tag  = OC_Version;
  184.             tags[1].ti_Data = (ULONG) 1;
  185.  
  186.             tags[2].ti_Tag  = OC_BuiltInCodeSet;    // Default, requested from Commodore
  187.             tags[2].ti_Data = (ULONG) 0;
  188.  
  189.             Catalog=OpenCatalogA(NULL,"muispeak.catalog",tags);
  190.  
  191.          }
  192.     }    
  193.  
  194.     init();
  195.  
  196.     App = CreateApp();
  197.  
  198.     get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  199.     get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  200.     get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  201.     get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  202.     get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  203.     get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  204.     get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  205.  
  206.     set(App->CY_OUTPUT,MUIA_Cycle_Active,&OUTPUT_CHANNEL);
  207.  
  208.     
  209.     setstring( App->STR_TEXT , DEFAULT_STR);
  210.     set( App->TX_PHONEME , MUIA_Text_Contents,MyTranslate(DEFAULT_STR));
  211.  
  212.  
  213.     while (running)
  214.     {
  215.         switch (DoMethod(App->App,MUIM_Application_Input,&signal))    
  216.         {
  217.             case RET_SPEAK:
  218.                 char *x;
  219.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  220.                 Speak(x);
  221.                 break;
  222.  
  223.             case RET_SEX:
  224.                 get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  225.                 break;
  226.  
  227.             case RET_KIND:
  228.                 get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  229.                 break;
  230.  
  231.             case RET_OUTPUT:
  232.                 get(App->CY_OUTPUT,MUIA_Cycle_Active,&OUTPUT_CHANNEL);
  233.                 break;
  234.  
  235.             case RET_SPEED:
  236.                 get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  237.                 break;
  238.  
  239.             case RET_HEIGHT:
  240.                 get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  241.                 break;
  242.  
  243.             case RET_VOLUME:
  244.                 get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  245.                 break;
  246.  
  247.             case RET_PERTUB:
  248.                 get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  249.                 break;
  250.  
  251.             case RET_ENTHU:
  252.                 get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  253.                 break;
  254.             
  255.             case RET_F1ADJ:
  256.                 get(App->SL_F1ADJ,MUIA_Slider_Level,&F1ADJ );
  257.                 break;    
  258.  
  259.             case RET_F2ADJ:
  260.                 get(App->SL_F2ADJ,MUIA_Slider_Level,&F2ADJ );
  261.                 break;    
  262.  
  263.             case RET_F3ADJ:
  264.                 get(App->SL_F3ADJ,MUIA_Slider_Level,&F3ADJ );
  265.                 break;    
  266.  
  267.             case RET_A1ADJ:
  268.                 get(App->SL_A1ADJ,MUIA_Slider_Level,&A1ADJ );
  269.                 break;    
  270.  
  271.             case RET_A2ADJ:
  272.                 get(App->SL_A2ADJ,MUIA_Slider_Level,&A2ADJ );
  273.                 break;    
  274.  
  275.             case RET_A3ADJ:
  276.                 get(App->SL_A3ADJ,MUIA_Slider_Level,&A3ADJ );
  277.                 break;    
  278.  
  279.             case RET_AFBIAS:
  280.                 get(App->SL_AFBIAS,MUIA_Slider_Level,&AFBIAS);
  281.                 break;    
  282.  
  283.             case RET_AVBIAS:
  284.                 get(App->SL_AVBIAS,MUIA_Slider_Level,&AVBIAS);
  285.                 break;    
  286.  
  287.             case RET_ARTIC:
  288.                 get(App->SL_ARTIC,MUIA_Slider_Level,&ARTIC);
  289.                 break;    
  290.  
  291.             case RET_CENT:
  292.                 get(App->SL_CENT,MUIA_Slider_Level,&CENT);
  293.                 break;    
  294.  
  295.             case RET_TEXT:
  296.                 char *x;
  297.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  298.                 set( App->TX_PHONEME , MUIA_Text_Contents, MyTranslate(x));
  299.                 set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  300.                 break;
  301.  
  302.             case MUIV_Application_ReturnID_Quit:
  303.                 running = FALSE;
  304.                         break;
  305.         }
  306.  
  307.         if (running && signal) Wait(signal);
  308.  
  309.     }        
  310.  
  311.     
  312.  
  313.     CloseDevice((struct IORequest *) SpeakIO);
  314.     DeleteIORequest((struct IORequest *) SpeakIO);
  315.     DeleteMsgPort(SpeakMP);
  316.  
  317.     DisposeApp(App);
  318.     CloseLibrary(MUIMasterBase);
  319.     CloseLibrary(UebersetzerBase);
  320.     CloseLibrary(TranslatorBase);
  321.     CloseLibrary((struct Library *) LocaleBase);
  322. }
  323.  
  324.  
  325. char * GetString(int stringNum)
  326. {
  327.     LONG   *l;
  328.     UWORD  *w;
  329.     STRPTR  builtIn;
  330.  
  331.     l = (LONG *)CatCompBlock;
  332.  
  333.     while (*l != stringNum)
  334.     {
  335.         w = (UWORD *)((ULONG)l + 4);
  336.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  337.     }
  338.     builtIn = (STRPTR)((ULONG)l + 6);
  339.  
  340.  
  341.     if (LocaleBase)
  342.         return(GetCatalogStr(Catalog,stringNum,builtIn));
  343.  
  344.     return(builtIn);}
  345.  
  346.