home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 3
/
FreeSoftwareCollection3pd199x-jp.img
/
pao
/
t_os
/
sound
/
src
/
sndplay.c
< prev
next >
Wrap
Text File
|
1980-01-02
|
9KB
|
313 lines
/* << High C V1.4 & 386ASM V2.0 >> ******************************************
**
** SND ファイルを再生します。
**
** 1991.01.29 : CREATE
** 1991.01.29 : FINISH
**
** < HISTORY >
** 1991.01.29 : CREATE
**
** < note > : TABS = 4
**
** Programed by Y.Hirata ( Nifty ID : NAB03321 )
**
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <snd.h>
#include <egb.h>
#include <mos.h>
#include <dos.h>
#include <msdos.cf>
#include "egbwork.h" /* TownsMENU用 */
#define TRUE 1
#define FALSE 0
extern INT23_init() ;
extern INT23_end() ;
typedef unsigned char uchar ;
typedef unsigned short ushort ;
typedef unsigned long ulong ;
typedef unsigned int uint ;
enum Values_for_ColorNo {
C_BLACK, C_BLUE, C_RED, C_PURPLE, /* 0 - 3 */
C_GREEN, C_LIGHTBLUE, C_YELLOW, C_WHITE, /* 4 - 7 */
C_HBLACK, C_HBLUE, C_HRED, C_HPURPLE, /* 8 - 11 */
C_HGREEN, C_HLIGHTBLUE, C_HYELLOW, C_HWHITE /* 12 - 15 */
} ;
enum Values_for_Write_Mode {
PSET, PRESET, OR, AND, XOR, NOT, MATTE, PASTEL, /* 0 ~ 7 */
DUMMY_1, OPAQUE, IMPSET, INPNOT, MASKSET, MASKRESET, MASKNOT
/* 8 ~ 15 */
} ;
#define SworkSize 16384 /* サウンド用作業域サイズ */
char Swork[SworkSize]; /* サウンド用作業域 */
char Para[128] ; /* EGB用 */
#define MworkSize 4096 /* マウス作業域のサイズ */
char Mwork[MworkSize] ; /* マウス作業域 */
char Sndfile[128] ; /* PCM 音声ファイル */
int Sndsize ; /* PCM 音声データサイズ */
char *Snddata ; /* PCM 音声格納領域 */
char Sndflg = FALSE ; /* PCM 音声 READ フラグ */
struct _SND_DATA {
char name[8] ; /* サウンドネーム */
ulong sid ; /* サウンドID */
ulong len ; /* データ幅 */
ulong loop_p ; /* ループポイント */
ulong loop_len ; /* ループレングス */
ushort sf ; /* サンプリング周波数 */
short hosei ; /* 原音の補正(ピッチベンド) */
uchar onkai ; /* 原音の音階 */
uchar flg ; /* ?フラグ */
} ;
union _SND_CHECK {
struct _SND_DATA data ;
char buf[30] ;
} Snd ;
typedef struct {
char _reserved[21] ; /* reserved area */
char _attrib ; /* attribute byte */
ushort _ftime ; /* time of file */
ushort _fdate ; /* date of file */
ulong _fsize ; /* file size */
char d_name[13] ; /* packed file name */
} DIR ;
/************************* DTAの設定 ************************************/
void setdta( p )
DIR *p ;
{
Registers.AX.LH.H = 0x1a ;
Registers.DX.R = (uint)p ;
Registers.DS.R = getds() ;
calldos() ;
}
/******************* 最初に一致するファイル名の検索 ************************/
int firstsearch( path,attr,dta )
char *path ;
int attr ;
DIR *dta ;
{
setdta( dta ) ;
Registers.AX.LH.H = 0x4e ;
Registers.CX.R = attr ; /* ファイルの種類 */
Registers.DX.R = (uint)path ; /* ファイル名 */
Registers.DS.R = getds() ;
calldos();
if ( (Registers.Flags & 0x0001) != 0 )
return ( FALSE ) ;
else
return ( TRUE ) ; /* 成功ならば 真 でreturn */
}
/*************************** ファイルサイズ取得 ****************************/
int getfsize()
{
DIR dta ;
ushort attr=0 ;
if ( firstsearch( Sndfile,attr,&dta ) ) { /* 最初のエントリ */
Sndsize = dta._fsize ;
return( dta._fsize ) ;
} else { /* ファイルが見つからない */
return( -1 ) ;
}
}
/**************************** 文字属性設定 *********************************/
void textatr( int t_sp,int f_st )
{
EGB_textDirection( Gwork,0 ) ;
EGB_textDisplayDirection( Gwork,0 ) ;
EGB_textSpace( Gwork,t_sp ) ; /* 文字間スペース [dot] */
EGB_textZoom( Gwork,0,8,16 ) ; /* ANK : 8 x 16 */
EGB_textZoom( Gwork,1,16,16 ) ; /* 漢字 : 16 x 16 */
EGB_fontStyle( Gwork,f_st ) ; /* 標準文字 */
}
/****************************** 文字出力 ***********************************/
void puttext( x, y, text, col )
int x, y, col ;
char *text ;
{
uint sl ;
EGB_color( Gwork,0,col ) ; /* 前景色 */
WORD( Para+0 ) = x ; /* X Point */
WORD( Para+2 ) = y ; /* Y Point */
sl = strlen( text ) ;
WORD( Para+4 ) = sl ;
strcpy( Para+6,text ) ;
EGB_sjisString( Gwork,Para ) ; /* 文字表示 */
}
/*************************** SND DATA の読込み *****************************/
void snd_load()
{
FILE *fp;
Sndflg = FALSE ;
if ( getfsize() == -1 ) return ;
Snddata = malloc( Sndsize ) ; /* SND データ格納領域確保 */
if ( Snddata == NULL ) {
printf("<snd_load> malloc error!\n") ;
return ;
} else {
fp = fopen( Sndfile,"rb" ) ;
fread( Snddata,1,Sndsize,fp ) ;
fclose( fp ) ;
Sndflg = TRUE ;
}
memcpy( Snd.buf,Snddata,30 ) ;
if ( !Sndflg ) {
printf("\x1b[33m") ;
printf(".SND ファイル ( %s ) を読み込めませんでした。\x1b[m\n",Sndfile) ;
return ;
} else {
printf("音声データ \x1b[36m%s \x1b[m",Sndfile) ;
printf(" を再生します。\n") ;
}
printf("\n") ;
/*
** PCM 音声を初期設定する
*/
SND_pcm_mode_set( 1 ) ; /* PCM音声モードチャンネル数設定 */
SND_volume_change( 71,127 ) ; /* 最大ボリュームにする */
}
/*************************** マウス初期化 **********************************/
void minit()
{
MOS_start( Mwork,MworkSize ) ;
MOS_disp( FALSE ) ; /* マウス非表示 */
}
/******************************* 初期設定 **********************************/
void init()
{
SND_init( Swork ) ; /* サウンド初期化 */
snd_load() ;
SND_elevol_mute( 0x0001 ) ; /* PCM 音源のみミュート解除*/
SND_elevol_all_mute( -1 ) ; /* 全ミュートの解除 */
/*
** TownsMENUは、Page 1 & 0 で Page 1 が前面, MENUは Page 0 に書かれている。
** V1.1 L20 時点。
*/
EGB_displayPage( Gwork,1,3 ) ; /* Show page 0 & 1 : Priority 1 */
minit() ; /* マウス初期化 */
EGB_writePage( Gwork,1 ) ; /* Write to Page 1 */
EGB_writeMode( Gwork,OPAQUE ) ; /* 背景色で塗り潰して */
EGB_color( Gwork,0,C_BLACK ) ; /* 前景色 : Black */
EGB_color( Gwork,1,C_HWHITE ) ; /* 背景色 : H_White */
EGB_color( Gwork,2,C_HGREEN ) ; /* 面塗色 : H_Green */
EGB_color( Gwork,3,C_BLACK ) ; /* 透過色 : Black */
EGB_displayStart( Gwork,0,0,0 ) ; /* 表示開始位置 */
EGB_displayStart( Gwork,1,0,0 ) ; /* 仮想画面位置 */
EGB_displayStart( Gwork,2,1,1 ) ; /* 画面の拡大 */
EGB_displayStart( Gwork,3,639,479 ) ; /* 画面の大きさ */
textatr( 0,0 ) ;
}
/******************************** プレイ開始 *********************************/
void play_start()
{
char buf[128] ;
int mbot, mx, my ;
int c ;
do { /* マウスの開放を待つ */
MOS_rdpos( &mbot,&mx,&my ) ;
} while ( mbot ) ;
strcpy( buf," " ) ;
c = ( 80 - strlen( buf ) ) / 2 + 1 ;
puttext( c*8,11*16+1,buf,C_HBLACK ) ;
sprintf( buf,"< %s >",Sndfile ) ;
c = ( 80 - strlen( buf ) ) / 2 + 1 ;
puttext( c*8,11*16+1,buf,C_HBLACK ) ;
sprintf( buf,"を再生します♪ (NOTE=%d)",Snd.data.onkai ) ;
c = ( 80 - strlen( buf ) ) / 2 + 1 ;
puttext( c*8,12*16+9,buf,C_HBLACK ) ;
SND_pcm_play_stop( 71 ) ;
SND_pcm_play( 71,Snd.data.onkai,127,Snddata ) ;
while ( TRUE ) {
if ( !SND_pcm_status( 71 ) ) break ;
MOS_rdpos( &mbot,&mx,&my ) ;
if ( mbot ) break ;
}
SND_pcm_play_stop( 71 ) ;
}
/********************************* メイン **********************************/
void main( int ac, char *av[] )
{
int endp ;
printf("SNDPLAY.EXP v0.50 (c) パオパオ 1991. ") ;
printf("<< Copyright (C) Y.Hirata 1991. >>\n") ;
if ( ac > 1 ) { /* 引数あり */
strcpy( Sndfile,av[1] ) ;
endp = strlen( Sndfile ) ;
if ( strchr( Sndfile,'.' ) == NULL ) { /* ファイル拡張子なし */
strcat( Sndfile,".SND" ) ;
} else {
if ( strcmp( Sndfile+endp-4,".SND" ) &&
strcmp( Sndfile+endp-4,".snd" ) ) {
printf("\x1b[31mERROR\x1b[m : FILE NAME ( %s ) - ",Sndfile) ;
printf(".SND ファイル しか指定できません!\n") ;
exit( 1 ) ;
}
}
} else { /* 引数なし */
printf(".SND ファイルを指定して下さい。\n") ;
exit( 1 ) ;
}
INT23_init() ; /* ^C マスク設定 */
init() ; /* 各種初期設定 */
if ( Sndflg )
play_start() ; /* プレイ開始 */
close:
if ( Sndflg ) {
free( Snddata ) ;
}
SND_end() ; /* サウンド終了 */
INT23_end() ; /* ^C マスク解除 */
printf("\nプログラムを終了します。\n") ;
}