From 2a26aa85acaded83d006404d4943a431f8147386 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 7 Apr 2008 05:00:16 -0500 Subject: [PATCH] Actually make it compile again. --- Timeline/Audio_Track.C | 11 +++++++---- Timeline/Audio_Track.H | 3 ++- Timeline/Disk_Stream.C | 43 +++++++++++++++++++++++++++-------------- Timeline/Disk_Stream.H | 22 +++++++++++++++------ Timeline/Makefile | 6 +++++- Timeline/Port.C | 10 +++++++--- Timeline/Port.H | 10 +++++++++- Timeline/Region.C | 2 +- Timeline/Region.H | 2 +- Timeline/Track_Header.H | 6 ++++++ 10 files changed, 82 insertions(+), 33 deletions(-) diff --git a/Timeline/Audio_Track.C b/Timeline/Audio_Track.C index 6db587a..6a37d7b 100644 --- a/Timeline/Audio_Track.C +++ b/Timeline/Audio_Track.C @@ -117,7 +117,7 @@ Audio_Track::handle ( int m ) /* THREAD: IO */ /** determine region coverage and fill /buf/ with interleaved samples * from /frame/ to /nframes/ for exactly /channels/ channels. */ -void +nframes_t Audio_Track::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels ) { sample_t *cbuf = new sample_t[ nframes ]; @@ -125,9 +125,9 @@ Audio_Track::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int chann /* quick and dirty--let the regions figure out coverage for themselves */ for ( list ::const_iterator i = _widgets.begin(); i != _widgets.end(); i++ ) { - const Region *r = (Region*)i; + const Region *r = (Region*)(*i); - for ( int i = channels; i-- ) + for ( int i = channels; i--; ) { memset( cbuf, 0, nframes * sizeof( sample_t ) ); @@ -136,8 +136,11 @@ Audio_Track::play ( sample_t *buf, nframes_t frame, nframes_t nframes, int chann /* interleave */ int k = 0; - for ( int j = 0; j < nframes; j += channels ) + for ( unsigned int j = 0; j < nframes; j += channels ) buf[ j ] = cbuf[ k++ ]; } } + + /* FIXME: bogus */ + return nframes; } diff --git a/Timeline/Audio_Track.H b/Timeline/Audio_Track.H index 0564923..298c0ef 100644 --- a/Timeline/Audio_Track.H +++ b/Timeline/Audio_Track.H @@ -22,6 +22,7 @@ #include "Track.H" #include "Region.H" + #include class Audio_Track : public Track @@ -53,6 +54,6 @@ public: void dump ( void ); void remove_selected ( void ); - void play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels ); + nframes_t play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels ); }; diff --git a/Timeline/Disk_Stream.C b/Timeline/Disk_Stream.C index bd94b70..2f303bb 100644 --- a/Timeline/Disk_Stream.C +++ b/Timeline/Disk_Stream.C @@ -17,9 +17,12 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ +#include "Disk_Stream.H" #include "Track_Header.H" +#include "Audio_Track.H" +#include "Port.H" -static float seconds_to_buffer = 5.0f; +float Disk_Stream::seconds_to_buffer = 5.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 @@ -31,9 +34,10 @@ static float seconds_to_buffer = 5.0f; /* FIXME: can this be made to actually handle capture? */ /* FIXME: needs error handling everywhere! */ -Disk_Stream::Disk_Stream ( const Track_Header *th, float frame_rate, nframes_t nframes, int channels ) : _th( th ) +Disk_Stream::Disk_Stream ( Track_Header *th, float frame_rate, nframes_t nframes, int channels ) : _th( th ) { _frame = 0; + _thread = 0; const int blocks = frame_rate * seconds_to_buffer / nframes; @@ -41,7 +45,7 @@ Disk_Stream::Disk_Stream ( const Track_Header *th, float frame_rate, nframes_t n size_t bufsize = blocks * nframes * sizeof( sample_t ); - for ( int i = channels(); i-- ) + for ( int i = channels; i--; ) _rb[ i ] = jack_ringbuffer_create( bufsize ); sem_init( &_blocks, 0, blocks ); @@ -49,18 +53,18 @@ Disk_Stream::Disk_Stream ( const Track_Header *th, float frame_rate, nframes_t n run(); } -virtual ~Disk_Stream::Disk_Stream ( ) +Disk_Stream::~Disk_Stream ( ) { _th = NULL; sem_destroy( &_blocks ); - for ( int i = channels(); i-- ) + for ( int i = channels(); i--; ) jack_ringbuffer_free( _rb[ i ] ); } Audio_Track * -Disk_Stream::track ( void ) const +Disk_Stream::track ( void ) { return (Audio_Track*)_th->track(); } @@ -69,15 +73,23 @@ Disk_Stream::track ( void ) const void Disk_Stream::run ( void ) { - if ( pthread_create( 0, 0, &Disk_Stream::io_thread, this ) != 0 ) + if ( pthread_create( &_thread, NULL, &Disk_Stream::io_thread, this ) != 0 ) /* error */; } +/* void */ +/* DIsk_Stream::shutdown ( void ) */ +/* { */ +/* pthread_join( &_thread, NULL ); */ +/* } */ + /* static wrapper */ -void +void * Disk_Stream::io_thread ( void *arg ) { ((Disk_Stream*)arg)->io_thread(); + + return NULL; } /* THREAD: IO */ @@ -111,13 +123,13 @@ Disk_Stream::io_thread ( void ) /* deinterleave the buffer and stuff it into the per-channel ringbuffers */ - for ( int i = channels(); i-- ) + for ( int i = channels(); i--; ) { int k = 0; - for ( int j = i; j < _nframes; j += channels() ) + for ( unsigned int j = i; j < _nframes; j += channels() ) cbuf[ k++ ] = buf[ j ]; - jack_ringbuffer_write( _rb[ i ], cbuf, block_size ); + jack_ringbuffer_write( _rb[ i ], (char*)cbuf, block_size ); } } @@ -129,15 +141,16 @@ Disk_Stream::io_thread ( void ) /** take a block from the ringbuffers and send it out the track's * ports */ void -Disk_Stream::process ( vector ports ) +Disk_Stream::process ( void ) { const size_t block_size = _nframes * sizeof( sample_t ); - for ( int i = channels(); i-- ) + for ( int i = channels(); i--; ) { - sample_t *buf = _th->output[ i ]->buffer(); + sample_t *buf = (_th->output)[ i ].buffer( _nframes ); - jack_ringbuffer_read( _rb[ i ], buf, block_size ); + /* FIXME: handle underrun */ + jack_ringbuffer_read( _rb[ i ], (char*)buf, block_size ); } block_processed(); diff --git a/Timeline/Disk_Stream.H b/Timeline/Disk_Stream.H index 9813441..e69657f 100644 --- a/Timeline/Disk_Stream.H +++ b/Timeline/Disk_Stream.H @@ -19,20 +19,29 @@ #pragma once +#include "Port.H" // for nframes_t + #include #include +#include + +#include #include using std::vector; class Track_Header; +class Audio_Track; class Disk_Stream { - const Track_Header *_th; /* Track_Header we whould be playing */ + pthread_t _thread; + + Track_Header *_th; /* Track_Header we whould be playing */ nframes_t _nframes; + nframes_t _frame; vector _rb; @@ -42,19 +51,21 @@ class Disk_Stream int channels ( void ) const { return _rb.size(); } - Audio_Track * track ( void ) const; + Audio_Track * track ( void ); + + static void *io_thread ( void *arg ); protected: void block_processed ( void ) { sem_post( &_blocks ); } - bool wait_for_block ( void ) { while ( sem_wait( &_work ) == EINTR ); return true; } + bool wait_for_block ( void ) { while ( sem_wait( &_blocks ) == EINTR ); return true; } public: /* must be set before any Disk_Streams are created */ static float seconds_to_buffer; - Disk_Stream ( const Track_Header *th, float frame_rate, nframes_t nframes, int channels ); + Disk_Stream ( Track_Header *th, float frame_rate, nframes_t nframes, int channels ); virtual ~Disk_Stream ( ); @@ -73,9 +84,8 @@ public: } void run ( void ); - void io_thread ( void *arg ); void read_block ( sample_t *buf ); void io_thread ( void ); - void process ( vector ports ); + void process ( void ); }; diff --git a/Timeline/Makefile b/Timeline/Makefile index 4d1cd36..25173cc 100644 --- a/Timeline/Makefile +++ b/Timeline/Makefile @@ -11,6 +11,8 @@ SRCS= \ Peaks.C \ Audio_File.C \ Audio_File_SF.C \ + Port.C \ + Disk_Stream.C \ Loggable.C \ OBJS=$(SRCS:.C=.o) @@ -25,8 +27,10 @@ $(OBJS): Makefile include ../make.inc +#LIBS:=$(LIBS) -ljack -lpthread + timeline: $(OBJS) - $(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) $(OBJS) -o $@ + $(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -ljack -lpthread $(OBJS) -o $@ clean: rm -f $(OBJS) timeline makedepend diff --git a/Timeline/Port.C b/Timeline/Port.C index e350ce8..5a9c7fe 100644 --- a/Timeline/Port.C +++ b/Timeline/Port.C @@ -17,6 +17,10 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ +#include "Port.H" + +#include + /* nframes is the number of frames to buffer */ Port::Port ( jack_port_t *port ) { @@ -32,11 +36,11 @@ Port::~Port ( ) void Port::write ( sample_t *buf, nframes_t nframes ) { - memcpy( buffer(), buf, nframes * sizeof( sample_t ) ); + memcpy( buffer( nframes ), buf, nframes * sizeof( sample_t ) ); } sample_t * -Port::buffer ( void ) +Port::buffer ( nframes_t nframes ) { - return (sample_t*)jack_port_get_buffer( _port ); + return (sample_t*)jack_port_get_buffer( _port, nframes ); } diff --git a/Timeline/Port.H b/Timeline/Port.H index 6980dc8..4649085 100644 --- a/Timeline/Port.H +++ b/Timeline/Port.H @@ -17,6 +17,14 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ +#pragma once + +#include + +typedef float sample_t; +//typedef jack_nframes_t nframes_t; +typedef unsigned long nframes_t; + class Port { jack_port_t *_port; @@ -31,5 +39,5 @@ public: const char * name ( void ) const { return _name; } void write ( sample_t *buf, nframes_t nframes ); - + sample_t *buffer ( nframes_t nframes ); }; diff --git a/Timeline/Region.C b/Timeline/Region.C index 1e291d7..78b7206 100644 --- a/Timeline/Region.C +++ b/Timeline/Region.C @@ -551,7 +551,7 @@ Region::normalize ( void ) again? */ /* FIXME: should fade-out/fade-ins not be handled here? */ nframes_t -Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) +Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const { const Range &r = _range; diff --git a/Timeline/Region.H b/Timeline/Region.H index 11a47a8..a820097 100644 --- a/Timeline/Region.H +++ b/Timeline/Region.H @@ -206,7 +206,7 @@ public: void normalize ( void ); - nframes_t read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ); + nframes_t read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channel ) const; }; #endif diff --git a/Timeline/Track_Header.H b/Timeline/Track_Header.H index 8c78d42..b2c2379 100644 --- a/Timeline/Track_Header.H +++ b/Timeline/Track_Header.H @@ -30,6 +30,10 @@ #include "Loggable.H" +#include "Port.H" +#include +using std::vector; + class Track_Header : public Fl_Group, public Loggable { @@ -68,6 +72,8 @@ public: Fl_Pack *takes; + vector output; /* output ports... */ + const char *class_name ( void ) { return "Track_Header"; }