|
From: Martin R. <ru...@us...> - 2007-04-04 14:36:08
|
Update of /cvsroot/foo/foo/libfoo/src In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv18815/libfoo/src Modified Files: FOOSoundFile.m Makefile.am Log Message: added rudimentary flac support Index: Makefile.am =================================================================== RCS file: /cvsroot/foo/foo/libfoo/src/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 26 Aug 2004 09:47:52 -0000 1.5 --- Makefile.am 4 Apr 2007 14:36:04 -0000 1.6 *************** *** 36,39 **** --- 36,40 ---- if USE_GNUSTEP_BASE + include @GNUSTEP_MAKEFILES@/config.make include @GNUSTEP_MAKEFILES@/library-combo.make include @GNUSTEP_MAKEFILES@/common.make Index: FOOSoundFile.m =================================================================== RCS file: /cvsroot/foo/foo/libfoo/src/FOOSoundFile.m,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FOOSoundFile.m 28 Feb 2005 16:37:22 -0000 1.8 --- FOOSoundFile.m 4 Apr 2007 14:36:04 -0000 1.9 *************** *** 38,41 **** --- 38,42 ---- #include "FOO/FOOSoundFile.h" + #include "config.h" #import <Foundation/NSKeyedArchiver.h> *************** *** 116,119 **** --- 117,124 ---- } + // open file + _fileInfo.format = 0; // recommended by erik de castro lopo (libsndfile) + _fileName = RETAIN(name); + switch (sndmode) { *************** *** 126,131 **** we need to evaluate the header data of an already existing file, even if purely writing it */ // mode = SFM_WRITE; ! // break; case SND_ADDIN: --- 131,168 ---- we need to evaluate the header data of an already existing file, even if purely writing it */ + + /* hacky workaround for writing flac files: SFM_RDWR not + possible here, so determine header info by opening read only, + than open write only. works only for empty soundfiles, since + cache handling needs read access to file */ + #ifdef HAVE_SNDFILE_FLAC_SUPPORT + if (! (_file = sf_open([_fileName cString], SFM_READ, &_fileInfo))) + { + fprintf(stderr, "libsndfile: %s\n", sf_strerror(_file)); + FOO_ERROR(YES, NO); + } + + // flac ahead? + if ((_fileInfo.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_FLAC) + { + mode = SFM_WRITE; + } + else + { + mode = SFM_RDWR; + _fileInfo.format = 0; // reset + } + if (sf_close(_file)) + { + fprintf(stderr, "libsndfile: %s\n", sf_strerror(_file)); + FOO_ERROR(YES, NO); + } + _file = NULL; + + break; + #else // #ifdef HAVE_SNDFILE_FLAC_SUPPORT // mode = SFM_WRITE; ! break; ! #endif // #ifdef HAVE_SNDFILE_FLAC_SUPPORT case SND_ADDIN: *************** *** 137,144 **** } - // open file - _fileInfo.format = 0; // recommended by erik de castro lopo (libsndfile) - _fileName = RETAIN(name); - if (! (_file = sf_open([_fileName cString], mode, &_fileInfo))) { --- 174,177 ---- *************** *** 436,440 **** _cache.firstDirtyF = fromFrame; } ! if (_cache.lastDirtyF< lastF) { _cache.lastDirtyF = lastF; --- 469,473 ---- _cache.firstDirtyF = fromFrame; } ! if (_cache.lastDirtyF < lastF) { _cache.lastDirtyF = lastF; *************** *** 784,804 **** // seek #ifdef FOOSOUNDFILE_DEBUG ! { ! sf_count_t newpos; ! if ((newpos = sf_seek(_file, _cache.firstDirtyF, SEEK_SET)) == -1) #else ! if (sf_seek(_file, _cache.firstDirtyF, SEEK_SET) == -1) #endif ! { ! fprintf(stderr, "libsndfile: %s\n", sf_strerror(_file)); ! FOO_ERROR(YES, NO); ! } ! #ifdef FOOSOUNDFILE_DEBUG ! fprintf(stderr, "seeked to frame %ld in file\n", (long)newpos); ! } #endif // write --- 817,837 ---- // seek + if (sf_seek(_file, 0, SEEK_CUR) != _cache.firstDirtyF) + { #ifdef FOOSOUNDFILE_DEBUG ! sf_count_t newpos; ! if ((newpos = sf_seek(_file, _cache.firstDirtyF, SEEK_SET)) == -1) #else ! if (sf_seek(_file, _cache.firstDirtyF, SEEK_SET) == -1) #endif ! { ! fprintf(stderr, "libsndfile: %s\n", sf_strerror(_file)); ! FOO_ERROR(YES, NO); ! } #ifdef FOOSOUNDFILE_DEBUG ! fprintf(stderr, "seeked to frame %ld in file\n", (long)newpos); #endif + } // write |