home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 24
/
CD_ASCQ_24_0995.iso
/
dos
/
prg
/
dsik205
/
dsik.dat
/
EXAMPLES
/
EXAMP06.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-10
|
4KB
|
117 lines
/****************************************************************************
*
* Digital Sound Interface Kit (DSIK)
* Version 2.00
*
* by Carlos Hasan
*
* Filename: example6.c
* Version: Revision 1.0
*
* Language: WATCOM C
* Environment: IBM PC (DOS/4GW)
*
* Description: Play a huge 8-bit mono RAW sample file from disk.
*
* Note: You will hear small clicks between frames, because there
* is a small delay when you start playing a new a sample.
* Increasing the buffer length (see BUFLEN below) and polling
* the sound system more frequently will decrease the amount
* of clicks/cracks in the sound.
* This sound system was not designed to do this sort of
* things. Anyway, I think that would be useful to show
* how it can be done.
*
****************************************************************************/
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <conio.h>
#include "audio.h"
#include "import.h"
#include "timer.h"
/* 8-bit SIGNED mono raw sample file at 11kHz */
/* NOTE: you can use M2DSM.EXE to convert VOC/WAV/IFF to RAW files */
#define SMPPATH "TEST.RAW"
#define SMPFREQ 11025
/* chunk length in bytes (should be less than 256 Kb) */
#define BUFLEN 0x4000
int main(void)
{
SoundCard SC;
Sample *S[2];
int Handle;
long pos,len,filelen;
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);
dInitTimer();
atexit((void(*)(void))dDoneTimer);
dStartTimer((void(*)(void))dPoll,TICKS(200));
dSetupVoices(1,255);
dSetVoiceBalance(0,PAN_MIDDLE);
/* initialize sample structures */
S[0] = S[1] = NULL;
/* open huge sample file */
if ((Handle = open(SMPPATH,O_RDONLY|O_BINARY)) < 0) {
printf("Error opening sample file: %s\n",SMPPATH);
exit(EXIT_FAILURE);
}
if ((filelen = filelength(Handle)) < 0) {
printf("Error getting file length.\n");
exit(EXIT_FAILURE);
}
printf("Playing %ld samples from file %s\n", filelen, SMPPATH);
for (pos = 0; filelen > 0; pos ^= 1) {
/* print progress indicator on screen */
putch('.');
/* release sample structure (if previously allocated) */
if (S[pos]) {
dFreeSample(S[pos]);
S[pos] = NULL;
}
/* get length of the next chunk of samples */
len = (filelen > BUFLEN) ? BUFLEN : filelen;
filelen -= len;
/* load chunk of samples and set default frequency */
if (!(S[pos] = dImportSampleFile(Handle,len,FORM_RAW))) {
printf("Error (%03d) loading chunk of samples: %s.\n",
dError, dErrorMsg[dError]);
exit(EXIT_FAILURE);
}
S[pos]->Rate = SMPFREQ;
/* wait until previous chunk of samples finishes... */
while (dGetVoiceStatus(0) == PS_PLAYING) dPoll();
/* start playing new chunk of samples */
dPlayVoice(0,S[pos]);
}
/* wait until the last chunk of samples finishes */
while (dGetVoiceStatus(0) == PS_PLAYING) continue;
/* release sample buffers */
if (S[0]) dFreeSample(S[0]);
if (S[1]) dFreeSample(S[1]);
close(Handle);
return 0;
}