Make peak streaming work again.

pull/3/head
Jonathan Moore Liles 2008-05-10 13:19:55 -05:00
parent 45a660d98a
commit e2e2241715
4 changed files with 60 additions and 29 deletions

View File

@ -54,8 +54,6 @@ protected:
Peaks _peaks; Peaks _peaks;
// Peak_Writer *_peak_writer;
static const format_desc * static const format_desc *
find_format ( const format_desc *fd, const char *name ) find_format ( const format_desc *fd, const char *name )
{ {

View File

@ -126,8 +126,7 @@ Audio_File_SF::create ( const char *filename, nframes_t samplerate, int channels
c->_in = out; c->_in = out;
/* FIXME: 256 ? */ c->_peaks.prepare_for_writing();
// c->_peak_writer = new Peak_Writer( name, 256, channels );
return c; return c;
} }
@ -159,9 +158,6 @@ Audio_File_SF::close ( void )
if ( _in ) if ( _in )
sf_close( _in ); sf_close( _in );
/* if ( _peak_writer ) */
/* delete _peak_writer; */
_in = NULL; _in = NULL;
} }
@ -228,7 +224,7 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end
nframes_t nframes_t
Audio_File_SF::write ( sample_t *buf, nframes_t nframes ) Audio_File_SF::write ( sample_t *buf, nframes_t nframes )
{ {
// _peak_writer->write( buf, nframes ); _peaks.write( buf, nframes );
nframes_t l = sf_writef_float( _in, buf, nframes ); nframes_t l = sf_writef_float( _in, buf, nframes );

View File

@ -78,6 +78,9 @@
Peaks::peakbuffer Peaks::_peakbuf; Peaks::peakbuffer Peaks::_peakbuf;
bool Peaks::mipmapped_peakfiles = true;
/* chunksizes at which to generate peakfiles (on demand). This should /* chunksizes at which to generate peakfiles (on demand). This should
pretty much cover the usable range. Better performance can be pretty much cover the usable range. Better performance can be
achieved at high zoom-levels and for compressed sources with a achieved at high zoom-levels and for compressed sources with a
@ -88,6 +91,24 @@ const int Peaks::cache_levels = 8; /* number of sam
const int Peaks::cache_step = 1; /* powers of two between each level. 4 == 256, 2048, 16384, ... */ const int Peaks::cache_step = 1; /* powers of two between each level. 4 == 256, 2048, 16384, ... */
/* Peaks ( ) */
/* { */
/* _clip = NULL; */
/* } */
Peaks::Peaks ( Audio_File *c )
{
_clip = c;
_peak_writer = NULL;
}
Peaks::~Peaks ( )
{
if ( _peak_writer )
delete _peak_writer;
}
static static
const char * const char *
peakname ( const char *filename, nframes_t chunksize ) peakname ( const char *filename, nframes_t chunksize )
@ -297,7 +318,7 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chu
nframes_t ncc = nearest_cached_chunksize( chunksize ); nframes_t ncc = nearest_cached_chunksize( chunksize );
if ( ! current( cache_minimum ) ) if ( ! _peak_writer && ! current( cache_minimum ) )
/* Build peaks asyncronously */ /* Build peaks asyncronously */
if ( ! fork() ) if ( ! fork() )
exit( make_peaks( ) ); exit( make_peaks( ) );
@ -532,6 +553,26 @@ Peak::normalization_factor( void ) const
return s; return s;
} }
/* wrapper for peak writer */
void
Peaks::prepare_for_writing ( void )
{
assert( ! _peak_writer );
_peak_writer = new Peak_Writer( _clip->name(), cache_minimum, _clip->channels() );
}
void
Peaks::write ( sample_t *buf, nframes_t nframes )
{
_peak_writer->write( buf, nframes );
}
/* The Peak_Writer is for streaming peaks from audio buffers to disk
* while capturing. It works by accumulating a peak value across
* write() calls. */
Peak_Writer::Peak_Writer ( const char *filename, nframes_t chunksize, int channels ) Peak_Writer::Peak_Writer ( const char *filename, nframes_t chunksize, int channels )
{ {
@ -549,7 +590,7 @@ Peak_Writer::Peak_Writer ( const char *filename, nframes_t chunksize, int channe
Peak_Writer::~Peak_Writer ( ) Peak_Writer::~Peak_Writer ( )
{ {
fclose( _fp ); fclose( _fp );
delete _peak; delete[] _peak;
} }
/** append peaks for samples in /buf/ to peakfile */ /** append peaks for samples in /buf/ to peakfile */

View File

@ -28,7 +28,6 @@ struct Peak {
float max; float max;
float normalization_factor ( void ) const; float normalization_factor ( void ) const;
}; };
class Audio_File; class Audio_File;
@ -39,7 +38,7 @@ class Peaks
struct peakdata { struct peakdata {
nframes_t chunksize; /* should always be a power of 2 */ nframes_t chunksize; /* should always be a power of 2 */
Peak data[]; Peak data[];
}; };
@ -47,8 +46,8 @@ class Peaks
struct peakbuffer { struct peakbuffer {
size_t size; /* total allocation size */ size_t size; /* total allocation size */
size_t len; /* number of peaks */ size_t len; /* number of peaks */
nframes_t offset; /* starting sample */ nframes_t offset; /* starting sample */
peakdata *buf; peakdata *buf;
@ -69,42 +68,39 @@ class Peaks
int read_source_peaks ( Peak *peaks, int npeaks, nframes_t chunksize ) const; int read_source_peaks ( Peak *peaks, int npeaks, nframes_t chunksize ) const;
int read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chunksize ) const; int read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chunksize ) const;
Peak_Writer *_peak_writer; Peak_Writer *_peak_writer; /* exists when streaming peaks to disk */
/* not permitted */
Peaks ( const Peaks &rhs );
const Peaks &operator= ( const Peaks &rhs );
public: public:
static bool mipmapped_peakfiles;
static const int cache_minimum; static const int cache_minimum;
static const int cache_levels; static const int cache_levels;
static const int cache_step; static const int cache_step;
Peaks ( )
{
_clip = NULL;
}
Peaks ( Audio_File *c )
{ Peaks ( Audio_File *c );
_clip = c; ~Peaks ( );
}
Peak *peakbuf ( void ) const { return Peaks::_peakbuf.buf->data; } Peak *peakbuf ( void ) const { return Peaks::_peakbuf.buf->data; }
void clip ( Audio_File *c ) { _clip = c; } void clip ( Audio_File *c ) { _clip = c; }
int fill_buffer ( float fpp, nframes_t s, nframes_t e ) const; int fill_buffer ( float fpp, nframes_t s, nframes_t e ) const;
void downsample ( Peak *peaks, 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 ( void ); bool open ( void );
// float normalization_factor( float fpp, nframes_t start, nframes_t end ) ;
bool current ( nframes_t chunksize ) const; bool current ( nframes_t chunksize ) const;
bool make_peaks ( void ) const; bool make_peaks ( void ) const;
Peak & peak ( nframes_t start, nframes_t end ) const; void prepare_for_writing ( void );
void write ( sample_t *buf, nframes_t nframes );
Peak & operator[] ( int X ) const;
}; };
#include <stdio.h> #include <stdio.h>