[linux-audio-dev] [patch] speed up libaudiofile

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: [linux-audio-dev] [patch] speed up libaudiofile
From: Richard Guenther (richard.guenther_AT_student.uni-tuebingen.de)
Date: Sat Mar 25 2000 - 19:32:30 EET


Hi!

The following patch speeds up reading of the "common" .wav fileformat
by ~1000%. So read_file is no longer the bottlenet for GLAME. Patch
is against recent CVS checkout.

Btw, I cannot reach Michael and the last changes to the libaudiofile
CVS seem rather old, is libaudiofile considered "dead"? What replaced it?

Have fun, Richard.

--
Richard Guenther <richard.guenther_AT_student.uni-tuebingen.de>
WWW: http://www.anatom.uni-tuebingen.de/~richi/
The GLAME Project: http://www.glame.de/

Index: libaudiofile/af_vfs.c =================================================================== RCS file: /cvs/gnome/audiofile/libaudiofile/af_vfs.c,v retrieving revision 1.2 diff -u -r1.2 af_vfs.c --- libaudiofile/af_vfs.c 1999/11/21 00:05:19 1.2 +++ libaudiofile/af_vfs.c 2000/03/25 17:20:44 @@ -43,31 +43,7 @@ free(vfile); } -size_t -af_fread(void *data, size_t size, size_t nmemb, AF_VirtualFile *vfile) -{ - if(vfile->read) { - int retval; - retval = (* vfile->read) (vfile, data, size * nmemb); - - return retval/size; - } else - return 0; -} - -size_t -af_fwrite(const void *data, size_t size, size_t nmemb, AF_VirtualFile *vfile) -{ - if(vfile->write) { - int retval; - - retval = (* vfile->write) (vfile, data, size * nmemb); - - return retval/size; - } else - return 0; -} int af_fclose(AF_VirtualFile *vfile) Index: libaudiofile/af_vfs.h =================================================================== RCS file: /cvs/gnome/audiofile/libaudiofile/af_vfs.h,v retrieving revision 1.2 diff -u -r1.2 af_vfs.h --- libaudiofile/af_vfs.h 1999/11/21 00:05:19 1.2 +++ libaudiofile/af_vfs.h 2000/03/25 17:20:44 @@ -48,11 +48,29 @@ AF_VirtualFile *af_virtual_file_new_for_file(FILE *fh); void af_virtual_file_destroy(AF_VirtualFile *vfile); -size_t af_fread(void *data, size_t size, size_t nmemb, AF_VirtualFile *vfile); -size_t af_fwrite(const void *data, size_t size, size_t nmemb, AF_VirtualFile *vfile); int af_fclose(AF_VirtualFile *vfile); long af_flength(AF_VirtualFile *vfile); int af_fseek(AF_VirtualFile *vfile, long offset, int whence); long af_ftell(AF_VirtualFile *vfile); + +/* + Inlined trampolines to the virtual methods. + FIXME: we should not allow vfile->read/write == NULL +*/ + +static inline size_t af_fread(void *data, size_t size, size_t nmemb, AF_VirtualFile *vfile) +{ + if (!vfile->read) + return 0; + return ((* vfile->read) (vfile, data, size * nmemb))/size; +} + +static inline size_t af_fwrite(const void *data, size_t size, size_t nmemb, AF_VirtualFile *vfile) +{ + if (!vfile->write) + return 0; + return ((* vfile->write) (vfile, data, size * nmemb))/size; +} + #endif Index: libaudiofile/bread.c =================================================================== RCS file: /cvs/gnome/audiofile/libaudiofile/bread.c,v retrieving revision 1.13 diff -u -r1.13 bread.c --- libaudiofile/bread.c 1999/08/16 16:46:42 1.13 +++ libaudiofile/bread.c 2000/03/25 17:20:44 @@ -47,7 +47,7 @@ u_int8_t *buffer8 = (u_int8_t *) samples; u_int16_t *buffer16 = (u_int16_t *) samples; u_int32_t *buffer32 = (u_int32_t *) samples; - int frameSize, channelCount; + int frameSize, channelCount, res; assert(file); assert(track == AF_DEFAULT_TRACK); @@ -126,17 +126,31 @@ switch (file->sampleFormat) { case AF_SAMPFMT_TWOSCOMP: - while (done < sampleCount) - { - if (af_fread(&datum, 2, 1, file->fh) < 1) + if (file->byteOrder != file->virtualByteOrder) { + while (done < sampleCount) { - _af_error(AF_BAD_READ); - break; + res = af_fread(buffer16, 2, sampleCount-done, file->fh); + if (res < 1) { + _af_error(AF_BAD_READ); + break; + } + done += res; + while (res-->0) { + *buffer16 = _af_byteswapint16(*buffer16); + buffer16++; + } } - if (file->byteOrder != file->virtualByteOrder) - datum = _af_byteswapint16(datum); - *buffer16++ = datum; - done++; + } else { + while (done < sampleCount) + { + res = af_fread(buffer16, 2, sampleCount-done, file->fh); + if (res < 1) { + _af_error(AF_BAD_READ); + break; + } + buffer16 += res; + done += res; + } } break;


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Sat Mar 25 2000 - 20:07:10 EET