home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
120.lha
/
Muncho2
/
soundobj.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-21
|
1KB
|
72 lines
#include <exec/types.h>
#include <exec/memory.h>
#include <lattice/stdio.h>
#include "soundobj.h"
#define TICKS_PER_SEC (3579545)
struct SOUNDOBJ *SO_new(fn_)
char *fn_;
{
FILE *fopen();
FILE *fp_;
char *malloc();
struct SOUNDOBJ *p_;
BYTE *data_;
ULONG datalen;
UWORD rate;
int SO_sound();
int SO_delete();
if(!(fp_=fopen(fn_,"r"))){
return(NULL);
}
if(fread(&datalen,sizeof(ULONG),1,fp_) <= 0){
fclose(fp_);
return(NULL);
}
if(fread(&rate,sizeof(UWORD),1,fp_) <= 0){
fclose(fp_);
return(NULL);
}
if(!(data_=(BYTE *)AllocMem(datalen * sizeof(BYTE),MEMF_CHIP))){
fclose(fp_);
return(NULL);
}
if(fread(data_,datalen,1,fp_) <= 0){
fclose(fp_);
FreeMem(data_,datalen * sizeof(BYTE));
return(NULL);
}
fclose(fp_);
if(!(p_=(struct SOUNDOBJ *)malloc(sizeof(struct SOUNDOBJ)))){
FreeMem(data_,datalen * sizeof(BYTE));
return(NULL);
}
p_->data_ = data_;
p_->datalen = datalen;
p_->rate = rate;
p_->period = TICKS_PER_SEC/rate;
p_->sound = SO_sound;
p_->delete = SO_delete;
return(p_);
}
SO_delete(p_)
struct SOUNDOBJ *p_;
{
FreeMem(p_->data_,p_->datalen * sizeof(BYTE));
return(1);
}
SO_sound(p_)
struct SOUNDOBJ *p_;
{
audio_sound(p_->data_,p_->datalen,p_->period,60);
return(1);
}