home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / sound / mp2_099 / src / gem / mp2audio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-05  |  5.2 KB  |  225 lines

  1.    /* MPEG Audio layer 2 decoder. */
  2.  
  3. #include <tos.h>
  4. #include <vdi.h>
  5. #include <aes.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10.  
  11. #include "version.h"
  12. #include "snddefs.h"
  13. #include "mp2audio.h"
  14. #include "mp2info.h"
  15. #include "mp2conf.h"
  16.  
  17. #include "mp2ctrl.rsh"    /* rsc file */
  18. #include "mp2ctrl.rh"
  19. #include "mp2wind.h"
  20.  
  21. #include "libshoe.h"
  22.  
  23. /* global variables */
  24. int time_slice=DEFAULT_TIME_SLICE,count_dir=DEFAULT_COUNT_DIR;
  25. int find_first=0,play_first=0;
  26. long block=(long)DEFAULT_BLOCK_SIZE*1024L;
  27. int fd, replay = 0, file_open, ext, quit;
  28. int app_id, acc_id, vdi_id;
  29. int dom;
  30. long buffer;
  31. WINDFORM windforms[5];
  32. WINDHANDLELIST *windhandles = NULL;
  33. #ifdef STATIC_BUFFER
  34. char buffer_mem[(long)BLOCK_SIZE];
  35. #else
  36. char *buffer_mem;
  37. #endif
  38.  
  39. extern int _app;
  40.  
  41. /* global variables from mp2file.c */
  42. extern char path[512], filename[512];
  43. extern long filesize,filepos;
  44.  
  45. /* global variables from mp2event.c */
  46. extern long total_time;
  47.  
  48. /* Function in this module. */
  49. static void setup_rsrc(int nbpl);
  50. extern void unix2dos(char *);
  51.  
  52. /* Functions from mp2init.c */
  53. extern int external_clock(void);
  54. extern void init_replay(void);
  55.  
  56. /* Functions from mp2exit.c */
  57. extern void exit_replay(void);
  58.  
  59. /* Functions from mp2file.c */
  60. extern void close_file(int fd);
  61. extern int reopen_file(int fd);
  62.  
  63. /* Functions from mp2event.c */
  64. extern void main_event_loop(void);
  65. extern void fg_init(int wind_id);
  66. extern void update_time(void);
  67. extern void unquote(char *);
  68.  
  69. /* Functions from mp2info.c */
  70. extern int getmp2info(int);
  71. extern void show_mp2_error(int);
  72.  
  73. /* Function from bifshoe.c */
  74. extern void load_bifs(void);
  75.  
  76. #pragma warn -par
  77. int main(int argc, char *argv[])
  78. {
  79.     int wchar,hchar,wbar,hbar;
  80.     int work_in[11] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 };
  81.     int work_out[57];
  82.     int tmp_id, button;
  83.  
  84.     if(_app) {
  85.         if(locksnd() < 0) {
  86.             button = form_alert(1,"[1][The audio subsystem|"
  87.                                   "is already in use!][ Quit | Force ]");
  88.             if(button == 1)
  89.                 return -129;
  90.             unlocksnd();
  91.             locksnd();
  92.         }
  93.     }
  94.  
  95.     dom = (Pdomain(1) == 0) ? 1 : 0;
  96.  
  97.     /* Default clock is automatic detection. */
  98.     ext = external_clock();
  99.  
  100.     /* Default path is current. */
  101.     path[0] = 'A' + (char)Dgetdrv();
  102.     path[1] = ':';
  103.     Dgetpath(path+2, 0);
  104.     strcat(path, "\\");
  105.  
  106. #ifdef STATIC_BUFFER
  107.     block = (long)BLOCK_SIZE;
  108. #else
  109.     buffer_mem=(char *)malloc((size_t)block);
  110. #endif
  111.  
  112.     if((app_id = appl_init()) >= 0) {
  113. #ifndef STATIC_BUFFER
  114.         if(buffer_mem==NULL) {
  115.             form_alert(1,"[1][Not enough memory!][OK]");
  116.             appl_exit();
  117.             return 1;
  118.         }
  119. #endif
  120.         if(!_app || _GemParBlk.global[0] >= 0x0400)
  121.             tmp_id = menu_register(app_id, "  MP2 Audio ");
  122.         if(!_app)
  123.             acc_id = tmp_id;        
  124.         
  125.         work_in[0]=vdi_id=graf_handle(&wchar,&hchar,&wbar,&hbar);
  126.         v_opnvwk(work_in,&vdi_id,work_out);
  127.         if(vdi_id > 0) {
  128.             vq_extnd(vdi_id,1,work_out);
  129.             setup_rsrc(work_out[4]);
  130.             
  131.             /* Load application specific Shoe bifs. */
  132.             load_bifs();
  133.             
  134.             /* Load Shoe bootstrap code. */
  135.             parse_eval("(load \"mp2audio.sho\")");
  136.             
  137.             if(_app) {
  138.                 fg_init(WIND_CTRL);
  139.                 graf_mouse(ARROW,NULL);
  140.  
  141.                 main_event_loop();
  142.                 if(replay)
  143.                     exit_replay();
  144.     
  145.                 v_clsvwk(vdi_id);
  146.             } else if (acc_id >= 0)
  147.                 main_event_loop();
  148.         }
  149.  
  150.         /* This restores at least the keyclick.        */
  151.         soundcmd(4,1);        /* Set Adder-In -> Matrix. */
  152.         soundcmd(5,3);        /* ADC input -> PSG.       */
  153.         soundcmd(6,3);        /* STE prescaler 160.      */
  154.  
  155.         appl_exit();
  156. #ifndef STATIC_BUFFER
  157.         free(buffer_mem);
  158. #endif
  159.     }
  160.  
  161.     unlocksnd();
  162.     return 0;
  163. }
  164. #pragma warn .par
  165.  
  166. /* Initialize resource structures. */
  167. static void setup_rsrc(int nbpl)
  168. {
  169.     int ob;
  170.     char ver[64];
  171.     
  172.     for(ob = 0; ob < NUM_OBS; ob++)
  173.         rsrc_obfix(rs_object,ob);
  174.  
  175.     switch(nbpl) {
  176.         case 1:
  177.         case 2:
  178.             windforms[WIND_CTRL].formtree=rs_trindex[FORM_CTRL1];
  179.             windforms[WIND_INFO].formtree=rs_trindex[FORM_INFO1];
  180.             windforms[WIND_SHOE].formtree=rs_trindex[FORM_SHOE];
  181.             break;
  182.         case 4:
  183.         default:
  184.             windforms[WIND_CTRL].formtree=rs_trindex[FORM_CTRL4];
  185.             windforms[WIND_INFO].formtree=rs_trindex[FORM_INFO4];
  186.             windforms[WIND_SHOE].formtree=rs_trindex[FORM_SHOE];
  187.     }
  188.  
  189.     strcpy(windforms[WIND_CTRL].wind_title,"");
  190.     strcpy(windforms[WIND_INFO].wind_title,"Info");
  191.     strcpy(windforms[WIND_SHOE].wind_title,"      Shoe Console      ");
  192.     strcpy(ver,"Version ");
  193.     strcat(ver,VERSION_TEXT);
  194.     strcpy(windforms[WIND_INFO].formtree[INFO_VERSION].ob_spec.tedinfo->te_ptext,ver);
  195.     windforms[WIND_CTRL].windkind=(MOVER | CLOSER | NAME);
  196.     windforms[WIND_INFO].windkind=(MOVER | CLOSER | NAME);
  197.     windforms[WIND_SHOE].windkind=(MOVER | CLOSER | NAME);
  198.     windforms[WIND_CTRL].firstobj=CTRL_FIRST;
  199.     windforms[WIND_INFO].firstobj=INFO_FIRST;
  200.     windforms[WIND_SHOE].firstobj=SHOE_FIRST;
  201.     windforms[WIND_CTRL].objdepth=2;
  202.     windforms[WIND_INFO].objdepth=1;
  203.     windforms[WIND_SHOE].objdepth=0;
  204. }
  205.  
  206. /* Convert filenames from unix to ST format. */
  207. void unix2dos(char *path)
  208. {
  209.     int i = 0;
  210.     char tmp[512];
  211.  
  212.     if(path[0] == '/') {
  213.         strcpy(tmp,&path[1]);
  214.         strcpy(path,"U:\\");
  215.         strcat(path,tmp);
  216.         while(path[i]) {
  217.             if(path[i] == '/')
  218.                 path[i] = '\\';
  219.             i++;
  220.         }
  221.     }
  222.     if(path[strlen(path)-1] != '\\')
  223.         path[strlen(path)-1] = '\\';
  224. }
  225.