From ebb86a1e622a1ee930c7c12c941c0f67f3e7fffb Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 8 Apr 2008 21:20:44 -0500 Subject: [PATCH] Fiddle with playback... --- Timeline/Audio_File_SF.C | 10 +++++----- Timeline/Audio_Track.C | 13 +++++++++---- Timeline/Disk_Stream.C | 14 +++++++++----- Timeline/Port.C | 4 ++-- Timeline/Port.H | 2 +- Timeline/Region.C | 19 ++++++++++++++----- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Timeline/Audio_File_SF.C b/Timeline/Audio_File_SF.C index 79cfb4a..8062f36 100644 --- a/Timeline/Audio_File_SF.C +++ b/Timeline/Audio_File_SF.C @@ -98,15 +98,15 @@ Audio_File_SF::seek ( nframes_t offset ) nframes_t Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len ) { + if ( len > 256 * 100 ) + printf( "warning: attempt to read an insane number of frames (%lu) from soundfile\n", len ); + +// printf( "len = %lu, channels = %d\n", len, _channels ); + if ( _channels == 1 || channel == -1 ) return sf_readf_float( _in, buf, len ); else { - if ( len > 256 * 100 ) - printf( "warning: attempt to read an insane number of frames (%lu) from soundfile\n", len ); - - printf( "len = %lu, channels = %d\n", len, _channels ); - sample_t *tmp = new sample_t[ len * _channels ]; nframes_t rlen = sf_readf_float( _in, tmp, len ); diff --git a/Timeline/Audio_Track.C b/Timeline/Audio_Track.C index 721a15d..03c9318 100644 --- a/Timeline/Audio_Track.C +++ b/Timeline/Audio_Track.C @@ -135,10 +135,15 @@ Audio_Track::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int chann if ( ! r->read( cbuf, frame, nframes, i ) ) /* error ? */; - /* interleave */ - int k = 0; - for ( unsigned int j = 0; j < nframes; j += channels ) - buf[ j ] = cbuf[ k++ ]; + if ( channels == 1 ) + memcpy( buf, cbuf, nframes * sizeof( sample_t ) ); + else + { + /* interleave */ + int k = 0; + for ( unsigned int j = i; k < nframes; j += channels ) + buf[ j ] = cbuf[ k++ ]; + } } } diff --git a/Timeline/Disk_Stream.C b/Timeline/Disk_Stream.C index 867616b..0c81a24 100644 --- a/Timeline/Disk_Stream.C +++ b/Timeline/Disk_Stream.C @@ -22,7 +22,8 @@ #include "Audio_Track.H" #include "Port.H" -float Disk_Stream::seconds_to_buffer = 5.0f; +// float Disk_Stream::seconds_to_buffer = 5.0f; +float Disk_Stream::seconds_to_buffer = 1.0f; /* A Disk_Stream uses a separate I/O thread to stream a track's regions from disk into a ringbuffer, to be processed by the RT @@ -39,6 +40,8 @@ Disk_Stream::Disk_Stream ( Track_Header *th, float frame_rate, nframes_t nframes _frame = 0; _thread = 0; + printf( "nframes %lu\n", nframes ); + const int blocks = frame_rate * seconds_to_buffer / nframes; _nframes = nframes; @@ -102,7 +105,7 @@ Disk_Stream::read_block ( sample_t *buf ) if ( ! timeline ) return; - printf( "IO: attempting to read block @ %lu\n", _frame ); +// printf( "IO: attempting to read block @ %lu\n", _frame ); if ( ! track() ) { @@ -145,7 +148,7 @@ Disk_Stream::io_thread ( void ) for ( int i = channels(); i--; ) { int k = 0; - for ( unsigned int j = i; j < _nframes; j += channels() ) + for ( unsigned int j = i; k < _nframes; j += channels() ) cbuf[ k++ ] = buf[ j ]; jack_ringbuffer_write( _rb[ i ], (char*)cbuf, block_size ); @@ -166,10 +169,11 @@ Disk_Stream::process ( nframes_t nframes ) for ( int i = channels(); i--; ) { - sample_t *buf = (_th->output)[ i ].buffer( _nframes ); + void *buf = (_th->output)[ i ].buffer( _nframes ); /* FIXME: handle underrun */ - jack_ringbuffer_read( _rb[ i ], (char*)buf, block_size ); + if ( jack_ringbuffer_read( _rb[ i ], (char*)buf, block_size ) < block_size ) + printf( "disktream (rt): buffer underrun!\n" ); } block_processed(); diff --git a/Timeline/Port.C b/Timeline/Port.C index 6328cd8..90c2886 100644 --- a/Timeline/Port.C +++ b/Timeline/Port.C @@ -49,8 +49,8 @@ Port::write ( sample_t *buf, nframes_t nframes ) memcpy( buffer( nframes ), buf, nframes * sizeof( sample_t ) ); } -sample_t * +void * Port::buffer ( nframes_t nframes ) { - return (sample_t*)jack_port_get_buffer( _port, nframes ); + return jack_port_get_buffer( _port, nframes ); } diff --git a/Timeline/Port.H b/Timeline/Port.H index 18ae299..7853494 100644 --- a/Timeline/Port.H +++ b/Timeline/Port.H @@ -40,5 +40,5 @@ public: const char * name ( void ) const { return _name; } void write ( sample_t *buf, nframes_t nframes ); - sample_t *buffer ( nframes_t nframes ); + void *buffer ( nframes_t nframes ); }; diff --git a/Timeline/Region.C b/Timeline/Region.C index d54a08c..820a103 100644 --- a/Timeline/Region.C +++ b/Timeline/Region.C @@ -565,11 +565,13 @@ Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) co nframes_t sofs, ofs, cnt; + cnt = nframes; + if ( pos < r.offset ) { sofs = 0; ofs = r.offset - pos; - cnt = nframes - ofs; + cnt -= ofs; } else { @@ -577,10 +579,11 @@ Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) co sofs = pos - r.offset; } - if ( ofs > nframes ) + if ( ofs >= nframes ) return 0; - const nframes_t start = ofs + r.start + sofs; +// const nframes_t start = ofs + r.start + sofs; + const nframes_t start = r.start + sofs; const nframes_t len = min( cnt, nframes - ofs ); const nframes_t end = start + len; @@ -592,12 +595,18 @@ Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) co /* FIXME: seeking can be very expensive. Esp. with compressed * formats. We should attempt to avoid it. But here or in the * Audio_File class? */ + + // printf( "reading region ofs = %lu, sofs = %lu, %lu-%lu\n", ofs, sofs, start, end ); + cnt = _clip->read( buf + ofs, channel, start, end ); /* apply gain */ - for ( int i = cnt; i--; ) - buf[i] *= _scale; + if ( _scale != 1.0f ) + for ( int i = cnt; i--; ) + buf[i] *= _scale; + +// printf( "read %lu frames\n", cnt ); return cnt; }