Finish making Peaks use Clip

This commit is contained in:
Jonathan Moore Liles 2008-02-17 17:33:59 -06:00
parent bb0b511122
commit d36804ea4e
3 changed files with 17 additions and 19 deletions

2
Clip.C
View File

@ -46,7 +46,7 @@ Clip::Clip ( const char *filename ) : _peaks( this )
sf_close( in ); sf_close( in );
_peaks.open( filename ); _peaks.open();
} }

28
Peaks.C
View File

@ -179,11 +179,13 @@ peakname ( const char *filename )
} }
bool bool
Peaks::open ( const char *filename ) Peaks::open ( void )
{ {
const char *filename = _clip->name();
int fd; int fd;
make_peaks( filename, 256 ); make_peaks( 256 );
if ( ( fd = ::open( peakname( filename ), O_RDONLY ) ) < 0 ) if ( ( fd = ::open( peakname( filename ), O_RDONLY ) ) < 0 )
return false; return false;
@ -208,24 +210,16 @@ Peaks::open ( const char *filename )
return true; return true;
} }
void
long_to_float( long *buf, int len )
{
for ( int i = len; i--; )
*((float*)buf) = *buf / 32768;
}
/** returns false if peak file for /filename/ is out of date */ /** returns false if peak file for /filename/ is out of date */
bool bool
Peaks::current ( const char *filename ) Peaks::current ( void ) const
{ {
int sfd, pfd; int sfd, pfd;
if ( ( sfd = ::open( filename, O_RDONLY ) ) < 0 ) if ( ( sfd = ::open( _clip->name(), O_RDONLY ) ) < 0 )
return true; return true;
if ( ( pfd = ::open( peakname( filename ), O_RDONLY ) ) < 0 ) if ( ( pfd = ::open( peakname( _clip->name() ), O_RDONLY ) ) < 0 )
return false; return false;
struct stat sst, pst; struct stat sst, pst;
@ -242,9 +236,11 @@ Peaks::current ( const char *filename )
/** build peaks file for /filename/ if necessary */ /** build peaks file for /filename/ if necessary */
bool bool
Peaks::make_peaks ( const char *filename, int chunksize ) Peaks::make_peaks ( int chunksize )
{ {
if ( current( filename ) ) const char *filename = _clip->name();
if ( current() )
return true; return true;
if ( ! _clip->open() ) if ( ! _clip->open() )
@ -272,4 +268,6 @@ Peaks::make_peaks ( const char *filename, int chunksize )
_clip->close(); _clip->close();
fclose( fp ); fclose( fp );
return true;
} }

View File

@ -80,10 +80,10 @@ public:
void downsample ( int s, int e, float *mhi, float *mlo ) const; void downsample ( int s, int e, float *mhi, float *mlo ) const;
void read ( int X, float *hi, float *lo ) const; void read ( int X, float *hi, float *lo ) const;
bool open ( const char *filename ); bool open ( void );
bool current ( const char *filename ); bool current ( void ) const;
bool make_peaks ( const char *filename, int chunksize ); bool make_peaks ( int chunksize );
Peak & operator[] ( int X ) const; Peak & operator[] ( int X ) const;