home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
utils
/
sfxmake.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-12
|
2KB
|
94 lines
#include <fstream.h>
#include <dir.h>
#include <string.h>
#include <io.h>
#include <values.h>
#include "utils.h"
const long BUFSIZE = MAXINT;
int create_gfxlib(int argc, char *argv[]);
int main(int argc,char** argv)
{
//-----------------------------------------------------
// check for two arguments
if (argc<2)
{
cout << "\nUSAGE : SFXMAKE <sfxlib> <file1, ...> @<listfile>\n"
" SFXMAKE constructs SFX sound effects libraries\n"
" from the files listed on the command line or in\n"
" <listfile>. SFXMAKE constructs the SFX library\n"
" with the entries in the order in which they appear\n"
" on the command file and/or in <listfile>.\n";
return -1;
}
if (create_gfxlib(argc, argv))
cout << "ok\n";
return 0;
} // main
static int count;
static char* sndbuffer;
static ofstream sfxlib;
void bld_sfxlib(char *file);
int create_gfxlib(int argc, char *argv[])
{
//-----------------------------------------------------
// allocate buffer for sound files
sndbuffer=new char[(size_t)BUFSIZE];
//------------------------------------------------------
// open the new file
// write out the count
// write out size/data pairs
// close file
sfxlib.open(argv[1],ios::binary);
count = 0;
sfxlib.write((char*)&count,sizeof(count));
int rtn = parse_cmdline(argc-2, argv+2, bld_sfxlib);
if (rtn) {
sfxlib.seekp(0);
sfxlib.write((char*)&count,sizeof(count));
cout << "stored " << count << " entries\n";
}
sfxlib.close();
delete sndbuffer;
return rtn;
}
void bld_sfxlib(char *file)
{
ifstream clip;
struct ffblk ffblk;
long size;
findfirst(file,&ffblk,0);
size=ffblk.ff_fsize;
clip.open(file,ios::binary);
sfxlib.write((char*)&size,sizeof(size));
char *bf = sndbuffer;
int chread;
do
{
clip.read(bf, MAXINT);
chread = clip.gcount();
if (chread)
sfxlib.write(sndbuffer,chread);
} while (chread == MAXINT);
clip.close();
cout << (++count) << ": " << size << " bytes\n";
}