Support optional mipmapping of peakfiles. Mipmap peaks for new captures.
This commit is contained in:
parent
fc99144548
commit
d1a2f52352
|
@ -93,6 +93,8 @@ public:
|
|||
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 void finalize ( void ) { _peaks.finish_writing(); }
|
||||
|
||||
bool read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels );
|
||||
|
||||
};
|
||||
|
|
|
@ -158,8 +158,6 @@ Audio_File_SF::close ( void )
|
|||
if ( _in )
|
||||
sf_close( _in );
|
||||
|
||||
_peaks.finish_writing();
|
||||
|
||||
_in = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -842,6 +842,8 @@ Audio_Region::finalize ( nframes_t frame )
|
|||
_clip->close();
|
||||
_clip->open();
|
||||
|
||||
_clip->finalize();
|
||||
|
||||
/* FIXME: should we attempt to truncate the file? */
|
||||
|
||||
_range.length = frame - _range.start - _range.offset;
|
||||
|
|
|
@ -581,47 +581,29 @@ class Peak_Builder
|
|||
|
||||
public:
|
||||
|
||||
/** generate additional cache levels for a peakfile with only 1 block (ie. that of a new capture) */
|
||||
bool
|
||||
run ( void )
|
||||
make_peaks_mipmap ( void )
|
||||
{
|
||||
if ( ! Peaks::mipmapped_peakfiles )
|
||||
return true;
|
||||
|
||||
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;
|
||||
last_block_pos = sizeof( peakfile_block_header );
|
||||
|
||||
_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 );
|
||||
/* open for reading */
|
||||
rfp = fopen( peakname( filename ), "r" );
|
||||
|
||||
// rfp = freopen( peakname( filename ), "r", fp );
|
||||
|
||||
/* open the file again for appending */
|
||||
fp = fopen( peakname( filename ), "r+" );
|
||||
fseek( fp, 0, SEEK_END );
|
||||
|
||||
Peak buf[ _clip->channels() ];
|
||||
|
||||
/* now build the remaining peak levels, each based on the
|
||||
* preceding level */
|
||||
|
||||
|
@ -655,6 +637,45 @@ public:
|
|||
fclose( rfp );
|
||||
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" );
|
||||
|
||||
return true;
|
||||
|
@ -674,7 +695,15 @@ Peaks::make_peaks ( void ) const
|
|||
{
|
||||
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
|
||||
|
@ -710,6 +739,11 @@ Peaks::finish_writing ( void )
|
|||
delete _peak_writer;
|
||||
_peak_writer = NULL;
|
||||
}
|
||||
|
||||
/* now fill in the rest of the cache */
|
||||
|
||||
if ( ! fork() )
|
||||
exit( make_peaks_mipmap() );
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -101,6 +101,7 @@ public:
|
|||
|
||||
bool current ( void ) const;
|
||||
bool make_peaks ( void ) const;
|
||||
bool make_peaks_mipmap ( void ) const;
|
||||
|
||||
void prepare_for_writing ( void );
|
||||
void finish_writing ( void );
|
||||
|
|
Loading…
Reference in New Issue