home *** CD-ROM | disk | FTP | other *** search
/ Fun CD 26 / OTACD26.ISO / archive / game / nnirowave / nnirowave.lzh / nnirowave / nnirowave.c next >
C/C++ Source or Header  |  1997-12-30  |  8KB  |  357 lines

  1. /*  クイズなないろドリームス 音声ローダ  Ver.0.8 */
  2. /*  97/7/29  (c)tokai@main.eng.hokudai.ac.jp     */
  3.  
  4. #include<string.h>
  5. #include<stdlib.h>
  6. #include<stdio.h>
  7.  
  8. void wlong(long),wshort(short);
  9. FILE *fo,*fi;
  10.  
  11. // 入力ファイル名の作成
  12. char* cinput(char drive,int path ,char *head,int n)
  13. {
  14.  
  15.     char *out
  16.     ,num[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}
  17.     ,*path2[13]={
  18.      ":\\GL00_PCM\\",":\\GL01_PCM\\",":\\GL02_PCM\\",":\\GL03_PCM\\",":\\GL04_PCM\\",
  19.      ":\\GL05_PCM\\",":\\GL06_PCM\\",":\\GL07_PCM\\",":\\GL08_PCM\\",":\\GL09_PCM\\",
  20.      ":\\GL0A_PCM\\",":\\END_PCM\\",":\\"};
  21.     int i=0,i2=0,length,leng=-1;
  22.  
  23.     while(path2[path][++leng]!='\0');
  24.     length =leng + 10;
  25.     if((out = (char *)malloc(length*sizeof(char)))==0){
  26.       printf("error in cinput\n");exit(1);}
  27.     out[0] = drive;
  28.     for(i=1;i<=leng;i++) out[i] = path2[path][i-1];
  29.     out[i++]=head[0]; out[i++]=head[1];
  30.     i2 = n /16; n -= i2*16;
  31.     out[i++]=num[i2];out[i++]=num[n];
  32.     out[i++]='.';out[i++]='M';out[i++]='U';out[i++]='S';out[i]='\0';
  33.     
  34.     return(out);
  35. }
  36.  
  37. //出力ファイル名の作成
  38. char* coutput(int chara,int n){
  39.  
  40.     char *out
  41.     ,*chara2[15]={"kumiko_","momoko_","rotte_","saki_","mayumi_","emi_",
  42.                      "megumi_","rintu_","maou_","yosei_","effect_","end_",
  43.                      "opening_","omake_","aisatu_"};
  44.     int i,i2,i3,leng=-1,length;
  45.  
  46.     while(chara2[chara][++leng]!='\0');
  47.     length = leng + 7;
  48.     if((out = (char *)malloc(length*sizeof(char)))==0){
  49.       printf("error in cinput\n");exit(1);}
  50.     i2 = n /100; n -= i2*100; i2 += 48;
  51.     i3 = n /10; n -= i3*10; i3 += 48;
  52.     n += 48;
  53.     for(i=0;i<leng;i++) out[i] = chara2[chara][i]; 
  54.     out[i++]=i2;out[i++]=i3;out[i++]=n;
  55.     out[i++]='.';out[i++]='w';out[i++]='a';out[i++]='v';out[i]='\0';
  56.  
  57.     return(out);
  58. }
  59.  
  60. main(int argc,char *argv[])
  61. {
  62.     int i,i2,c1,c2,chara,path,from,to;
  63.     int size,chn,freq,bit;
  64.     int chr[15]={115,114,124,165,127,101,182,107,59,292,11,185,18,9,10};
  65.     char *file,*ofile,*file2[300],drive,*head;
  66.  
  67.     freq = 38000; chn=1; bit = 16;
  68.  
  69.     printf("CDの入っているドライブ名を入力して下さい。\n(例)ドライブ A なら a \n\n? ");
  70.     scanf("%c",&drive);
  71.     printf("\n抜き出すファイルの種類を選んで下さい。\n\n0:久美子音声 1:桃子音声   2:ロッテ音声 3:サキ音声 4:真由美音声\n5:絵美音声   6:めぐみ音声 7:リンツ音声 8:魔王音声 9:妖精(その他)音声\n10:各種効果音   11:エンディング音声 12:オープニング音声 13:おまけ音声\n14:あいさつ音声\n\n? ");
  72.     scanf("%d",&chara);
  73.     
  74.   if(chara <0 || chara > 14)
  75.         {printf("正しい範囲を指定して下さい。");exit(1);}
  76.  
  77.   if(chara != 13){
  78.      printf("\n存在するファイルの数は %d 個です。抜き出す範囲を指定して下さい。\n(例)30番から39番まで10個のファイルを抜き出す時は from? 30  to? 39\n\n",chr[chara]);
  79.      printf("from? ");scanf("%d",&from);
  80.      printf("to? ");scanf("%d",&to);
  81.      if(from <1 || from > to || to > chr[chara])
  82.         {printf("正しい範囲を指定して下さい。");exit(1);} }
  83.  
  84.    switch(chara){
  85.  
  86.    case 0: //kumiko
  87.  
  88.      head="00";path = chara;
  89.      for(i=from;i<=to;i++){
  90.       i2 = i+12-1;
  91.       file2[i] = cinput(drive,path,head,i2); }
  92.      break;
  93.  
  94.   case 1: //momoko
  95.  
  96.      head="01";path = chara;
  97.      for(i=from;i<=to;i++){
  98.       i2 = i+17-1;
  99.       file2[i] = cinput(drive,path,head,i2); }
  100.      break;
  101.  
  102.  case 2: //rotte
  103.  
  104.      path = chara;
  105.      for(i=from;i<=to;i++){
  106.       if(i<123){
  107.        head="02";
  108.        i2 = i+14-1;}
  109.       else{
  110.        head="0D";
  111.        i2 = i-123;}
  112.      file2[i] = cinput(drive,path,head,i2); }
  113.      break;
  114.  
  115. case 3: //saki
  116.  
  117.      path = chara;
  118.      for(i=from;i<=to;i++){
  119.       if(i<164){
  120.        head="03";
  121.        i2 = i+17-1;}
  122.       else{
  123.        head="0B";
  124.        i2 = i-164;}
  125.      file2[i] = cinput(drive,path,head,i2); }
  126.      break;
  127.  
  128. case 4: //mayumi
  129.  
  130.      path = chara;
  131.      head="04";
  132.      for(i=from;i<=to;i++){
  133.       if(i<83) i2 = i+13-1;
  134.       else i2 = i-83+115;
  135.      file2[i] = cinput(drive,path,head,i2); }
  136.      break;
  137.  
  138. case 5: //emi
  139.  
  140.      path = chara;
  141.      for(i=from;i<=to;i++){
  142.       if(i<=92){
  143.        head="05";
  144.        if(i<=45) i2 = i+17-1;
  145.        else if(i<=77)i2 = i-46+74;
  146.        else if(i==78)i2 = 113;
  147.        else i2 = i - 79 + 123;}
  148.       else{
  149.        head="0A"; path = 9;
  150.        i2 = i - 93 + 95;}
  151.      file2[i] = cinput(drive,path,head,i2); }
  152.      break;
  153.  
  154. case 6: //megumi
  155.  
  156.      path = chara;
  157.      for(i=from;i<=to;i++){
  158.       if(i<=180){
  159.        head="06";
  160.        if(i<=109) i2 = i+14-1;
  161.        else i2 = i - 110 + 150;}
  162.       else{
  163.        head="0C";
  164.        i2 = i -181;}
  165.      file2[i] = cinput(drive,path,head,i2); }
  166.      break;
  167.  
  168. case 7: //rintu
  169.  
  170.      path = chara;
  171.      head="07";
  172.      for(i=from;i<=to;i++){
  173.        if(i<=28) i2 = i-1;
  174.        else if(i<=92) i2 = i-29+42;
  175.        else i2 = i - 93 + 119;
  176.      file2[i] = cinput(drive,path,head,i2); }
  177.      break;
  178.  
  179. case 8: //mao
  180.  
  181.      path = chara;
  182.      head="08";
  183.      for(i=from;i<=to;i++){
  184.        if(i<=57) i2 = i-1;
  185.        else i2 = i - 58 + 254;
  186.      file2[i] = cinput(drive,path,head,i2); }
  187.      break;
  188.  
  189. case 9: //yosei
  190.  
  191.      path = chara;
  192.      for(i=from;i<=to;i++){
  193.       if(i<=215){
  194.        head="09";
  195.        if(i<=104) i2 = i-1;
  196.        else i2 = i-105+145;}
  197.       else{
  198.        head="0A";
  199.        if(i<=241) i2 = i-216;
  200.        else if(i<=290) i2 = i - 242 + 46;
  201.        else i2 = i - 291 + 252;}
  202.      file2[i] = cinput(drive,path,head,i2); }
  203.      break;
  204.  
  205. case 10: //effect
  206.  
  207.      for(i=from;i<=to;i++){
  208.  
  209.       if (i<=9){
  210.        head="0F";
  211.        i2 = i -1;
  212.        if (i<=2) path = 4;
  213.        else if(i==3) path = 0;
  214.        else if(i<=5) path = 3;
  215.        else path = 4;}
  216.       else{
  217.        head="0A";
  218.        i2 = i - 10 + 254;
  219.        path = 6;} 
  220.      file2[i] = cinput(drive,path,head,i2); }
  221.      break;
  222.  
  223. case 11: //ending
  224.  
  225.      path = chara;
  226.      head="0E";
  227.      for(i=from;i<=to;i++){
  228.        if(i<=111) i2 = i-1;
  229.        else i2 = i - 112 + 118;
  230.      file2[i] = cinput(drive,path,head,i2); }
  231.      break;
  232.  
  233. case 12: //opening
  234.  
  235.      path = 12;
  236.      head="09";
  237.      for(i=from;i<=to;i++){
  238.        i2 = i-1+ 111;
  239.      file2[i] = cinput(drive,path,head,i2); }
  240.      break;
  241.  
  242. case 13: //omake
  243.  
  244.  
  245.      printf("\nキャラクターを選んで下さい。\n\n1:久美子 2:桃子   3:シャルロッテ\n4:サキ   5:真由美 6:絵美\n7:めぐみ 8:妖精   9:リンツ\n\n");
  246.      printf("? ");scanf("%d",&from);
  247.      if(from <1 || from > 9)
  248.         {printf("正しい範囲を指定して下さい。");exit(1);} 
  249.  
  250.      to=from;
  251.      path = 12;
  252.      head="0F";
  253.      for(i=from;i<=to;i++){
  254.        i2 = i-1+ 128;
  255.      file2[i] = cinput(drive,path,head,i2); }
  256.      break;
  257.  
  258. case 14: //aisatu
  259.  
  260.      path = 12;
  261.      head="0F";
  262.      for(i=from;i<=to;i++){
  263.        i2 = i-1+ 137;
  264.      file2[i] = cinput(drive,path,head,i2); }
  265.      break;
  266.  
  267.    default:
  268.      printf("正しい番号を入力して下さい");
  269.      exit(1);
  270. }
  271.  
  272.      for(i=from;i<=to;i++){
  273.  
  274. /* check input file size */
  275.  
  276.     file = file2[i];
  277.     fprintf(stderr,"\n-- No.%d -- file name = %s\ncheckig size .",i,file);
  278.  
  279.     size = 0;
  280.     if((fi = fopen(file,"rb"))==0){
  281.      printf("\nfile not found %s\n",file);exit(1);}
  282.     while(fgetc(fi)!=-1) {
  283.       size++;
  284.       if(size%51200==0)fprintf(stderr,".");}
  285.     fclose(fi);
  286.  
  287.     fprintf(stderr,"ok.\nsize = %d byte\n\n",size);
  288.  
  289.  
  290. /* open output file */
  291.  
  292.       ofile = coutput(chara,i);
  293.       fprintf(stderr,"writing file %s .",ofile); 
  294.  
  295.       if((fo = fopen(ofile,"wb"))==0){
  296.          printf("\nfile write  errror %s\n",ofile);exit(1);}
  297.  
  298. /* reopen input file */
  299.  
  300.     if((fi = fopen(file,"rb"))==0){
  301.      printf("\nfile not found %s\n",file);exit(1);}
  302.  
  303.     fputc('R',fo);
  304.     fputc('I',fo);    
  305.     fputc('F',fo);
  306.     fputc('F',fo);
  307.     wlong((long)(size+36));
  308.     fputc('W',fo);
  309.     fputc('A',fo);    
  310.     fputc('V',fo);
  311.     fputc('E',fo);
  312.     fputc('f',fo);
  313.     fputc('m',fo);    
  314.     fputc('t',fo);
  315.     fputc(' ',fo);
  316.     wlong(16l);    
  317.     wshort(1);    
  318.     wshort((short)chn);    
  319.     wlong((long)freq);    
  320.     wlong((long)(freq*bit/8*chn));
  321.     wshort((short)(bit/8*chn));
  322.     wshort((short)bit);
  323.     fputc('d',fo);
  324.     fputc('a',fo);    
  325.     fputc('t',fo);
  326.     fputc('a',fo);
  327.     wlong((long)size);
  328.  
  329.     for(i2=0;i2<size;i2+=bit/8*chn){
  330.       if(i2%51200==0)fprintf(stderr,".");
  331.       c1=fgetc(fi); c2=fgetc(fi); 
  332.       fputc(c2,fo);fputc(c1,fo);}
  333.  
  334.   fprintf(stderr,"done.\n");
  335.  
  336.    fclose(fi);
  337.    fclose(fo);
  338.  
  339.   }
  340.  
  341.     return(1);
  342.   }
  343.  
  344. void wshort(short n)
  345. {
  346.     fputc(n & 255,fo);
  347.         fputc((n >> 8)&255,fo);
  348. }
  349.  
  350. void wlong(long n)
  351. {
  352.     fputc((int)(n & 255),fo);
  353.     fputc((int)((n >> 8) & 255),fo);
  354.     fputc((int)((n >> 16)& 255),fo);
  355.     fputc((int)((n >> 24)& 255),fo);
  356. }
  357.