// All listings are for Watcom C++ 10.6 and are unoptimized to increase // readability. Copyright (C)1998 Robert Basler // Listing 1 - LoadWav int16 LoadWav(FILE *wav, dword *flags, dword *dataposition, dword *datasize) { *flags=0; *dataposition=0; *datasize=0; dword riffsignature, chunkid, chunksize, nextseek, filesize, hd32; int16 hd16; fread(&riffsignature,1,sizeof(riffsignature),wav); // Make sure is a RIFF file if(riffsignature!=0x46464952) return(-1); // RIFF // Get the size of the first chunk, not including the chunk size and id. fread(&chunksize,1,sizeof(filesize),wav); // Get the chunk id, make sure it is a WAV file. fread(&chunkid,1,sizeof(chunkid),wav); if(chunkid!=0x45564157) return(S3DE_BADTRACK); // WAVE filesize=chunksize+sizeof(riffsignature)+sizeof(chunksize); nextseek=sizeof(chunksize)+sizeof(riffsignature)+sizeof(chunkid); while(nextseek2) return(-1); if (hd16==2) *flags|=S3DF_STEREO; // Samples per second - values seem to vary from exact values fread(&hd32,1,sizeof(hd32),wav); // so accept ranges. if (hd32<=10512) *flags|=S3DF_8000; else if ((hd32>10512) && (hd32<=16537)) *flags|=S3DF_11025; else if ((hd32>16537) && (hd32<=33075)) *flags|=S3DF_22050; else *flags|=S3DF_44100; fread(&hd32,1,sizeof(hd32),wav); // Throughput bytes per second fread(&hd16,1,sizeof(hd16),wav); // Block alignment fread(&hd16,1,sizeof(hd16),wav); // Bits per sample if (hd16==8) *flags|=S3DF_8bit; else if (hd16==16) *flags|=S3DF_16bit; else return(-1); break; }; case 0x61746164: {//Data Chunk *dataposition=nextseek+sizeof(chunksize)+sizeof(chunkid); *datasize=chunksize; break; }; default: break; } nextseek=chunksize+nextseek+sizeof(chunkid)+sizeof(chunksize); } if ((*flags==0) || (*dataposition==0) || (*datasize==0)) return(-1); return(0); }; // Listing 2 - convert16to8 // Convert 16 bit sample buffer to 8 bit sample buffer. void convert16to8(void *inbuf16, void *outbuf8, dword bufsize8); /#pragma aux convert16to8 = \ " pushf" /* Save flags register and check parameters */ \ " or esi,esi"\ " jz done"\ " or edi,edi"\ " jz done"\ " or ecx,ecx"\ " jz done"\ " cld" /* Make sure we are going the right way for the loop */ \ "top:"\ " mov ax,word ptr [esi]" /* Get 16-bit signed sample */ \ " add esi,2" /* On to next sample */ \ " xor ah,0x80" /* Invert high bit of high byte of sample */ \ " mov byte ptr [edi],ah" /* Save the converted sample */ \ " inc edi" /* And so on and so on... */ \ " loop top"\ "done:"\ " popf"\ parm [esi] [edi] [ecx]\ modify [ax esi edi ecx]; // Listing 3 - initvolumetable void initvolumetable(void) { for (int32 volume=0;volume