home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 24
/
CD_ASCQ_24_0995.iso
/
dos
/
prg
/
dsik205
/
dsik.dat
/
EXAMPLES
/
EXAMP07.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-10
|
8KB
|
260 lines
/****************************************************************************
*
* Digital Sound Interface Kit (DSIK)
* Version 2.00
*
* by Carlos Hasan
*
* Filename: example7.c
* Version: Revision 1.0
*
* Language: WATCOM C
* Environment: IBM PC (DOS/4GW)
*
* Description: Music module and sound sequencer.
*
* Revision History:
* ----------------
*
* Revision 1.0 94/10/28 23:16:47 chv
* Initial revision
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <i86.h>
#include "audio.h"
#include "import.h"
#include "timer.h"
#ifdef SHAREWARE
#define NUMVOICES 4
#else
#define NUMVOICES 16
#endif
typedef struct {
int frame,sec,min,hour;
} SMPTE;
SMPTE smpte;
/* timer interrupt handler called 100 times per second, it will update
the current SMPTE time and call the dPoll() routine */
void timer(void)
{
if (++smpte.frame >= 100) {
smpte.frame = 0;
if (++smpte.sec >= 60) {
smpte.sec = 0;
if (++smpte.min >= 60) {
smpte.min = 0;
if (++smpte.hour >= 24) {
smpte.hour = 0;
}
}
}
}
dPoll();
}
long getcurtime(void)
{
return smpte.frame+100L*smpte.sec+6000L*smpte.min+360000L*smpte.hour;
}
long gettime(int hour, int min, int sec, int frame)
{
return frame+100L*sec+6000L*min+360000L*hour;
}
void waittime(int hour, int min, int sec, int frame)
{
long n;
n = gettime(hour,min,sec,frame);
while (n > getcurtime()) {
cprintf("[%02d:%02d:%02d.%02d]\r", smpte.hour, smpte.min,
smpte.sec, smpte.frame);
if (kbhit()) {
switch (toupper(getch())) {
case 0x1B:
cprintf("\nAborted.\n\r");
exit(EXIT_FAILURE);
break;
case 0x0D:
cprintf("\n\r");
break;
case 0x20:
smpte.hour = hour;
smpte.min = min;
smpte.sec = sec;
smpte.frame = frame;
break;
}
}
}
}
int main(int argc, char *argv[])
{
FILE *f;
DSM *mod,*m;
Sample *smp,*s;
SoundCard SC;
SMPTE t;
char seqpath[_MAX_PATH],path[_MAX_PATH];
char drive[_MAX_DRIVE],dir[_MAX_DIR],name[_MAX_FNAME],ext[_MAX_EXT];
int mvol,svol,sbal;
char buf[128];
int i,linenum;
printf("\nSound Sequencer V1.00 Copyright (C) 1995 Carlos Hasan\n");
if (argc < 2) {
printf("Use: SEQ [options] eventfile[.seq]\n");
printf("\t-m###\tmusic volume (0-255)\n");
printf("\t-s###\tsfx volume (0-255)\n");
printf("\t-b###\tsfx balance (0=left,128=right)\n\n");
printf("Used to sequence MOD/S3M/MTM/STM/669/DSM music module files\n");
printf("and WAV/VOC/IFF/RAW/SMP sample files.\n");
exit(EXIT_FAILURE);
}
strcpy(seqpath,"default.seq");
mvol = svol = 255;
sbal = 64;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'm':
mvol = atoi(&argv[i][2]);
break;
case 's':
svol = atoi(&argv[i][2]);
break;
case 'b':
sbal = atoi(&argv[i][2]);
break;
default:
printf("Unknown -%c option.\n",argv[i][1]);
exit(EXIT_FAILURE);
}
}
else {
strncpy(seqpath,argv[i],sizeof(seqpath));
}
}
strupr(seqpath);
_splitpath(seqpath,drive,dir,name,ext);
if (!*ext) strcpy(ext,".SEQ");
_makepath(seqpath,drive,dir,name,ext);
dRegisterDrivers();
if (dLoadSetup(&SC,"SETUP.CFG")) {
printf("Please run SETUP.EXE to configure.\n");
exit(EXIT_FAILURE);
}
printf("%s at Port %03Xh using IRQ %d on DMA channel %d\n\n",
dGetDriverStruc(SC.ID)->Name, SC.Port, SC.IrqLine, SC.DmaChannel);
if (dInit(&SC)) {
printf("Error initializing the sound system.\n");
exit(EXIT_FAILURE);
}
atexit((void(*)(void))dDone);
dSetupVoices(NUMVOICES+1,128);
dSetMusicVolume(mvol);
dSetSoundVolume(svol);
dSetVoiceBalance(NUMVOICES,sbal);
dInitTimer();
atexit((void(*)(void))dDoneTimer);
dStartTimer(timer,TICKS(100));
if (!(f = fopen(seqpath,"rt"))) {
printf("Error opening %s event file.\n",seqpath);
exit(EXIT_FAILURE);
}
mod = NULL;
smp = NULL;
for (linenum = 1; fgets(buf,sizeof(buf),f); linenum++) {
if (buf[0] == ';' || buf[0] == '\n') continue;
if (sscanf(buf,"%02d:%02d:%02d.%02d %s", &t.hour, &t.min,
&t.sec, &t.frame, path) != 5) {
printf("Error reading file %s line %d.\n", seqpath, linenum);
exit(EXIT_FAILURE);
}
strupr(path);
_splitpath(path,drive,dir,name,ext);
_makepath(path,drive,dir,name,ext);
if (!strcmp(ext,".DSM")) i = FORM_DSM;
else if (!strcmp(ext,".MOD")) i = FORM_MOD;
else if (!strcmp(ext,".S3M")) i = FORM_S3M;
else if (!strcmp(ext,".MTM")) i = FORM_MTM;
else if (!strcmp(ext,".669")) i = FORM_669;
else if (!strcmp(ext,".STM")) i = FORM_STM;
else if (!strcmp(ext,".WAV")) i = FORM_WAV;
else if (!strcmp(ext,".VOC")) i = FORM_VOC;
else if (!strcmp(ext,".IFF")) i = FORM_IFF;
else if (!strcmp(ext,".RAW")) i = FORM_RAW;
else if (!strcmp(ext,".SMP")) i = FORM_RAW;
else {
printf("Unknown file format: %s\n",path);
exit(EXIT_FAILURE);
}
if (i < FORM_WAV) {
if (!(m = dImportModule(path,i))) {
printf("Error (%03d) loading %s module file: %s.\n",
dError, path, dErrorMsg[dError]);
exit(EXIT_FAILURE);
}
waittime(t.hour,t.min,t.sec,t.frame);
if (mod) {
for (i = mvol; i >= 0; i--) {
dSetMusicVolume(i);
delay(5);
}
dStopMusic();
dFreeModule(mod);
}
printf("Playing module %s%s\n",name,ext);
mod = m;
dPlayMusic(mod);
dSetMusicVolume(mvol);
}
else {
if (!(s = dImportSample(path,i))) {
printf("Error (%03d) loading %s sample file: %s.\n",
dError, path, dErrorMsg[dError]);
exit(EXIT_FAILURE);
}
waittime(t.hour,t.min,t.sec,t.frame);
if (smp) {
dStopVoice(NUMVOICES);
dFreeSample(smp);
}
printf("Playing sample %s%s\n",name,ext);
smp = s;
dPlayVoice(NUMVOICES,smp);
}
}
fclose(f);
printf("Press SPACE to quit.\n");
waittime(23,59,59,0);
dStopMusic();
dStopVoice(NUMVOICES);
if (mod) dFreeModule(mod);
if (smp) dFreeSample(smp);
printf("Done. \n");
return EXIT_SUCCESS;
}