Make make_peaks use Clip to access source.
This commit is contained in:
parent
f27a222e47
commit
bb0b511122
35
Peaks.C
35
Peaks.C
|
@ -247,50 +247,29 @@ Peaks::make_peaks ( const char *filename, int chunksize )
|
||||||
if ( current( filename ) )
|
if ( current( filename ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
SNDFILE *in;
|
if ( ! _clip->open() )
|
||||||
SF_INFO si;
|
return false;
|
||||||
|
|
||||||
memset( &si, 0, sizeof( si ) );
|
|
||||||
|
|
||||||
in = sf_open( filename, SFM_READ, &si );
|
|
||||||
|
|
||||||
FILE *fp = fopen( peakname( filename ), "w" );
|
FILE *fp = fopen( peakname( filename ), "w" );
|
||||||
|
|
||||||
if ( fp == NULL )
|
if ( fp == NULL )
|
||||||
{
|
{
|
||||||
sf_close( in );
|
_clip->close();
|
||||||
/* return fals */
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write chunksize first */
|
/* write chunksize first */
|
||||||
fwrite( &chunksize, sizeof( int ), 1, fp );
|
fwrite( &chunksize, sizeof( int ), 1, fp );
|
||||||
|
|
||||||
float *fbuf = new float[ chunksize ];
|
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
do {
|
do {
|
||||||
/* read in a buffer */
|
|
||||||
len = sf_read_float( in, fbuf, chunksize );
|
|
||||||
|
|
||||||
Peak p;
|
Peak p;
|
||||||
p.max = -1.0;
|
len = clip_read_peaks( &p, 1, chunksize );
|
||||||
p.min = 1.0;
|
|
||||||
|
|
||||||
for ( int i = 0; i < len; ++i )
|
|
||||||
{
|
|
||||||
if ( fbuf[i] > p.max )
|
|
||||||
p.max = fbuf[i];
|
|
||||||
if ( fbuf[i] < p.min )
|
|
||||||
p.min = fbuf[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
fwrite( &p, sizeof( Peak ), 1, fp );
|
fwrite( &p, sizeof( Peak ), 1, fp );
|
||||||
}
|
}
|
||||||
while ( len == chunksize );
|
while ( len );
|
||||||
|
|
||||||
|
_clip->close();
|
||||||
|
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
sf_close( in );
|
|
||||||
|
|
||||||
delete fbuf;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue