Timeline: Always wait for diskstreams when freewheeling.
This commit is contained in:
parent
55f54085c5
commit
4bf4a1ef14
|
@ -108,8 +108,6 @@ Playback_DS::read_block ( sample_t *buf, nframes_t nframes )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AVOID_UNNECESSARY_COPYING 1
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Playback_DS::disk_thread ( void )
|
Playback_DS::disk_thread ( void )
|
||||||
{
|
{
|
||||||
|
@ -119,9 +117,7 @@ Playback_DS::disk_thread ( void )
|
||||||
|
|
||||||
/* buffer to hold the interleaved data returned by the track reader */
|
/* buffer to hold the interleaved data returned by the track reader */
|
||||||
sample_t *buf = buffer_alloc( _nframes * channels() * _disk_io_blocks );
|
sample_t *buf = buffer_alloc( _nframes * channels() * _disk_io_blocks );
|
||||||
#ifndef AVOID_UNNECESSARY_COPYING
|
sample_t *cbuf = buffer_alloc( _nframes * _disk_io_blocks );
|
||||||
sample_t *cbuf = buffer_alloc( _nframes * channels() * _disk_io_blocks );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int blocks_ready = 0;
|
int blocks_ready = 0;
|
||||||
|
|
||||||
|
@ -165,51 +161,16 @@ Playback_DS::disk_thread ( void )
|
||||||
|
|
||||||
for ( int i = channels(); i--; )
|
for ( int i = channels(); i--; )
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef AVOID_UNNECESSARY_COPYING
|
|
||||||
|
|
||||||
/* deinterleave direcectly into the ringbuffer to avoid
|
|
||||||
* unnecessary copying */
|
|
||||||
|
|
||||||
jack_ringbuffer_data_t rbd[2];
|
|
||||||
|
|
||||||
memset( rbd, 0, sizeof( rbd ) );
|
|
||||||
|
|
||||||
jack_ringbuffer_get_write_vector( _rb[ i ], rbd );
|
|
||||||
|
|
||||||
if ( rbd[ 0 ].len >= block_size )
|
|
||||||
{
|
|
||||||
/* it'll all fit in one go */
|
|
||||||
buffer_deinterleave_one_channel( (sample_t*)rbd[ 0 ].buf, buf, i, channels(), nframes );
|
|
||||||
}
|
|
||||||
else if ( rbd[ 0 ].len + rbd[ 1 ].len >= block_size )
|
|
||||||
{
|
|
||||||
/* there's enough space in the ringbuffer, but it's not contiguous */
|
|
||||||
|
|
||||||
assert( ! ( rbd[ 0 ].len % sizeof( sample_t ) ) );
|
|
||||||
// assert( ! ( rbd[ 1 ].len % sizeof( sample_t ) ) );
|
|
||||||
|
|
||||||
const nframes_t f = rbd[ 0 ].len / sizeof( sample_t );
|
|
||||||
|
|
||||||
/* do the first half */
|
|
||||||
buffer_deinterleave_one_channel( (sample_t*)rbd[ 0 ].buf, buf, i, channels(), f );
|
|
||||||
|
|
||||||
assert( rbd[ 1 ].len >= ( nframes - f ) * sizeof( sample_t ) );
|
|
||||||
|
|
||||||
/* do the second half */
|
|
||||||
buffer_deinterleave_one_channel( (sample_t*)rbd[ 1 ].buf, buf + f, i, channels(), nframes - f );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++_xruns;
|
|
||||||
|
|
||||||
jack_ringbuffer_write_advance( _rb[ i ], block_size );
|
|
||||||
#else
|
|
||||||
buffer_deinterleave_one_channel( cbuf, buf, i, channels(), nframes );
|
buffer_deinterleave_one_channel( cbuf, buf, i, channels(), nframes );
|
||||||
|
|
||||||
if ( jack_ringbuffer_write( _rb[ i ], (char*)cbuf, block_size ) < block_size )
|
size_t wr = 0;
|
||||||
++_xruns;
|
|
||||||
#endif
|
while ( wr < block_size )
|
||||||
}
|
{
|
||||||
|
wr += jack_ringbuffer_write( _rb[ i ], ((char*)cbuf) + wr, block_size - wr );
|
||||||
|
// usleep( 10 * 1000 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,9 +179,7 @@ done:
|
||||||
DMESSAGE( "playback thread terminating" );
|
DMESSAGE( "playback thread terminating" );
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
#ifndef AVOID_UNNECESSARY_COPYING
|
|
||||||
free(cbuf);
|
free(cbuf);
|
||||||
#endif
|
|
||||||
|
|
||||||
_terminate = false;
|
_terminate = false;
|
||||||
|
|
||||||
|
@ -234,21 +193,32 @@ Playback_DS::process ( nframes_t nframes )
|
||||||
{
|
{
|
||||||
THREAD_ASSERT( RT );
|
THREAD_ASSERT( RT );
|
||||||
|
|
||||||
|
|
||||||
const size_t block_size = nframes * sizeof( sample_t );
|
const size_t block_size = nframes * sizeof( sample_t );
|
||||||
|
|
||||||
// printf( "process: %lu %lu %lu\n", _frame, _frame + nframes, nframes );
|
// printf( "process: %lu %lu %lu\n", _frame, _frame + nframes, nframes );
|
||||||
|
|
||||||
for ( int i = channels(); i--; )
|
for ( int i = channels(); i--; )
|
||||||
{
|
{
|
||||||
|
|
||||||
void *buf = track()->output[ i ].buffer( nframes );
|
void *buf = track()->output[ i ].buffer( nframes );
|
||||||
|
|
||||||
if ( jack_ringbuffer_read( _rb[ i ], (char*)buf, block_size ) < block_size )
|
if ( engine->freewheeling() )
|
||||||
{
|
{
|
||||||
++_xruns;
|
size_t rd = 0;
|
||||||
memset( buf, 0, block_size );
|
|
||||||
/* FIXME: we need to resync somehow */
|
while ( rd < block_size )
|
||||||
|
{
|
||||||
|
rd += jack_ringbuffer_read( _rb[ i ], ((char*)buf) + rd, block_size - rd );
|
||||||
|
// usleep( 10 * 1000 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( jack_ringbuffer_read( _rb[ i ], (char*)buf, block_size ) < block_size )
|
||||||
|
{
|
||||||
|
++_xruns;
|
||||||
|
memset( buf, 0, block_size );
|
||||||
|
/* FIXME: we need to resync somehow */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: figure out a way to stop IO while muted without losing sync */
|
/* TODO: figure out a way to stop IO while muted without losing sync */
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "Thread.H"
|
#include "Thread.H"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
const Audio_Region *
|
const Audio_Region *
|
||||||
Record_DS::capture_region ( void ) const
|
Record_DS::capture_region ( void ) const
|
||||||
{
|
{
|
||||||
|
@ -63,8 +65,6 @@ Record_DS::write_block ( sample_t *buf, nframes_t nframes )
|
||||||
_frames_written += nframes;
|
_frames_written += nframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AVOID_UNNECESSARY_COPYING 1
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Record_DS::disk_thread ( void )
|
Record_DS::disk_thread ( void )
|
||||||
{
|
{
|
||||||
|
@ -78,9 +78,7 @@ Record_DS::disk_thread ( void )
|
||||||
|
|
||||||
/* buffer to hold the interleaved data returned by the track reader */
|
/* buffer to hold the interleaved data returned by the track reader */
|
||||||
sample_t *buf = buffer_alloc( nframes * channels() );
|
sample_t *buf = buffer_alloc( nframes * channels() );
|
||||||
#ifndef AVOID_UNNECESSARY_COPYING
|
|
||||||
sample_t *cbuf = buffer_alloc( nframes );
|
sample_t *cbuf = buffer_alloc( nframes );
|
||||||
#endif
|
|
||||||
|
|
||||||
const size_t block_size = nframes * sizeof( sample_t );
|
const size_t block_size = nframes * sizeof( sample_t );
|
||||||
|
|
||||||
|
@ -96,50 +94,15 @@ Record_DS::disk_thread ( void )
|
||||||
/* pull data from the per-channel ringbuffers and interlace it */
|
/* pull data from the per-channel ringbuffers and interlace it */
|
||||||
for ( int i = channels(); i--; )
|
for ( int i = channels(); i--; )
|
||||||
{
|
{
|
||||||
|
size_t rd = 0;
|
||||||
|
|
||||||
#ifdef AVOID_UNNECESSARY_COPYING
|
while ( rd < block_size )
|
||||||
/* interleave direcectly from the ringbuffer to avoid
|
|
||||||
* unnecessary copying */
|
|
||||||
|
|
||||||
jack_ringbuffer_data_t rbd[2];
|
|
||||||
|
|
||||||
memset( rbd, 0, sizeof( rbd ) );
|
|
||||||
|
|
||||||
jack_ringbuffer_get_read_vector( _rb[ i ], rbd );
|
|
||||||
|
|
||||||
if ( rbd[ 0 ].len >= block_size )
|
|
||||||
{
|
{
|
||||||
/* it'll all fit in one go */
|
rd += jack_ringbuffer_read( _rb[ i ], ((char*)cbuf) + rd, block_size - rd );
|
||||||
buffer_interleave_one_channel( buf, (sample_t*)rbd[ 0 ].buf, i, channels(), nframes );
|
// usleep( 10 * 1000 );
|
||||||
}
|
}
|
||||||
else if ( rbd[ 0 ].len + rbd[ 1 ].len >= block_size )
|
|
||||||
{
|
|
||||||
/* there's enough space in the ringbuffer, but it's not contiguous */
|
|
||||||
|
|
||||||
assert( ! ( rbd[ 0 ].len % sizeof( sample_t ) ) );
|
|
||||||
|
|
||||||
const nframes_t f = rbd[ 0 ].len / sizeof( sample_t );
|
|
||||||
|
|
||||||
/* do the first half */
|
|
||||||
buffer_interleave_one_channel( buf, (sample_t*)rbd[ 0 ].buf, i, channels(), f );
|
|
||||||
|
|
||||||
assert( rbd[ 1 ].len >= ( nframes - f ) * sizeof( sample_t ) );
|
|
||||||
|
|
||||||
/* do the second half */
|
|
||||||
buffer_interleave_one_channel( buf + f, (sample_t*)rbd[ 0 ].buf, i, channels(), nframes - f );
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++_xruns;
|
|
||||||
|
|
||||||
jack_ringbuffer_read_advance( _rb[ i ], block_size );
|
|
||||||
#else
|
|
||||||
if ( jack_ringbuffer_read( _rb[ i ], (char*)cbuf, block_size ) < block_size )
|
|
||||||
++_xruns;
|
|
||||||
|
|
||||||
buffer_interleave_one_channel( buf, cbuf, i, channels(), nframes );
|
buffer_interleave_one_channel( buf, cbuf, i, channels(), nframes );
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_block( buf, nframes );
|
write_block( buf, nframes );
|
||||||
|
@ -155,42 +118,32 @@ Record_DS::disk_thread ( void )
|
||||||
const nframes_t nframes = _nframes;
|
const nframes_t nframes = _nframes;
|
||||||
const size_t block_size = _nframes * sizeof( sample_t );
|
const size_t block_size = _nframes * sizeof( sample_t );
|
||||||
|
|
||||||
#ifdef AVOID_UNNECESSARY_COPYING
|
|
||||||
sample_t *cbuf = buffer_alloc( nframes );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while ( blocks_ready-- > 0 || ( ! sem_trywait( &_blocks ) && errno != EAGAIN ) )
|
while ( blocks_ready-- > 0 || ( ! sem_trywait( &_blocks ) && errno != EAGAIN ) )
|
||||||
{
|
{
|
||||||
|
for ( int i = channels(); i--; )
|
||||||
|
{
|
||||||
|
jack_ringbuffer_read( _rb[ i ], (char*)cbuf, block_size );
|
||||||
|
|
||||||
for ( int i = channels(); i--; )
|
buffer_interleave_one_channel( buf, cbuf, i, channels(), nframes );
|
||||||
{
|
}
|
||||||
jack_ringbuffer_read( _rb[ i ], (char*)cbuf, block_size );
|
|
||||||
|
|
||||||
buffer_interleave_one_channel( buf, cbuf, i, channels(), nframes );
|
const nframes_t frames_remaining = (_stop_frame - _frame ) - _frames_written;
|
||||||
}
|
|
||||||
|
|
||||||
const nframes_t frames_remaining = (_stop_frame - _frame ) - _frames_written;
|
if ( frames_remaining < nframes )
|
||||||
|
{
|
||||||
if ( frames_remaining < nframes )
|
/* this is the last block, might be partial */
|
||||||
{
|
write_block( buf, frames_remaining );
|
||||||
/* this is the last block, might be partial */
|
break;
|
||||||
write_block( buf, frames_remaining );
|
}
|
||||||
break;
|
else
|
||||||
}
|
write_block( buf, nframes );
|
||||||
else
|
|
||||||
write_block( buf, nframes );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AVOID_UNNECESSARY_COPYING
|
|
||||||
free(cbuf);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
#ifndef AVOID_UNNECESSARY_COPYING
|
|
||||||
free(cbuf);
|
free(cbuf);
|
||||||
#endif
|
|
||||||
|
|
||||||
DMESSAGE( "finalzing capture" );
|
DMESSAGE( "finalzing capture" );
|
||||||
|
|
||||||
|
@ -300,17 +253,28 @@ Record_DS::process ( nframes_t nframes )
|
||||||
/* read the entire input buffer */
|
/* read the entire input buffer */
|
||||||
void *buf = track()->input[ i ].buffer( nframes );
|
void *buf = track()->input[ i ].buffer( nframes );
|
||||||
|
|
||||||
/* if ( buffer_is_digital_black( (sample_t*)buf, nframes ) ) */
|
|
||||||
/* DWARNING( "recording an entirely blank buffer" ); */
|
|
||||||
|
|
||||||
/* FIXME: this results in a ringbuffer size that is no longer
|
/* FIXME: this results in a ringbuffer size that is no longer
|
||||||
necessarily a multiple of nframes... how will the other side
|
necessarily a multiple of nframes... how will the other side
|
||||||
handle that? */
|
handle that? */
|
||||||
if ( jack_ringbuffer_write( _rb[ i ], (char*)buf + offset, block_size ) < block_size )
|
|
||||||
|
if ( engine->freewheeling() )
|
||||||
{
|
{
|
||||||
++_xruns;
|
size_t wr = 0;
|
||||||
memset( buf, 0, block_size );
|
|
||||||
/* FIXME: we need to resync somehow */
|
while ( wr < block_size )
|
||||||
|
{
|
||||||
|
wr += jack_ringbuffer_write( _rb[ i ], ((char*)buf) + offset_size + wr, block_size - wr );
|
||||||
|
// usleep( 10 * 1000 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( jack_ringbuffer_write( _rb[ i ], ((char*)buf) + offset_size, block_size ) < block_size )
|
||||||
|
{
|
||||||
|
++_xruns;
|
||||||
|
memset( buf, 0, block_size );
|
||||||
|
/* FIXME: we need to resync somehow */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue