Code: Select all
typedef struct
{
char riff[4];//'RIFF'
unsigned int riffSize;
char wave[4];//'WAVE'
char fmt[4];//'fmt '
unsigned int fmtSize;
unsigned short format;
unsigned short channels;
unsigned int samplesPerSec;
unsigned int bytesPerSec;
unsigned short blockAlign;
unsigned short bitsPerSample;
char data[4];//'data'
unsigned int dataSize;
} BasicWAVEHeader;
char* readWAV(char* filename,BasicWAVEHeader* header,IrrlichtDevice* device)
{
char* buffer = 0;
FILE* file = fopen(filename,"rb");
if (!file)
{
device->getLogger()->log("Couldn't open.");
return 0;
}
if (fread(header,sizeof(BasicWAVEHeader),1,file))
{
if (!(//these things *must* be valid with this basic header
memcmp("RIFF",header->riff,4) ||
memcmp("WAVE",header->wave,4) ||
memcmp("fmt ",header->fmt,4) ||
memcmp("data",header->data,4)
))
{
buffer = (char*)malloc(header->dataSize);
if (buffer)
{
if (fread(buffer,header->dataSize,1,file))
{
fclose(file);
return buffer;
}
free(buffer);
}
}
}
fclose(file);
return 0;
}
Is it possible to do, even with the BasicWAVEHeader struct?