Skip to content

Commit

Permalink
Fix wave bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
liufeigit committed Jan 17, 2024
1 parent 44b4231 commit 86d298d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/util/flux_wave.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ char __wav_header[44]={
0x00, 0x00, 0x00, 0x00
};

static int __readChunkSize(FILE *file);
static void __readChunkName(FILE *file);

int waveReadObj_new(WaveReadObj *waveObj,char *fileName){
int status=0;
WaveReadObj wave=NULL;
Expand All @@ -76,8 +79,10 @@ int waveReadObj_new(WaveReadObj *waveObj,char *fileName){
unsigned int offset=0;
unsigned int dataSize=0;

char *chunkName=NULL;

wave=*waveObj=(WaveReadObj )calloc(1, sizeof(struct OpaqueWaveRead ));
fp=fopen(fileName, "rb+");
fp=fopen(fileName, "rb");

fread(&header, 1, sizeof(header), fp);
if(header.fmtSize<16){
Expand All @@ -92,6 +97,24 @@ int waveReadObj_new(WaveReadObj *waveObj,char *fileName){
// printf("format is %d\n",header.format);

offset=20+header.fmtSize+4; // ???
fseek(fp, offset, SEEK_SET);

// LIST
chunkName=(char *)calloc(5, sizeof(char ));
strncpy(chunkName,header.data,4);
while(strncmp(chunkName, "data", 4)){
int skipSize=0;

fread(&skipSize, 1, sizeof(int ), fp);
offset+=4;

offset+=skipSize;
fseek(fp, offset, SEEK_SET);
fread(chunkName, 4, sizeof(char ), fp);

offset+=4;
}

fseek(fp, offset, SEEK_SET);
fread(&dataSize, 1, sizeof(unsigned int ), fp);

Expand All @@ -105,6 +128,7 @@ int waveReadObj_new(WaveReadObj *waveObj,char *fileName){

wave->dataLength=dataSize/(header.bit/ 8);

free(chunkName);
return status;
}

Expand Down Expand Up @@ -215,7 +239,7 @@ int waveWriteObj_new(WaveWriteObj *waveObj,char *fileName,
int _channelNum=1;

wave=*waveObj=(WaveWriteObj )calloc(1, sizeof(struct OpaqueWaveWrite ));
fp=fopen(fileName, "wb+");
fp=fopen(fileName, "wb");

if(samplate){
if(*samplate>0&&*samplate<=196000){
Expand Down

0 comments on commit 86d298d

Please sign in to comment.