@@ -98,15 +98,15 @@ Audio_File_SF::seek ( nframes_t offset ) | |||||
nframes_t | nframes_t | ||||
Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len ) | 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 ) | if ( _channels == 1 || channel == -1 ) | ||||
return sf_readf_float( _in, buf, len ); | return sf_readf_float( _in, buf, len ); | ||||
else | 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 ]; | sample_t *tmp = new sample_t[ len * _channels ]; | ||||
nframes_t rlen = sf_readf_float( _in, tmp, len ); | nframes_t rlen = sf_readf_float( _in, tmp, len ); | ||||
@@ -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 ) ) | if ( ! r->read( cbuf, frame, nframes, i ) ) | ||||
/* error ? */; | /* 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++ ]; | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -22,7 +22,8 @@ | |||||
#include "Audio_Track.H" | #include "Audio_Track.H" | ||||
#include "Port.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 | /* 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 | 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; | _frame = 0; | ||||
_thread = 0; | _thread = 0; | ||||
printf( "nframes %lu\n", nframes ); | |||||
const int blocks = frame_rate * seconds_to_buffer / nframes; | const int blocks = frame_rate * seconds_to_buffer / nframes; | ||||
_nframes = nframes; | _nframes = nframes; | ||||
@@ -102,7 +105,7 @@ Disk_Stream::read_block ( sample_t *buf ) | |||||
if ( ! timeline ) | if ( ! timeline ) | ||||
return; | return; | ||||
printf( "IO: attempting to read block @ %lu\n", _frame ); | |||||
// printf( "IO: attempting to read block @ %lu\n", _frame ); | |||||
if ( ! track() ) | if ( ! track() ) | ||||
{ | { | ||||
@@ -145,7 +148,7 @@ Disk_Stream::io_thread ( void ) | |||||
for ( int i = channels(); i--; ) | for ( int i = channels(); i--; ) | ||||
{ | { | ||||
int k = 0; | 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 ]; | cbuf[ k++ ] = buf[ j ]; | ||||
jack_ringbuffer_write( _rb[ i ], (char*)cbuf, block_size ); | jack_ringbuffer_write( _rb[ i ], (char*)cbuf, block_size ); | ||||
@@ -166,10 +169,11 @@ Disk_Stream::process ( nframes_t nframes ) | |||||
for ( int i = channels(); i--; ) | for ( int i = channels(); i--; ) | ||||
{ | { | ||||
sample_t *buf = (_th->output)[ i ].buffer( _nframes ); | |||||
void *buf = (_th->output)[ i ].buffer( _nframes ); | |||||
/* FIXME: handle underrun */ | /* 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(); | block_processed(); | ||||
@@ -49,8 +49,8 @@ Port::write ( sample_t *buf, nframes_t nframes ) | |||||
memcpy( buffer( nframes ), buf, nframes * sizeof( sample_t ) ); | memcpy( buffer( nframes ), buf, nframes * sizeof( sample_t ) ); | ||||
} | } | ||||
sample_t * | |||||
void * | |||||
Port::buffer ( nframes_t nframes ) | Port::buffer ( nframes_t nframes ) | ||||
{ | { | ||||
return (sample_t*)jack_port_get_buffer( _port, nframes ); | |||||
return jack_port_get_buffer( _port, nframes ); | |||||
} | } |
@@ -40,5 +40,5 @@ public: | |||||
const char * name ( void ) const { return _name; } | const char * name ( void ) const { return _name; } | ||||
void write ( sample_t *buf, nframes_t nframes ); | void write ( sample_t *buf, nframes_t nframes ); | ||||
sample_t *buffer ( nframes_t nframes ); | |||||
void *buffer ( nframes_t nframes ); | |||||
}; | }; |
@@ -565,11 +565,13 @@ Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) co | |||||
nframes_t sofs, ofs, cnt; | nframes_t sofs, ofs, cnt; | ||||
cnt = nframes; | |||||
if ( pos < r.offset ) | if ( pos < r.offset ) | ||||
{ | { | ||||
sofs = 0; | sofs = 0; | ||||
ofs = r.offset - pos; | ofs = r.offset - pos; | ||||
cnt = nframes - ofs; | |||||
cnt -= ofs; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -577,10 +579,11 @@ Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) co | |||||
sofs = pos - r.offset; | sofs = pos - r.offset; | ||||
} | } | ||||
if ( ofs > nframes ) | |||||
if ( ofs >= nframes ) | |||||
return 0; | 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 len = min( cnt, nframes - ofs ); | ||||
const nframes_t end = start + len; | 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 | /* FIXME: seeking can be very expensive. Esp. with compressed | ||||
* formats. We should attempt to avoid it. But here or in the | * formats. We should attempt to avoid it. But here or in the | ||||
* Audio_File class? */ | * 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 ); | cnt = _clip->read( buf + ofs, channel, start, end ); | ||||
/* apply gain */ | /* 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; | return cnt; | ||||
} | } |