X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fjackrack%2Ffilter_jackrack.c;h=0c9fe9bff83e93d4b97fbb63375bddb3319b74ae;hb=d04a620d461e2fee930e50f056e53d23d56d6458;hp=37c75da6e7d2a57ff3fa9a9ed2455900f15dbc6f;hpb=25ca9db8aaf529bf0d16fdd7e4e135c0f112d7ae;p=melted diff --git a/src/modules/jackrack/filter_jackrack.c b/src/modules/jackrack/filter_jackrack.c index 37c75da..0c9fe9b 100644 --- a/src/modules/jackrack/filter_jackrack.c +++ b/src/modules/jackrack/filter_jackrack.c @@ -18,8 +18,7 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "filter_jackrack.h" - +#include #include #include @@ -32,24 +31,9 @@ #include #include -#include "ui.h" - -#define BUFFER_LEN 2048 * 3 +#include "jack_rack.h" -static void *jackrack_thread( void *arg ) -{ - mlt_properties properties = arg; - ui_t *jackrack = mlt_properties_get_data( properties, "jackrack", NULL ); - - while ( mlt_properties_get_int( properties, "_done" ) == 0 ) - if ( ui_loop_iterate( jackrack ) ) - break; - - ui_quit( jackrack ); - ui_destroy( jackrack ); - - return NULL; -} +#define BUFFER_LEN 204800 * 3 static void initialise_jack_ports( mlt_properties properties ) { @@ -65,18 +49,12 @@ static void initialise_jack_ports( mlt_properties properties ) // Start JackRack if ( mlt_properties_get( properties, "src" ) ) { - pthread_t *jackrack_pthread = mlt_pool_alloc( sizeof( pthread_t ) ); - snprintf( rack_name, sizeof( rack_name ), "jackrack%d", getpid() ); - ui_t *jackrack = ui_new( rack_name, mlt_properties_get_int( properties, "channels" ), 0, 0 ); + jack_rack_t *jackrack = jack_rack_new( rack_name, mlt_properties_get_int( properties, "channels" ) ); jack_rack_open_file( jackrack, mlt_properties_get( properties, "src" ) ); mlt_properties_set_data( properties, "jackrack", jackrack, 0, NULL, NULL ); mlt_properties_set( properties, "_rack_client_name", rack_name ); - mlt_properties_set_int( properties, "_done", 0 ); - mlt_properties_set_data( properties, "jackrack_pthread", jackrack_pthread, 0, NULL, NULL ); - - pthread_create( jackrack_pthread, NULL, jackrack_thread, properties ); } // Allocate buffers and ports @@ -236,9 +214,6 @@ static int jackrack_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form // Get the filter properties mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter ); - // Restore the original get_audio - frame->get_audio = mlt_frame_pop_audio( frame ); - int jack_frequency = mlt_properties_get_int( filter_properties, "_sample_rate" ); // Get the producer's audio @@ -256,51 +231,51 @@ static int jackrack_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form // Get the filter-specific properties jack_ringbuffer_t **output_buffers = mlt_properties_get_data( filter_properties, "output_buffers", NULL ); jack_ringbuffer_t **input_buffers = mlt_properties_get_data( filter_properties, "input_buffers", NULL ); - pthread_mutex_t *output_lock = mlt_properties_get_data( filter_properties, "output_lock", NULL ); - pthread_cond_t *output_ready = mlt_properties_get_data( filter_properties, "output_ready", NULL ); +// pthread_mutex_t *output_lock = mlt_properties_get_data( filter_properties, "output_lock", NULL ); +// pthread_cond_t *output_ready = mlt_properties_get_data( filter_properties, "output_ready", NULL ); // Process the audio int16_t *q = *buffer; - float sample; + float sample[ 2 ][ 10000 ]; int i, j; +// struct timespec tm = { 0, 0 }; // Convert to floats and write into output ringbuffer if ( jack_ringbuffer_write_space( output_buffers[0] ) >= ( *samples * sizeof(float) ) ) { for ( i = 0; i < *samples; i++ ) for ( j = 0; j < *channels; j++ ) - { - sample = ( float )( *q ++ ) / 32768.0; - jack_ringbuffer_write( output_buffers[j], ( char * )&sample, sizeof(float) ); - } + sample[ j ][ i ] = ( float )( *q ++ ) / 32768.0; + + for ( j = 0; j < *channels; j++ ) + jack_ringbuffer_write( output_buffers[j], ( char * )sample[ j ], *samples * sizeof(float) ); } // Synchronization phase - wait for signal from Jack process - while ( mlt_properties_get_int( filter_properties, "_sync" ) - && jack_ringbuffer_read_space( input_buffers[ *channels - 1 ] ) < ( *samples * sizeof(float) ) ) - pthread_cond_wait( output_ready, output_lock ); + while ( jack_ringbuffer_read_space( input_buffers[ *channels - 1 ] ) < ( *samples * sizeof(float) ) ) ; + //pthread_cond_wait( output_ready, output_lock ); // Read from input ringbuffer and convert from floats - //if ( jack_ringbuffer_read_space( input_buffers[0] ) >= ( *samples * sizeof(float) ) ) + if ( jack_ringbuffer_read_space( input_buffers[0] ) >= ( *samples * sizeof(float) ) ) { // Initialise to silence, but repeat last frame if available in case of // buffer underrun - sample = 0; + for ( j = 0; j < *channels; j++ ) + jack_ringbuffer_read( input_buffers[j], ( char * )sample[ j ], *samples * sizeof(float) ); + q = *buffer; for ( i = 0; i < *samples; i++ ) for ( j = 0; j < *channels; j++ ) { - jack_ringbuffer_read( input_buffers[j], ( char * )&sample, sizeof(float) ); - - if ( sample > 1.0 ) - sample = 1.0; - else if ( sample < -1.0 ) - sample = -1.0; + if ( sample[ j ][ i ] > 1.0 ) + sample[ j ][ i ] = 1.0; + else if ( sample[ j ][ i ] < -1.0 ) + sample[ j ][ i ] = -1.0; - if ( sample > 0 ) - *q ++ = 32767 * sample; + if ( sample[ j ][ i ] > 0 ) + *q ++ = 32767 * sample[ j ][ i ]; else - *q ++ = 32768 * sample; + *q ++ = 32768 * sample[ j ][ i ]; } } @@ -313,12 +288,10 @@ static int jackrack_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) { - if ( frame->get_audio != NULL ) { mlt_properties properties = MLT_FILTER_PROPERTIES( this ); - mlt_frame_push_audio( frame, frame->get_audio ); mlt_frame_push_audio( frame, this ); - frame->get_audio = jackrack_get_audio; + mlt_frame_push_audio( frame, jackrack_get_audio ); if ( mlt_properties_get_int( properties, "_sync" ) ) initialise_jack_ports( properties ); @@ -328,7 +301,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) } -void filter_close( mlt_filter this ) +static void filter_close( mlt_filter this ) { int i; char mlt_name[20]; @@ -352,14 +325,9 @@ void filter_close( mlt_filter this ) mlt_pool_release( mlt_properties_get_data( properties, "jack_input_buffers", NULL ) ); mlt_pool_release( mlt_properties_get_data( properties, "output_lock", NULL ) ); mlt_pool_release( mlt_properties_get_data( properties, "output_ready", NULL ) ); - - pthread_t *jackrack_pthread = mlt_properties_get_data( properties, "jackrack_thread", NULL ); - if ( jackrack_pthread != NULL ) - { - mlt_properties_set_int( properties, "_done", 1 ); - pthread_join( *jackrack_pthread, NULL ); - mlt_pool_release( jackrack_pthread ); - } + + jack_rack_t *jackrack = mlt_properties_get_data( properties, "jackrack", NULL ); + jack_rack_destroy( jackrack ); this->parent.close = NULL; mlt_service_close( &this->parent ); @@ -368,7 +336,7 @@ void filter_close( mlt_filter this ) /** Constructor for the filter. */ -mlt_filter filter_jackrack_init( char *arg ) +mlt_filter filter_jackrack_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter this = mlt_filter_new( ); if ( this != NULL )