Fiddle with playback...

This commit is contained in:
Jonathan Moore Liles 2008-04-08 21:20:44 -05:00
parent 7f43a99030
commit ebb86a1e62
6 changed files with 40 additions and 22 deletions

View File

@ -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 );

View File

@ -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++ ];
}
}
}

View File

@ -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();

View File

@ -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 );
}

View File

@ -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 );
};

View File

@ -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;
}