Continue switching over to peak server system.
This commit is contained in:
parent
95a2896d53
commit
48bcd7ed98
|
@ -48,25 +48,10 @@ Peaks::fill_buffer ( float fpp, int s, int e ) const
|
||||||
{
|
{
|
||||||
_fpp = fpp;
|
_fpp = fpp;
|
||||||
|
|
||||||
printf( "fill_buffer\n" );
|
read_peaks( s, e, (e - s) / fpp, fpp );
|
||||||
|
|
||||||
/* FIXME: repair this */
|
|
||||||
// if ( fpp < _peaks->chunksize )
|
|
||||||
{
|
|
||||||
/* looks like we're going to have to switch to a higher resolution peak file
|
|
||||||
or read directly from the source */
|
|
||||||
read_peaks( s, e, (e - s) / fpp, fpp );
|
|
||||||
|
|
||||||
/* FIXME: are we *SURE* we got them all? */
|
|
||||||
return (e - s) / fpp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* else */
|
|
||||||
/* { */
|
|
||||||
/* /\* we'll just downsample on the fly in this case--no need for extra copying into */
|
|
||||||
/* the buffer *\/ */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
|
/* FIXME: are we *SURE* we got them all? */
|
||||||
|
return (e - s) / fpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,53 +79,69 @@ Peaks::downsample ( Peak *peaks, int s, int e, float *mhi, float *mlo ) const
|
||||||
int
|
int
|
||||||
Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const
|
Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const
|
||||||
{
|
{
|
||||||
int fd;
|
FILE *fp;
|
||||||
|
|
||||||
if ( ( fd = ::open( peakname( _clip->name() ), O_RDONLY ) ) < 0 )
|
if ( ! ( fp = fopen( peakname( _clip->name() ), "r" ) ) )
|
||||||
{
|
{
|
||||||
printf( "failed to open peak file!" );
|
printf( "failed to open peak file!" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Peak *pbuf = new Peak[ chunksize ];
|
|
||||||
|
|
||||||
/* get chunk size of peak file */
|
/* get chunk size of peak file */
|
||||||
int pfchunksize;
|
int pfchunksize;
|
||||||
::read( fd, &pfchunksize, sizeof( int ) );
|
fread( &pfchunksize, sizeof( int ), 1, fp );
|
||||||
|
|
||||||
|
int channels = _clip->channels();
|
||||||
|
const int ratio = chunksize / pfchunksize;
|
||||||
|
|
||||||
|
if ( ratio == 1 )
|
||||||
|
{
|
||||||
|
int len = fread( peaks, sizeof( Peak ) * channels, npeaks, fp );
|
||||||
|
fclose( fp );
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
Peak *pbuf = new Peak[ ratio * channels ];
|
||||||
|
|
||||||
/* locate to start position */
|
/* locate to start position */
|
||||||
lseek( fd, SEEK_CUR, s / pfchunksize );
|
fseek( fp, (s * channels / pfchunksize) * sizeof( Peak ), SEEK_CUR );
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for ( i = 0; i < npeaks; ++i )
|
for ( i = 0; i < npeaks; ++i )
|
||||||
{
|
{
|
||||||
/* read in a buffer */
|
/* read in a buffer */
|
||||||
len = ::read( fd, pbuf, chunksize );
|
len = fread( pbuf, sizeof( Peak ) * channels, ratio, fp );
|
||||||
|
|
||||||
Peak &p = peaks[ i ];
|
Peak *pk = peaks + (i * channels);
|
||||||
|
|
||||||
// downsample( pbuf,
|
/* get the peak for each channel */
|
||||||
|
for ( int j = 0; j < channels; ++j )
|
||||||
|
{
|
||||||
|
Peak &p = pk[ j ];
|
||||||
|
|
||||||
p.min = 0;
|
p.min = 0;
|
||||||
p.max = 0;
|
p.max = 0;
|
||||||
|
|
||||||
/* for ( int j = len; j--; ) */
|
for ( int k = j; k < len * channels; k += channels )
|
||||||
/* { */
|
{
|
||||||
/* if ( fbuf[ j ] > p.max ) */
|
if ( pbuf[ k ].max > p.max )
|
||||||
/* p.max = fbuf[ j ]; */
|
p.max = pbuf[ k ].max;
|
||||||
/* if ( fbuf[ j ] < p.min ) */
|
if ( pbuf[ k ].min < p.min )
|
||||||
/* p.min = fbuf[ j ]; */
|
p.min = pbuf[ k ].min;
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
if ( len < chunksize )
|
}
|
||||||
|
|
||||||
|
if ( len < ratio )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delete fbuf; */
|
delete pbuf;
|
||||||
|
|
||||||
_clip->close();
|
fclose( fp );
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +209,13 @@ Peaks::read_peaks ( int s, int e, int npeaks, int chunksize ) const
|
||||||
|
|
||||||
_peakbuf.offset = s;
|
_peakbuf.offset = s;
|
||||||
_peakbuf.buf->chunksize = chunksize;
|
_peakbuf.buf->chunksize = chunksize;
|
||||||
_peakbuf.len = read_source_peaks( _peakbuf.buf->data, s, npeaks, chunksize );
|
|
||||||
|
/* FIXME: compart to (minimum) peakfile chunk size */
|
||||||
|
if ( chunksize < 256 )
|
||||||
|
_peakbuf.len = read_source_peaks( _peakbuf.buf->data, s, npeaks, chunksize );
|
||||||
|
else
|
||||||
|
_peakbuf.len = read_peakfile_peaks( _peakbuf.buf->data, s, npeaks, chunksize );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the peak for the range of samples */
|
/** Return the peak for the range of samples */
|
||||||
|
@ -336,7 +343,7 @@ Peaks::make_peaks ( int chunksize )
|
||||||
nframes_t s = 0;
|
nframes_t s = 0;
|
||||||
do {
|
do {
|
||||||
len = read_source_peaks( peaks, s, 1, chunksize );
|
len = read_source_peaks( peaks, s, 1, chunksize );
|
||||||
s += len;
|
s += len * chunksize;
|
||||||
fwrite( peaks, sizeof( peaks ), 1, fp );
|
fwrite( peaks, sizeof( peaks ), 1, fp );
|
||||||
}
|
}
|
||||||
while ( len );
|
while ( len );
|
||||||
|
|
|
@ -459,9 +459,10 @@ Region::draw ( int X, int Y, int W, int H )
|
||||||
int peaks;
|
int peaks;
|
||||||
Peak *pbuf;
|
Peak *pbuf;
|
||||||
|
|
||||||
|
const nframes_t start = _start + offset + timeline->x_to_ts( X - rx );
|
||||||
_clip->read_peaks( timeline->fpp(),
|
_clip->read_peaks( timeline->fpp(),
|
||||||
// _start + offset, min( (_end - _start) - offset, _end),
|
start,
|
||||||
_start + offset, _start + offset + timeline->x_to_ts( W ),
|
start + timeline->x_to_ts( W ),
|
||||||
&peaks, &pbuf, &channels );
|
&peaks, &pbuf, &channels );
|
||||||
|
|
||||||
assert( pbuf );
|
assert( pbuf );
|
||||||
|
@ -479,7 +480,7 @@ Region::draw ( int X, int Y, int W, int H )
|
||||||
pb[ j ].max *= _scale;
|
pb[ j ].max *= _scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waveform::draw( rx, X, (y() + Fl::box_dy( box() )) + (i * ch), W, ch,
|
Waveform::draw( X, (y() + Fl::box_dy( box() )) + (i * ch), W, ch,
|
||||||
pb, peaks,
|
pb, peaks,
|
||||||
selected() ? fl_invert_color( _color ) : _color );
|
selected() ? fl_invert_color( _color ) : _color );
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ bool Waveform::logarithmic = true;
|
||||||
|
|
||||||
/** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
|
/** draw a portion of /clip/'s waveform. coordinates are the portion to draw */
|
||||||
void
|
void
|
||||||
Waveform::draw ( int ox, int X, int Y, int W, int H,
|
Waveform::draw ( int X, int Y, int W, int H,
|
||||||
Peak *pbuf, int peaks,
|
Peak *pbuf, int peaks,
|
||||||
Fl_Color color )
|
Fl_Color color )
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
static bool vary_color;
|
static bool vary_color;
|
||||||
static bool logarithmic;
|
static bool logarithmic;
|
||||||
|
|
||||||
static void draw ( int ox, int X, int Y, int W, int H,
|
static void draw ( int X, int Y, int W, int H,
|
||||||
Peak *pbuf, int peaks,
|
Peak *pbuf, int peaks,
|
||||||
Fl_Color color );
|
Fl_Color color );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue