home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 24
/
CD_ASCQ_24_0995.iso
/
dos
/
prg
/
dsik205
/
dsik.dat
/
EXAMPLES
/
EXAMP04.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-10
|
3KB
|
100 lines
/****************************************************************************
*
* Digital Sound Interface Kit (DSIK)
* Version 2.00
*
* by Carlos Hasan
*
* Filename: example4.c
* Version: Revision 1.0
*
* Language: WATCOM C
* Environment: IBM PC (DOS/4GW)
*
* Description: Play a sample using the keyboard like a piano.
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include "audio.h"
#include "import.h"
#define NUMVOICES 6
#define SMPPATH "SAMPLE.WAV"
#define SMPFORM FORM_WAV
#define FREQ(p) (((long)MIDCFREQ*MIDCPERIOD)/p)
int periodtable[48] =
/* C C# D D# E F F# G G# A A# B */
{ 856,808,762,720,678,640,604,570,538,508,480,453,
428,404,381,360,339,320,302,285,269,254,240,226,
214,202,190,180,170,160,151,143,135,127,120,113,
107,101,95,90,85,80,75,71,67,63,60,56 };
char keytable[36] = "ZSXDCVGBHNJMQ2W3ER5T6Y7UI9O0P";
int main(void)
{
SoundCard SC;
Sample *S;
int i,chan,key;
dRegisterDrivers();
if (dLoadSetup(&SC,"SETUP.CFG")) {
printf("Please run SETUP.EXE to configure.\n");
exit(EXIT_FAILURE);
}
if (dInit(&SC)) {
printf("Error initializing the sound system.\n");
exit(EXIT_FAILURE);
}
atexit((void(*)(void))dDone);
if (!(S = dImportSample(SMPPATH,SMPFORM))) {
printf("Error (%03d) loading %s sample file: %s.\n",
dError, SMPPATH, dErrorMsg[dError]);
exit(EXIT_FAILURE);
}
/* use N-note polyphony */
dSetupVoices(NUMVOICES,96);
printf("\n");
printf(" C# D# F# G# A# C# D# F# G# A# C# D# \n");
printf(" │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ \n");
printf(" │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ \n");
printf(" │ │S││D│ │ │G││H││J│ │ │2││3│ │ │5││6││7│ │ │9││0│ │ \n");
printf(" │ └┬┘└┬┘ │ └┬┘└┬┘└┬┘ │ └┬┘└┬┘ │ └┬┘└┬┘└┬┘ │ └┬┘└┬┘ │ \n");
printf(" │ Z│ X│ C│ V│ B│ N│ M│ Q│ W│ E│ R│ T│ Y│ U│ I│ O│ P│ \n");
printf(" └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘ \n");
printf(" C D E F G A B C D E F G A B C D E \n");
printf("\n");
printf(" Press keys to play the sample and ESC to exit. \n");
chan = 0;
do {
while (!kbhit()) dPoll();
if ((key = toupper(getch())) != 27) {
for (i = 0; i < 36; i++) {
if (key == keytable[i]) {
/* play chord C-E-G */
dPlayVoice(chan+0,S);
dPlayVoice(chan+1,S);
dPlayVoice(chan+2,S);
dSetVoiceFreq(chan+0,FREQ(periodtable[i+0]));
dSetVoiceFreq(chan+1,FREQ(periodtable[i+4]));
dSetVoiceFreq(chan+2,FREQ(periodtable[i+7]));
chan = (chan + 3) % NUMVOICES;
}
}
}
} while (key != 27);
dFreeSample(S);
return 0;
}