From 22030e41b6d33d3e604203e2a41f8cbda41500b4 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 26 Mar 2008 19:46:38 -0500 Subject: [PATCH] Improve peak reading efficiency. --- Engine/Peak_Server.C | 15 ++++++++------- Engine/Peaks.C | 20 +++++++++++++------- Engine/Peaks.H | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Engine/Peak_Server.C b/Engine/Peak_Server.C index 32b5e8c..22d0493 100644 --- a/Engine/Peak_Server.C +++ b/Engine/Peak_Server.C @@ -127,19 +127,20 @@ Peak_Server::handle_request ( int s, const char *buf, int l ) int npeaks = pk->fill_buffer( fpp, start, end ); - /* deinterlace and transmit */ int channels = af->channels(); - /* FIXME: really inefficient */ + Peak *pbuf = new Peak[ npeaks * channels ]; + + /* deinterlace */ + int k = 0; for ( int i = 0; i < channels; i++ ) for ( int j = i; j < npeaks * channels; j += channels ) - send( s, pk->peakbuf() + j, sizeof( Peak ), 0 ); + pbuf[ k++ ] = pk->peakbuf()[ j ]; + /* transmit */ + send( s, pbuf, sizeof( Peak ) * npeaks * channels, 0 ); -/* for ( int i = 0; i < af->channels(); ++i ) */ -/* { */ -/* send( s, pk->peakbuf(), npeaks * sizeof( Peak ), 0 ); */ -/* } */ + delete pbuf; break; } diff --git a/Engine/Peaks.C b/Engine/Peaks.C index acd5b21..f6bdb55 100644 --- a/Engine/Peaks.C +++ b/Engine/Peaks.C @@ -147,7 +147,7 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize } int -Peaks::read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const +Peaks::read_source_peaks ( Peak *peaks, int npeaks, int chunksize ) const { int channels = _clip->channels(); @@ -155,9 +155,6 @@ Peaks::read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) size_t len; - _clip->open(); - _clip->seek( s ); - int i; for ( i = 0; i < npeaks; ++i ) { @@ -190,6 +187,17 @@ Peaks::read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) delete fbuf; + return i; +} + +int +Peaks::read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const +{ + _clip->open(); + _clip->seek( s ); + + int i = read_source_peaks( peaks, npeaks, chunksize ); + _clip->close(); return i; @@ -340,10 +348,8 @@ Peaks::make_peaks ( int chunksize ) Peak peaks[ _clip->channels() ]; size_t len; - nframes_t s = 0; do { - len = read_source_peaks( peaks, s, 1, chunksize ); - s += len * chunksize; + len = read_source_peaks( peaks, 1, chunksize ); fwrite( peaks, sizeof( peaks ), 1, fp ); } while ( len ); diff --git a/Engine/Peaks.H b/Engine/Peaks.H index c4a8137..a2747aa 100644 --- a/Engine/Peaks.H +++ b/Engine/Peaks.H @@ -64,6 +64,7 @@ class Peaks void read_peaks ( int s, int e, int npeaks, int chunksize ) const; int read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const; + int read_source_peaks ( Peak *peaks, int npeaks, int chunksize ) const; int read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const; const char *peakname ( const char *filename ) const;