home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 3 / FreeSoftwareCollection3pd199x-jp.img / pao / t_os / sound / src / sndplay.c < prev    next >
Text File  |  1980-01-02  |  9KB  |  313 lines

  1. /* << High C V1.4  &  386ASM V2.0 >> ******************************************
  2. **
  3. **    SND ファイルを再生します。
  4. **
  5. **    1991.01.29 : CREATE
  6. **    1991.01.29 : FINISH
  7. **
  8. **    < HISTORY >
  9. **    1991.01.29 : CREATE
  10. **
  11. **    < note > : TABS = 4
  12. **
  13. **    Programed by Y.Hirata ( Nifty ID : NAB03321 )
  14. **
  15. ******************************************************************************/
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <snd.h>
  21. #include <egb.h>
  22. #include <mos.h>
  23. #include <dos.h>
  24. #include <msdos.cf>
  25. #include "egbwork.h"                            /*  TownsMENU用                */
  26.  
  27. #define        TRUE            1
  28. #define        FALSE            0
  29.  
  30. extern        INT23_init() ;
  31. extern        INT23_end() ;
  32.  
  33. typedef unsigned char    uchar ;
  34. typedef unsigned short    ushort ;
  35. typedef unsigned long    ulong ;
  36. typedef unsigned int    uint ;
  37.  
  38. enum Values_for_ColorNo {
  39.         C_BLACK, C_BLUE, C_RED, C_PURPLE,                /*  0 -  3    */
  40.         C_GREEN, C_LIGHTBLUE, C_YELLOW, C_WHITE,        /*  4 -  7    */
  41.         C_HBLACK, C_HBLUE, C_HRED, C_HPURPLE,            /*  8 - 11    */
  42.         C_HGREEN, C_HLIGHTBLUE, C_HYELLOW, C_HWHITE        /* 12 - 15    */
  43.     } ;
  44.  
  45. enum Values_for_Write_Mode {
  46.         PSET, PRESET, OR, AND, XOR, NOT, MATTE, PASTEL,        /*  0 ~ 7    */
  47.         DUMMY_1, OPAQUE, IMPSET, INPNOT, MASKSET, MASKRESET, MASKNOT
  48.                                                             /*  8 ~ 15    */
  49.     } ;
  50.  
  51. #define    SworkSize    16384                        /*  サウンド用作業域サイズ        */
  52. char    Swork[SworkSize];                        /*  サウンド用作業域            */
  53.  
  54. char    Para[128] ;                                /*  EGB用                    */
  55.  
  56. #define    MworkSize    4096                        /*  マウス作業域のサイズ            */
  57. char    Mwork[MworkSize] ;                        /*  マウス作業域                */
  58.  
  59. char    Sndfile[128] ;                            /*  PCM 音声ファイル            */
  60.  
  61. int        Sndsize ;                                /*  PCM 音声データサイズ        */
  62. char    *Snddata ;                                /*  PCM 音声格納領域        */
  63. char    Sndflg = FALSE ;                        /*  PCM 音声 READ フラグ        */
  64.  
  65. struct _SND_DATA {
  66.     char    name[8] ;                            /*  サウンドネーム                */
  67.     ulong    sid ;                                /*  サウンドID                    */
  68.     ulong    len ;                                /*  データ幅                    */
  69.     ulong    loop_p ;                            /*  ループポイント                */
  70.     ulong    loop_len ;                            /*  ループレングス                */
  71.     ushort    sf ;                                /*  サンプリング周波数            */
  72.     short    hosei ;                                /*  原音の補正(ピッチベンド)    */
  73.     uchar    onkai ;                                /*  原音の音階                */
  74.     uchar    flg ;                                /*  ?フラグ                    */
  75.     } ;
  76.  
  77. union _SND_CHECK {
  78.     struct _SND_DATA    data ;
  79.     char                buf[30] ;
  80.     } Snd ;
  81.  
  82. typedef struct {
  83.     char    _reserved[21] ;                        /*  reserved area            */
  84.     char    _attrib ;                            /*  attribute byte            */
  85.     ushort    _ftime ;                             /*  time of file            */
  86.     ushort    _fdate ;                            /*  date of file            */
  87.     ulong    _fsize ;                            /*  file size                */
  88.     char    d_name[13] ;                        /*  packed file name        */
  89. } DIR ;
  90.  
  91. /*************************  DTAの設定  ************************************/
  92. void setdta( p )
  93. DIR *p ;
  94. {
  95.     Registers.AX.LH.H = 0x1a ;
  96.     Registers.DX.R = (uint)p ;
  97.     Registers.DS.R = getds() ;
  98.     calldos() ;
  99. }
  100.  
  101. /*******************  最初に一致するファイル名の検索  ************************/
  102. int firstsearch( path,attr,dta )
  103. char    *path ;
  104. int        attr ;
  105. DIR        *dta ;
  106. {
  107.     setdta( dta ) ;
  108.     Registers.AX.LH.H = 0x4e ;
  109.     Registers.CX.R = attr ;                        /*  ファイルの種類    */
  110.     Registers.DX.R = (uint)path ;                /*  ファイル名        */
  111.     Registers.DS.R = getds() ;
  112.     calldos();
  113.     if ( (Registers.Flags & 0x0001) != 0 )
  114.         return ( FALSE ) ;
  115.     else
  116.         return ( TRUE ) ;                    /*  成功ならば 真 でreturn    */
  117. }
  118.  
  119. /***************************  ファイルサイズ取得  ****************************/
  120. int getfsize()
  121. {
  122.     DIR        dta ;
  123.     ushort    attr=0 ;
  124.  
  125.     if ( firstsearch( Sndfile,attr,&dta ) ) {        /*  最初のエントリ    */
  126.         Sndsize = dta._fsize ;
  127.         return( dta._fsize ) ;
  128.     } else {                                    /*  ファイルが見つからない    */
  129.         return( -1 ) ;
  130.     }
  131. }
  132.  
  133. /****************************  文字属性設定  *********************************/
  134. void textatr( int t_sp,int f_st )
  135. {
  136.     EGB_textDirection( Gwork,0 ) ;
  137.     EGB_textDisplayDirection( Gwork,0 ) ;
  138.     EGB_textSpace( Gwork,t_sp ) ;        /* 文字間スペース [dot]        */
  139.     EGB_textZoom( Gwork,0,8,16 ) ;        /* ANK  :  8 x 16            */
  140.     EGB_textZoom( Gwork,1,16,16 ) ;        /* 漢字 : 16 x 16            */
  141.     EGB_fontStyle( Gwork,f_st ) ;        /* 標準文字                    */
  142. }
  143.  
  144. /******************************  文字出力  ***********************************/
  145. void puttext( x, y, text, col )
  146. int    x, y, col ;
  147. char    *text ;
  148. {
  149.     uint    sl ;
  150.  
  151.     EGB_color( Gwork,0,col ) ;            /* 前景色                    */
  152.     WORD( Para+0 ) = x ;                /* X Point                    */
  153.     WORD( Para+2 ) = y ;                /* Y Point                    */
  154.     sl = strlen( text ) ;
  155.     WORD( Para+4 ) = sl ;
  156.     strcpy( Para+6,text ) ; 
  157.     EGB_sjisString( Gwork,Para ) ;        /* 文字表示                    */
  158. }
  159.  
  160. /***************************  SND DATA の読込み  *****************************/
  161. void snd_load()
  162. {
  163.     FILE *fp;
  164.  
  165.     Sndflg = FALSE ;
  166.     if ( getfsize() == -1 ) return ;
  167.     
  168.     Snddata = malloc( Sndsize ) ;                /*  SND データ格納領域確保    */
  169.     if ( Snddata == NULL ) {
  170.         printf("<snd_load> malloc error!\n") ;
  171.         return ;
  172.     } else {
  173.         fp = fopen( Sndfile,"rb" ) ;
  174.         fread( Snddata,1,Sndsize,fp ) ;
  175.         fclose( fp ) ;
  176.         Sndflg = TRUE ;
  177.     }
  178.  
  179.     memcpy( Snd.buf,Snddata,30 ) ;
  180.  
  181.     if ( !Sndflg ) {
  182.         printf("\x1b[33m") ;
  183.         printf(".SND ファイル ( %s ) を読み込めませんでした。\x1b[m\n",Sndfile) ;
  184.         return ;
  185.     } else {
  186.         printf("音声データ \x1b[36m%s \x1b[m",Sndfile) ;
  187.         printf(" を再生します。\n") ;
  188.     }
  189.     printf("\n") ;
  190.  
  191. /*
  192. **    PCM 音声を初期設定する
  193. */
  194.     SND_pcm_mode_set( 1 ) ;                        /*  PCM音声モードチャンネル数設定    */
  195.     SND_volume_change( 71,127 ) ;                /*  最大ボリュームにする        */
  196.  
  197. }
  198.  
  199. /***************************  マウス初期化  **********************************/
  200. void minit()
  201. {
  202.     MOS_start( Mwork,MworkSize ) ;
  203.     MOS_disp( FALSE ) ;                                /* マウス非表示        */
  204. }
  205.  
  206. /*******************************  初期設定  **********************************/
  207. void init()
  208. {
  209.     SND_init( Swork ) ;                                /*  サウンド初期化            */
  210.  
  211.     snd_load() ;
  212.  
  213.     SND_elevol_mute( 0x0001 ) ;                        /*  PCM 音源のみミュート解除*/
  214.     SND_elevol_all_mute( -1 ) ;                        /*  全ミュートの解除        */
  215.  
  216. /*
  217. **    TownsMENUは、Page 1 & 0 で Page 1 が前面, MENUは Page 0 に書かれている。
  218. **    V1.1 L20 時点。
  219. */
  220.     EGB_displayPage( Gwork,1,3 ) ;    /* Show page 0 & 1 : Priority 1        */
  221.  
  222.     minit() ;                                        /*  マウス初期化            */
  223.  
  224.     EGB_writePage( Gwork,1 ) ;                        /* Write to Page 1        */
  225.     EGB_writeMode( Gwork,OPAQUE ) ;                    /* 背景色で塗り潰して    */
  226.     EGB_color( Gwork,0,C_BLACK ) ;                    /* 前景色 : Black        */
  227.     EGB_color( Gwork,1,C_HWHITE ) ;                    /* 背景色 : H_White        */
  228.     EGB_color( Gwork,2,C_HGREEN ) ;                    /* 面塗色 : H_Green        */
  229.     EGB_color( Gwork,3,C_BLACK ) ;                    /* 透過色 : Black        */
  230.     EGB_displayStart( Gwork,0,0,0 ) ;                /* 表示開始位置            */
  231.     EGB_displayStart( Gwork,1,0,0 ) ;                /* 仮想画面位置         */
  232.     EGB_displayStart( Gwork,2,1,1 ) ;                /* 画面の拡大            */
  233.     EGB_displayStart( Gwork,3,639,479 ) ;            /* 画面の大きさ         */
  234.     textatr( 0,0 ) ;
  235.  
  236. }
  237.  
  238. /********************************  プレイ開始  *********************************/
  239. void play_start()
  240. {
  241.     char    buf[128] ;
  242.     int        mbot, mx, my ;
  243.     int        c ;
  244.  
  245.     do {                                            /*  マウスの開放を待つ        */
  246.         MOS_rdpos( &mbot,&mx,&my ) ;
  247.     } while ( mbot ) ;
  248.  
  249.     strcpy( buf,"                   " ) ;
  250.     c = ( 80 - strlen( buf ) ) / 2 + 1 ;
  251.     puttext( c*8,11*16+1,buf,C_HBLACK ) ;
  252.     sprintf( buf,"< %s >",Sndfile ) ;
  253.     c = ( 80 - strlen( buf ) ) / 2 + 1 ;
  254.     puttext( c*8,11*16+1,buf,C_HBLACK ) ;
  255.     sprintf( buf,"を再生します♪ (NOTE=%d)",Snd.data.onkai ) ;
  256.     c = ( 80 - strlen( buf ) ) / 2 + 1 ;
  257.     puttext( c*8,12*16+9,buf,C_HBLACK ) ;
  258.  
  259.     SND_pcm_play_stop( 71 ) ;
  260.     SND_pcm_play( 71,Snd.data.onkai,127,Snddata ) ;
  261.  
  262.     while ( TRUE ) {
  263.         if ( !SND_pcm_status( 71 ) ) break ;
  264.         MOS_rdpos( &mbot,&mx,&my ) ;
  265.         if ( mbot ) break ;
  266.     }
  267.  
  268.     SND_pcm_play_stop( 71 ) ;
  269. }
  270.  
  271. /*********************************  メイン  **********************************/
  272. void main( int ac, char *av[] )
  273. {
  274.     int        endp ;
  275.  
  276.     printf("SNDPLAY.EXP  v0.50  (c) パオパオ 1991.        ") ;
  277.     printf("<< Copyright (C) Y.Hirata 1991. >>\n") ;
  278.  
  279.     if ( ac > 1 ) {                                    /*  引数あり            */
  280.         strcpy( Sndfile,av[1] ) ;
  281.         endp = strlen( Sndfile ) ;
  282.         if ( strchr( Sndfile,'.' ) == NULL ) {        /*  ファイル拡張子なし        */
  283.             strcat( Sndfile,".SND" ) ;
  284.         } else {
  285.             if ( strcmp( Sndfile+endp-4,".SND" ) &&
  286.                     strcmp( Sndfile+endp-4,".snd" ) ) {
  287.                 printf("\x1b[31mERROR\x1b[m : FILE NAME ( %s ) - ",Sndfile) ;
  288.                 printf(".SND ファイル しか指定できません!\n") ;
  289.                 exit( 1 ) ;
  290.             }
  291.         }
  292.     } else {                                        /*  引数なし            */
  293.         printf(".SND ファイルを指定して下さい。\n") ;
  294.         exit( 1 ) ;
  295.     }
  296.  
  297.     INT23_init() ;                                    /*  ^C マスク設定            */
  298.     init() ;                                        /*  各種初期設定        */
  299.     if ( Sndflg )
  300.         play_start() ;                                /*  プレイ開始            */
  301.  
  302. close:
  303.     if ( Sndflg ) {
  304.         free( Snddata ) ;
  305.     }
  306.     SND_end() ;                                        /*  サウンド終了            */
  307.     INT23_end() ;                                    /*  ^C マスク解除            */
  308.  
  309.     printf("\nプログラムを終了します。\n") ;
  310.  
  311. }
  312.  
  313.