Browse Source

Make peak streaming work again.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
e2e2241715
4 changed files with 60 additions and 29 deletions
  1. +0
    -2
      Timeline/Audio_File.H
  2. +2
    -6
      Timeline/Audio_File_SF.C
  3. +43
    -2
      Timeline/Peaks.C
  4. +15
    -19
      Timeline/Peaks.H

+ 0
- 2
Timeline/Audio_File.H View File

@@ -54,8 +54,6 @@ protected:

Peaks _peaks;

// Peak_Writer *_peak_writer;

static const format_desc *
find_format ( const format_desc *fd, const char *name )
{


+ 2
- 6
Timeline/Audio_File_SF.C View File

@@ -126,8 +126,7 @@ Audio_File_SF::create ( const char *filename, nframes_t samplerate, int channels

c->_in = out;

/* FIXME: 256 ? */
// c->_peak_writer = new Peak_Writer( name, 256, channels );
c->_peaks.prepare_for_writing();

return c;
}
@@ -159,9 +158,6 @@ Audio_File_SF::close ( void )
if ( _in )
sf_close( _in );

/* if ( _peak_writer ) */
/* delete _peak_writer; */

_in = NULL;
}

@@ -228,7 +224,7 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end
nframes_t
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 );



+ 43
- 2
Timeline/Peaks.C View File

@@ -78,6 +78,9 @@

Peaks::peakbuffer Peaks::_peakbuf;


bool Peaks::mipmapped_peakfiles = true;

/* chunksizes at which to generate peakfiles (on demand). This should
pretty much cover the usable range. Better performance can be
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, ... */

/* Peaks ( ) */
/* { */
/* _clip = NULL; */
/* } */

Peaks::Peaks ( Audio_File *c )
{
_clip = c;
_peak_writer = NULL;
}

Peaks::~Peaks ( )
{
if ( _peak_writer )
delete _peak_writer;
}


static
const char *
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 );

if ( ! current( cache_minimum ) )
if ( ! _peak_writer && ! current( cache_minimum ) )
/* Build peaks asyncronously */
if ( ! fork() )
exit( make_peaks( ) );
@@ -532,6 +553,26 @@ Peak::normalization_factor( void ) const
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 )
{

@@ -549,7 +590,7 @@ Peak_Writer::Peak_Writer ( const char *filename, nframes_t chunksize, int channe
Peak_Writer::~Peak_Writer ( )
{
fclose( _fp );
delete _peak;
delete[] _peak;
}

/** append peaks for samples in /buf/ to peakfile */


+ 15
- 19
Timeline/Peaks.H View File

@@ -28,7 +28,6 @@ struct Peak {
float max;

float normalization_factor ( void ) const;

};

class Audio_File;
@@ -39,7 +38,7 @@ class Peaks

struct peakdata {

nframes_t chunksize; /* should always be a power of 2 */
nframes_t chunksize; /* should always be a power of 2 */
Peak data[];

};
@@ -47,8 +46,8 @@ class Peaks
struct peakbuffer {

size_t size; /* total allocation size */
size_t len; /* number of peaks */
nframes_t offset; /* starting sample */
size_t len; /* number of peaks */
nframes_t offset; /* starting sample */

peakdata *buf;

@@ -69,42 +68,39 @@ class Peaks
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;

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:

static bool mipmapped_peakfiles;

static const int cache_minimum;
static const int cache_levels;
static const int cache_step;

Peaks ( )
{
_clip = NULL;
}

Peaks ( Audio_File *c )
{
_clip = c;
}

Peaks ( Audio_File *c );
~Peaks ( );

Peak *peakbuf ( void ) const { return Peaks::_peakbuf.buf->data; }
void clip ( Audio_File *c ) { _clip = c; }

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;
bool open ( void );
// float normalization_factor( float fpp, nframes_t start, nframes_t end ) ;

bool current ( nframes_t chunksize ) const;
bool make_peaks ( void ) const;

Peak & peak ( nframes_t start, nframes_t end ) const;

Peak & operator[] ( int X ) const;

void prepare_for_writing ( void );
void write ( sample_t *buf, nframes_t nframes );
};

#include <stdio.h>


Loading…
Cancel
Save