Browse Source

Update peaks when necessary.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
0c9be68bcd
3 changed files with 38 additions and 14 deletions
  1. +36
    -13
      Peaks.C
  2. +1
    -0
      Peaks.H
  3. +1
    -1
      Waveform.H

+ 36
- 13
Peaks.C View File

@@ -39,7 +39,7 @@ Peaks::downsample ( int s, int e, float *mhi, float *mlo ) const
*mlo = 1.0; *mlo = 1.0;


if ( e > _len ) if ( e > _len )
e = _len;
e = _len;


for ( int j = s; j < e; j++ ) for ( int j = s; j < e; j++ )
{ {
@@ -105,28 +105,26 @@ Peaks::open ( const char *filename )
{ {
int fd; int fd;


try_again:
make_peaks( filename, 256 );

if ( ( fd = ::open( peakname( filename ), O_RDONLY ) ) < 0 ) if ( ( fd = ::open( peakname( filename ), O_RDONLY ) ) < 0 )
{
/* generate peaks here */
if ( make_peaks( filename, 256 ) )
goto try_again;
else
return false;
}
return false;


{ {
struct stat st; struct stat st;

fstat( fd, &st ); fstat( fd, &st );

_len = st.st_size; _len = st.st_size;
} }



_peaks = (peaks*)mmap( NULL, _len, PROT_READ, MAP_SHARED, fd, 0 ); _peaks = (peaks*)mmap( NULL, _len, PROT_READ, MAP_SHARED, fd, 0 );


::close( fd ); ::close( fd );


if ( _peaks == MAP_FAILED ) if ( _peaks == MAP_FAILED )
printf( "failed to create mapping! " );
printf( "failed to create mapping!\n" );


_len = (_len - sizeof( int )) / sizeof( Peak ); _len = (_len - sizeof( int )) / sizeof( Peak );


@@ -141,15 +139,40 @@ long_to_float( long *buf, int len )
*((float*)buf) = *buf / 32768; *((float*)buf) = *buf / 32768;
} }


/** returns false if peak file for /filename/ is out of date */
bool bool
Peaks::make_peaks ( const char *filename, int chunksize )
Peaks::current ( const char *filename )
{ {
SNDFILE *in;
int sfd, pfd;

if ( ( sfd = ::open( filename, O_RDONLY ) ) < 0 )
return true;

if ( ( pfd = ::open( peakname( filename ), O_RDONLY ) ) < 0 )
return false;


// sox_format_init();
struct stat sst, pst;


fstat( sfd, &sst );
fstat( pfd, &pst );


close( sfd );
close( pfd );

return sst.st_mtime <= pst.st_mtime;
}


/** build peaks file for /filename/ if necessary */
bool
Peaks::make_peaks ( const char *filename, int chunksize )
{
if ( current( filename ) )
return true;

SNDFILE *in;
SF_INFO si; SF_INFO si;

memset( &si, 0, sizeof( si ) ); memset( &si, 0, sizeof( si ) );


in = sf_open( filename, SFM_READ, &si ); in = sf_open( filename, SFM_READ, &si );


+ 1
- 0
Peaks.H View File

@@ -54,6 +54,7 @@ public:
void read ( int X, float *hi, float *lo ) const; void read ( int X, float *hi, float *lo ) const;
bool open ( const char *filename ); bool open ( const char *filename );


bool current ( const char *filename );
bool make_peaks ( const char *filename, int chunksize ); bool make_peaks ( const char *filename, int chunksize );


Peak & operator[] ( int X ) const; Peak & operator[] ( int X ) const;


+ 1
- 1
Waveform.H View File

@@ -46,7 +46,7 @@ public:
Waveform ( Clip *c ) : Fl_Widget( 0, 0, 500, 100, "" ) Waveform ( Clip *c ) : Fl_Widget( 0, 0, 500, 100, "" )
{ {
_clip = c; _clip = c;
_scale = 1;
label( _clip->name() ); label( _clip->name() );


_end = _clip->length(); _end = _clip->length();


Loading…
Cancel
Save