home *** CD-ROM | disk | FTP | other *** search
- USHORT *LoadSample();
- USHORT *AllocateMem();
- void KillSounds(), StartSound(), UpdateSounds();
-
- USHORT *waveform[NUMSAMPLES];
- USHORT wavelength[NUMSAMPLES];
- USHORT *dmaconw = (USHORT *)0xDFF096;
- USHORT inuse[4] = {0,0,0,0};
-
- ULONG *audioaddr[4] =
- {
- {(ULONG *)0xDFF0A0}, {(ULONG *)0xDFF0B0}, {(ULONG *)0xDFF0C0},
- {(ULONG *)0xDFF0D0},
- };
-
- USHORT *audiolen[4] =
- {
- {(USHORT *)0xDFF0A4}, {(USHORT *)0xDFF0B4}, {(USHORT *)0xDFF0C4},
- {(USHORT *)0xDFF0D4},
- };
-
- USHORT *audioper[4] =
- {
- {(USHORT *)0xDFF0A6}, {(USHORT *)0xDFF0B6}, {(USHORT *)0xDFF0C6},
- {(USHORT *)0xDFF0D6},
- };
-
- USHORT *audiovol[4] =
- {
- {(USHORT *)0xDFF0A8}, {(USHORT *)0xDFF0B8}, {(USHORT *)0xDFF0C8},
- {(USHORT *)0xDFF0D8},
- };
-
- USHORT *LoadSample(filename,length)
- char *filename;
- USHORT *length;
- {
- FILE *file;
- USHORT *buffer;
- ULONG size;
-
- if ((file=fopen(filename,"r"))==NULL) return(NULL);
- fseek(file,0L,2);
- size = ftell(file) & ~1L;
- fseek(file,0L,0);
- if ((buffer=AllocateMem(size,MEMF_CHIP))==NULL)
- {
- fclose(file);
- return(NULL);
- }
- *length=(USHORT)(fread((UBYTE *)buffer,1,(int)size,file)>>1);
- fclose(file);
- return(buffer);
- }
-
- USHORT *AllocateMem(size,requirements)
- ULONG size, requirements;
- {
- if (AvailMem(requirements)-size<=32000L) return(NULL);
- return((void *)AllocMem(size,requirements));
- }
-
- void KillSounds()
- {
- register int i;
-
- *dmaconw=0x000F;
- for (i=0;i<NUMSAMPLES;i++)
- if (waveform[i]) FreeMem(waveform[i],wavelength[i]<<1);
- }
-
- void StartSound(locat,len,jiffs,per,vol,chan)
- USHORT *locat;
- USHORT len;
- USHORT jiffs,per,vol,chan;
- {
- if (locat!=NULL)
- {
- if (inuse[chan]==0)
- {
- inuse[chan]=jiffs;
- *audioaddr[chan]=(ULONG)locat;
- *audiolen[chan]=len;
- *audioper[chan]=per;
- *audiovol[chan]=vol;
- switch (chan)
- {
- case 0: *dmaconw=0x8201;break;
- case 1: *dmaconw=0x8202;break;
- case 2: *dmaconw=0x8204;break;
- case 3: *dmaconw=0x8208;break;
- default: break;
- }
- }
- }
- }
-
- void UpdateSounds()
- {
- register int i;
-
- for (i=0;i<4;i++)
- {
- if (inuse[i]!=0)
- {
- inuse[i]--;
- if (inuse[i]==0)
- {
- switch (i)
- {
- case 0: *dmaconw=0x1;break;
- case 1: *dmaconw=0x2;break;
- case 2: *dmaconw=0x4;break;
- case 3: *dmaconw=0x8;break;
- }
- }
- }
- }
- }
-