Support optional mipmapping of peakfiles. Mipmap peaks for new captures.

This commit is contained in:
Jonathan Moore Liles 2008-05-10 20:40:43 -05:00
parent fc99144548
commit d1a2f52352
5 changed files with 67 additions and 30 deletions

View File

@ -93,6 +93,8 @@ public:
virtual nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t end ) = 0; virtual nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t end ) = 0;
virtual nframes_t write ( sample_t *buf, nframes_t len ) = 0; virtual nframes_t write ( sample_t *buf, nframes_t len ) = 0;
virtual void finalize ( void ) { _peaks.finish_writing(); }
bool read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels ); bool read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels );
}; };

View File

@ -158,8 +158,6 @@ Audio_File_SF::close ( void )
if ( _in ) if ( _in )
sf_close( _in ); sf_close( _in );
_peaks.finish_writing();
_in = NULL; _in = NULL;
} }

View File

@ -842,6 +842,8 @@ Audio_Region::finalize ( nframes_t frame )
_clip->close(); _clip->close();
_clip->open(); _clip->open();
_clip->finalize();
/* FIXME: should we attempt to truncate the file? */ /* FIXME: should we attempt to truncate the file? */
_range.length = frame - _range.start - _range.offset; _range.length = frame - _range.start - _range.offset;

View File

@ -581,47 +581,29 @@ class Peak_Builder
public: public:
/** generate additional cache levels for a peakfile with only 1 block (ie. that of a new capture) */
bool bool
run ( void ) make_peaks_mipmap ( void )
{ {
if ( ! Peaks::mipmapped_peakfiles )
return true;
Audio_File *_clip = _peaks->_clip; Audio_File *_clip = _peaks->_clip;
const char *filename = _clip->name(); const char *filename = _clip->name();
DMESSAGE( "building peaks for \"%s\"", filename );
FILE *rfp; FILE *rfp;
if ( ! ( fp = fopen( peakname( filename ), "w+" ) ) ) last_block_pos = sizeof( peakfile_block_header );
return false;
_clip->seek( 0 ); /* open for reading */
Peak buf[ _clip->channels() ];
DMESSAGE( "building level 1 peak cache" );
write_block_header( Peaks::cache_minimum );
/* build first level from source */
size_t len;
do {
len = _peaks->read_source_peaks( buf, 1, Peaks::cache_minimum );
fwrite( buf, sizeof( buf ), len, fp );
}
while ( len );
/* reopen for reading */
fclose( fp );
rfp = fopen( peakname( filename ), "r" ); rfp = fopen( peakname( filename ), "r" );
// rfp = freopen( peakname( filename ), "r", fp );
/* open the file again for appending */ /* open the file again for appending */
fp = fopen( peakname( filename ), "r+" ); fp = fopen( peakname( filename ), "r+" );
fseek( fp, 0, SEEK_END ); fseek( fp, 0, SEEK_END );
Peak buf[ _clip->channels() ];
/* now build the remaining peak levels, each based on the /* now build the remaining peak levels, each based on the
* preceding level */ * preceding level */
@ -655,6 +637,45 @@ public:
fclose( rfp ); fclose( rfp );
fclose( fp ); fclose( fp );
return true;
}
bool
make_peaks ( void )
{
Audio_File *_clip = _peaks->_clip;
const char *filename = _clip->name();
DMESSAGE( "building peaks for \"%s\"", filename );
FILE *rfp;
if ( ! ( fp = fopen( peakname( filename ), "w+" ) ) )
return false;
_clip->seek( 0 );
Peak buf[ _clip->channels() ];
DMESSAGE( "building level 1 peak cache" );
write_block_header( Peaks::cache_minimum );
/* build first level from source */
size_t len;
do {
len = _peaks->read_source_peaks( buf, 1, Peaks::cache_minimum );
fwrite( buf, sizeof( buf ), len, fp );
}
while ( len );
/* reopen for reading */
fclose( fp );
make_peaks_mipmap();
DMESSAGE( "done building peaks" ); DMESSAGE( "done building peaks" );
return true; return true;
@ -674,7 +695,15 @@ Peaks::make_peaks ( void ) const
{ {
Peak_Builder pb( this ); Peak_Builder pb( this );
return pb.run(); return pb.make_peaks();
}
bool
Peaks::make_peaks_mipmap ( void ) const
{
Peak_Builder pb( this );
return pb.make_peaks_mipmap();
} }
/** return normalization factor for a single peak, assuming the peak /** return normalization factor for a single peak, assuming the peak
@ -710,6 +739,11 @@ Peaks::finish_writing ( void )
delete _peak_writer; delete _peak_writer;
_peak_writer = NULL; _peak_writer = NULL;
} }
/* now fill in the rest of the cache */
if ( ! fork() )
exit( make_peaks_mipmap() );
} }
void void

View File

@ -101,6 +101,7 @@ public:
bool current ( void ) const; bool current ( void ) const;
bool make_peaks ( void ) const; bool make_peaks ( void ) const;
bool make_peaks_mipmap ( void ) const;
void prepare_for_writing ( void ); void prepare_for_writing ( void );
void finish_writing ( void ); void finish_writing ( void );