Work on making peak streaming work again.

This commit is contained in:
Jonathan Moore Liles 2008-05-10 20:10:16 -05:00
parent e27c0336fe
commit fc99144548
5 changed files with 53 additions and 19 deletions

View File

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

View File

@ -792,6 +792,13 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe
}
/** prepare for capturing */
void
Audio_Region::prepare ( void )
{
log_start();
}
/* THREAD: IO */
/** write /nframes/ from /buf/ to source. /buf/ is interleaved and
must match the channel layout of the write source! */
@ -825,15 +832,6 @@ Audio_Region::write ( nframes_t nframes )
return nframes;
}
/** prepare for capturing */
void
Audio_Region::prepare ( void )
{
log_start();
}
/** finalize region capture. Assumes that this *is* a captured region
and that no other regions refer to the same source */
bool

View File

@ -20,7 +20,7 @@
/*
peakfile reading/writing.
*/
*/
#include "Peaks.H"
@ -48,6 +48,8 @@
#include <errno.h>
#include "Transport.H" // for .recording
#include <list>
Peaks::peakbuffer Peaks::_peakbuf;
@ -376,12 +378,16 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chu
nframes_t ncc = nearest_cached_chunksize( chunksize );
if ( ! _peak_writer && ! current( cache_minimum ) )
/* Build peaks asyncronously */
if ( ! fork() )
exit( make_peaks( ) );
else
return 0;
/* never try to build peaks while recording */
if ( ! ( _peak_writer || transport->recording ) )
{
if ( ! current() )
/* Build peaks asyncronously */
if ( ! fork() )
exit( make_peaks() );
else
return 0;
}
Peakfile _peakfile;
@ -493,7 +499,7 @@ Peaks::open ( void )
/** returns false if peak file for /filename/ is out of date */
bool
Peaks::current ( nframes_t chunksize ) const
Peaks::current ( void ) const
{
int sfd, pfd;
@ -515,6 +521,16 @@ Peaks::current ( nframes_t chunksize ) const
}
static void
touch ( int fd )
{
struct stat st;
fstat( fd, &st );
fchmod( fd, st.st_mode );
}
/* The Peak_Builder is for generating peaks from imported or updated sources, or when the
peakfile is simply missing */
@ -686,6 +702,16 @@ Peaks::prepare_for_writing ( void )
_peak_writer = new Peak_Writer( _clip->name(), cache_minimum, _clip->channels() );
}
void
Peaks::finish_writing ( void )
{
if ( _peak_writer )
{
delete _peak_writer;
_peak_writer = NULL;
}
}
void
Peaks::write ( sample_t *buf, nframes_t nframes )
{
@ -720,7 +746,10 @@ Peak_Writer::Peak_Writer ( const char *filename, nframes_t chunksize, int channe
Peak_Writer::~Peak_Writer ( )
{
touch( fileno( _fp ) );
fclose( _fp );
delete[] _peak;
}
@ -746,6 +775,5 @@ Peak_Writer::write ( sample_t *buf, nframes_t nframes )
memset( _peak, 0, sizeof( Peak ) * _channels );
_index = 0;
}
}
}

View File

@ -99,10 +99,11 @@ public:
void read ( int X, float *hi, float *lo ) const;
bool open ( void );
bool current ( nframes_t chunksize ) const;
bool current ( void ) const;
bool make_peaks ( void ) const;
void prepare_for_writing ( void );
void finish_writing ( void );
void write ( sample_t *buf, nframes_t nframes );
};

View File

@ -1066,6 +1066,9 @@ Timeline::remove_track ( Track *track )
bool
Timeline::record ( void )
{
/* FIXME: right place for this? */
transport->recording = true;
Loggable::block_start();
for ( int i = tracks->children(); i-- ; )
@ -1096,6 +1099,8 @@ Timeline::stop ( void )
Loggable::block_end();
activate();
transport->recording = false;
}