fixes artefacts at the end of wav files using other chunks after the main data chunk.

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@531 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Raphael Coeffic 19 years ago
parent 9444a145cc
commit 45ef66821f

@ -525,6 +525,7 @@ int AmAudioFile::open(const string& filename, OpenMode mode, bool is_tmp)
f_fmt->setSubtypeId(fd.subtype);
f_fmt->channels = fd.channels;
f_fmt->rate = fd.rate;
data_size = fd.data_size;
}
begin = ftell(fp);
}
@ -690,27 +691,40 @@ int AmAudioFile::read(unsigned int user_ts, unsigned int size)
return -1;
}
int s = fread((void*)((unsigned char*)samples),1,size,fp);
int ret = (!ferror(fp) ? s : -1);
int ret;
int s = size;
read_block:
if(ftell(fp) - begin < data_size){
if(ftell(fp) - begin + size > data_size){
s = data_size - ftell(fp) + begin;
}
s = fread((void*)((unsigned char*)samples),1,s,fp);
ret = (!ferror(fp) ? s : -1);
#if __BYTE_ORDER == __BIG_ENDIAN
#define bswap_16(A) ((((u_int16_t)(A) & 0xff00) >> 8) | \
(((u_int16_t)(A) & 0x00ff) << 8))
unsigned int i;
for(i=0;i<=size/2;i++) {
u_int16_t *tmp;
((u_int16_t *)((unsigned char*)samples))[i]=bswap_16(((u_int16_t *)((unsigned char*)samples))[i]);
}
#endif
//DBG("s = %i; ret = %i\n",s,ret);
if(loop.get() && (ret <= 0) && feof(fp)){
unsigned int i;
for(i=0;i<=size/2;i++) {
u_int16_t *tmp;
((u_int16_t *)((unsigned char*)samples))[i]=bswap_16(((u_int16_t *)((unsigned char*)samples))[i]);
}
DBG("rewinding audio file...\n");
rewind();
s = fread((void*)((unsigned char*)samples),1,size,fp);
ret = (!ferror(fp) ? s : -1);
#endif
}
else {
if(loop.get() && data_size>0){
DBG("rewinding audio file...\n");
rewind();
goto read_block;
}
ret = -2; // eof
}
if(ret > 0 && s > 0 && (unsigned int)s < size){
@ -719,7 +733,7 @@ int AmAudioFile::read(unsigned int user_ts, unsigned int size)
return size;
}
return (feof(fp) && !loop.get() ? -2 : ret);
return ret;
}
int AmAudioFile::write(unsigned int user_ts, unsigned int size)

@ -174,6 +174,8 @@ static int wav_read_header(FILE* fp, struct amci_file_desc_t* fmt_desc)
fseek(fp,chunk_size,SEEK_CUR);
}
fmt_desc->data_size = chunk_size;
return 0;
}

Loading…
Cancel
Save