コード例 #1
0
ファイル: plugin.c プロジェクト: vpinon/mlt
static void
plugin_init_holder (plugin_t * plugin,
                    guint copy,
                    LADSPA_Handle instance,
                    jack_rack_t * jack_rack)
{
    unsigned long i;
    plugin_desc_t * desc;
    ladspa_holder_t * holder;

    desc = plugin->desc;
    holder = plugin->holders + copy;

    holder->instance = instance;

    if (desc->control_port_count > 0)
    {
        holder->ui_control_fifos    = g_malloc (sizeof (lff_t) * desc->control_port_count);
        holder->control_memory = g_malloc (sizeof (LADSPA_Data) * desc->control_port_count);
    }
    else
    {
        holder->ui_control_fifos  = NULL;
        holder->control_memory = NULL;
    }

    for (i = 0; i < desc->control_port_count; i++)
    {
        lff_init (holder->ui_control_fifos + i, CONTROL_FIFO_SIZE, sizeof (LADSPA_Data));
        holder->control_memory[i] =
            plugin_desc_get_default_control_value (desc, desc->control_port_indicies[i], sample_rate);

        plugin->descriptor->
        connect_port (instance, desc->control_port_indicies[i], holder->control_memory + i);
    }

    if (desc->status_port_count > 0)
    {
        holder->status_memory = g_malloc (sizeof (LADSPA_Data) * desc->status_port_count);
    }
    else
    {
        holder->status_memory = NULL;
    }

    for (i = 0; i < desc->status_port_count; i++)
    {
        plugin->descriptor->
        connect_port (instance, desc->status_port_indicies[i], holder->status_memory + i);
    }

    if (jack_rack->procinfo->jack_client && plugin->desc->aux_channels > 0)
        plugin_create_aux_ports (plugin, copy, jack_rack);

    if (plugin->descriptor->activate)
        plugin->descriptor->activate (instance);
}
コード例 #2
0
ファイル: factory.c プロジェクト: vpinon/mlt
static void add_port_to_metadata( mlt_properties p, plugin_desc_t* desc, int j )
{
	LADSPA_Data sample_rate = 48000;
	LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor;

	mlt_properties_set( p, "title", desc->port_names[ j ] );
	if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) )
	{
		mlt_properties_set( p, "type", "integer" );
		mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
	}
	else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) )
	{
		mlt_properties_set( p, "type", "boolean" );
		mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
	}
	else
	{
		mlt_properties_set( p, "type", "float" );
		mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
	}
	/* set upper and lower, possibly adjusted to the sample rate */
	if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) )
	{
		LADSPA_Data lower = desc->port_range_hints[j].LowerBound;
		if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
			lower *= sample_rate;
		if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
		{
			if (lower < FLT_EPSILON)
				lower = FLT_EPSILON;
		}
		mlt_properties_set_double( p, "minimum", lower );
	}
	if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) )
	{
		LADSPA_Data upper = desc->port_range_hints[j].UpperBound;
		if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
			upper *= sample_rate;
		mlt_properties_set_double( p, "maximum", upper );
	}
	if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
		mlt_properties_set( p, "scale", "log" );
}
コード例 #3
0
ファイル: producer_ladspa.c プロジェクト: aib/mlt
static jack_rack_t* initialise_jack_rack( mlt_properties properties, int channels )
{
	jack_rack_t *jackrack = NULL;
	unsigned long plugin_id = mlt_properties_get_int64( properties, "_pluginid" );

	// Start JackRack
	if ( plugin_id )
	{
		// Create JackRack without Jack client name so that it only uses LADSPA
		jackrack = jack_rack_new( NULL, channels );
		mlt_properties_set_data( properties, "_jackrack", jackrack, 0,
			(mlt_destructor) jack_rack_destroy, NULL );

		// Load one LADSPA plugin by its UniqueID
		plugin_desc_t *desc = plugin_mgr_get_any_desc( jackrack->plugin_mgr, plugin_id );
		plugin_t *plugin;

		if ( desc && ( plugin = jack_rack_instantiate_plugin( jackrack, desc ) ) )
		{
			LADSPA_Data value;
			int index, c;

			plugin->enabled = TRUE;
			plugin->wet_dry_enabled = FALSE;
			for ( index = 0; index < desc->control_port_count; index++ )
			{
				// Apply the control port values
				char key[20];
				value = plugin_desc_get_default_control_value( desc, index, sample_rate );
				snprintf( key, sizeof(key), "%d", index );
				if ( mlt_properties_get( properties, key ) )
					value = mlt_properties_get_double( properties, key );
				for ( c = 0; c < plugin->copies; c++ )
					plugin->holders[c].control_memory[index] = value;
			}
			process_add_plugin( jackrack->procinfo, plugin );
		}
		else
		{
			mlt_log_error( properties, "failed to load plugin %lu\n", plugin_id );
		}
	}

	return jackrack;
}
コード例 #4
0
ファイル: plugin_settings.c プロジェクト: amongll/AVFX
static void
settings_set_to_default (settings_t * settings, guint32 sample_rate)
{
    unsigned long control;
    guint copy;
    LADSPA_Data value;

    for (control = 0; control < settings->desc->control_port_count; control++)
    {
        value = plugin_desc_get_default_control_value (settings->desc, control, sample_rate);

        for (copy = 0; copy < settings->copies; copy++)
        {
            settings->control_values[copy][control] = value;
        }

        settings->locks[control] = TRUE;
    }
}
コード例 #5
0
ファイル: factory.c プロジェクト: amongll/AVFX
static mlt_properties metadata( mlt_service_type type, const char *id, char *data )
{
	char file[ PATH_MAX ];
	if( type == filter_type )
	{
		snprintf( file, PATH_MAX, "%s/jackrack/%s",
			  mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "filter_ladspa.yml" );
	}
	else
	{
		snprintf( file, PATH_MAX, "%s/jackrack/%s",
			  mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "producer_ladspa.yml" );
	}
	mlt_properties result = mlt_properties_parse_yaml( file );

#ifdef GPL
	if ( !strncmp( id, "ladspa.", 7 ) )
	{
		// Annotate the yaml properties with ladspa control port info.
		plugin_desc_t *desc = plugin_mgr_get_any_desc( g_jackrack_plugin_mgr, strtol( id + 7, NULL, 10 ) );

		if ( desc )
		{
			mlt_properties params = mlt_properties_new();
			mlt_properties p;
			char key[20];
			int i;

			mlt_properties_set( result, "identifier", id );
			mlt_properties_set( result, "title", desc->name );
			mlt_properties_set( result, "creator", desc->maker ? desc->maker : "unknown" );
			mlt_properties_set( result, "description", "LADSPA plugin" );
			mlt_properties_set_data( result, "parameters", params, 0, (mlt_destructor) mlt_properties_close, NULL );
			for ( i = 0; i < desc->control_port_count; i++ )
			{
				int j = desc->control_port_indicies[i];
				LADSPA_Data sample_rate = 48000;
				LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor;

				p = mlt_properties_new();
				snprintf( key, sizeof(key), "%d", i );
				mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
				snprintf( key, sizeof(key), "%d", j );
				mlt_properties_set( p, "identifier", key );
				mlt_properties_set( p, "title", desc->port_names[ j ] );
				if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) )
				{
					mlt_properties_set( p, "type", "integer" );
					mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
				}
				else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) )
				{
					mlt_properties_set( p, "type", "boolean" );
					mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
				}
				else
				{
					mlt_properties_set( p, "type", "float" );
					mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
				}
				/* set upper and lower, possibly adjusted to the sample rate */
				if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) )
				{
					LADSPA_Data lower = desc->port_range_hints[j].LowerBound;
					if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
						lower *= sample_rate;
					if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
					{
						if (lower < FLT_EPSILON)
							lower = FLT_EPSILON;
					}
					mlt_properties_set_double( p, "minimum", lower );
				}
				if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) )
				{
					LADSPA_Data upper = desc->port_range_hints[j].UpperBound;
					if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
						upper *= sample_rate;
					mlt_properties_set_double( p, "maximum", upper );
				}
				if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
					mlt_properties_set( p, "scale", "log" );
				mlt_properties_set( p, "mutable", "yes" );
			}

			if( type == filter_type )
			{
				p = mlt_properties_new();
				snprintf( key, sizeof(key), "%d", i );
				mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
				mlt_properties_set( p, "identifier", "wetness" );
				mlt_properties_set( p, "title", "Wet/Dry" );
				mlt_properties_set( p, "type", "float" );
				mlt_properties_set_double( p, "default", 1 );
				mlt_properties_set_double( p, "minimum", 0 );
				mlt_properties_set_double( p, "maximum", 1 );
				mlt_properties_set( p, "mutable", "yes" );
			}
		}
	}
#endif

	return result;
}
コード例 #6
0
ファイル: plugin.c プロジェクト: jwm-art-net/jack-rack
static void
plugin_init_holder (plugin_t * plugin,
                    guint copy,
                    LADSPA_Handle instance,
                    jack_rack_t * jack_rack)
{
  unsigned long i;
  plugin_desc_t * desc;
  ladspa_holder_t * holder;
  
  desc = plugin->desc;
  holder = plugin->holders + copy;
  
  holder->instance = instance;
  
  if (desc->control_port_count > 0)
    {
      holder->ui_control_fifos    = g_malloc (sizeof (lff_t) * desc->control_port_count);
#ifdef HAVE_ALSA
      holder->midi_control_fifos  = g_malloc (sizeof (lff_t) * desc->control_port_count);
#endif
      holder->control_memory = g_malloc (sizeof (LADSPA_Data) * desc->control_port_count);
    }
  else
    {
      holder->ui_control_fifos  = NULL;
#ifdef HAVE_ALSA
      holder->midi_control_fifos  = NULL;
#endif
      holder->control_memory = NULL;
    }
  
  for (i = 0; i < desc->control_port_count; i++)
    {
      lff_init (holder->ui_control_fifos + i, CONTROL_FIFO_SIZE, sizeof (LADSPA_Data));
#ifdef HAVE_ALSA
      lff_init (holder->midi_control_fifos + i, CONTROL_FIFO_SIZE, sizeof (LADSPA_Data));
#endif
      
      holder->control_memory[i] =
        plugin_desc_get_default_control_value (desc, desc->control_port_indicies[i], sample_rate);        
      
      plugin->descriptor->
        connect_port (instance, desc->control_port_indicies[i], holder->control_memory + i);
    }
  
  for (i = 0; i < desc->port_count; i++)
    {
      if (!LADSPA_IS_PORT_CONTROL (desc->port_descriptors[i]))
        continue;
      
      if (LADSPA_IS_PORT_OUTPUT (desc->port_descriptors[i]))
        plugin->descriptor-> connect_port (instance, i, &unused_control_port_output);
    }
  
  if (plugin->desc->aux_channels > 0)
    plugin_create_aux_ports (plugin, copy, jack_rack);
  
  if (plugin->descriptor->activate)
    plugin->descriptor->activate (instance);
}
コード例 #7
0
ファイル: filter_ladspa.c プロジェクト: mltframework/mlt
static int ladspa_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
	int error = 0;

	// Get the filter service
	mlt_filter filter = mlt_frame_pop_audio( frame );

	// Get the filter properties
	mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );

	// Check if the channel configuration has changed
	int prev_channels = mlt_properties_get_int( filter_properties, "_prev_channels" );
	if ( prev_channels != *channels )
	{
		if( prev_channels )
		{
			mlt_log_info( MLT_FILTER_SERVICE(filter), "Channel configuration changed. Old: %d New: %d.\n", prev_channels, *channels );
			mlt_properties_set_data( filter_properties, "jackrack", NULL, 0, (mlt_destructor) NULL, NULL );
		}
		mlt_properties_set_int( filter_properties, "_prev_channels", *channels );
	}

	// Initialise LADSPA if needed
	jack_rack_t *jackrack = mlt_properties_get_data( filter_properties, "jackrack", NULL );
	if ( jackrack == NULL )
	{
		sample_rate = *frequency; // global inside jack_rack
		jackrack = initialise_jack_rack( filter_properties, *channels );
	}

	if ( jackrack && jackrack->procinfo && jackrack->procinfo->chain &&
		 mlt_properties_get_int64( filter_properties, "_pluginid" ) )
	{
		plugin_t *plugin = jackrack->procinfo->chain;
		LADSPA_Data value;
		int i, c;
		mlt_position position = mlt_filter_get_position( filter, frame );
		mlt_position length = mlt_filter_get_length2( filter, frame );

		// Get the producer's audio
		*format = mlt_audio_float;
		mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );

		// Resize the buffer if necessary.
		if ( *channels < jackrack->channels )
		{
			// Add extra channels to satisfy the plugin.
			// Extra channels in the buffer will be ignored by downstream services.
			int old_size = mlt_audio_format_size( *format, *samples, *channels );
			int new_size = mlt_audio_format_size( *format, *samples, jackrack->channels );
			uint8_t* new_buffer = mlt_pool_alloc( new_size );
			memcpy( new_buffer, *buffer, old_size );
			// Put silence in extra channels.
			memset( new_buffer + old_size, 0, new_size - old_size );
			mlt_frame_set_audio( frame, new_buffer, *format, new_size, mlt_pool_release );
			*buffer = new_buffer;
		}

		for ( i = 0; i < plugin->desc->control_port_count; i++ )
		{
			// Apply the control port values
			char key[20];
			value = plugin_desc_get_default_control_value( plugin->desc, i, sample_rate );
			snprintf( key, sizeof(key), "%d", i );
			if ( mlt_properties_get( filter_properties, key ) )
				value = mlt_properties_anim_get_double( filter_properties, key, position, length );
			for ( c = 0; c < plugin->copies; c++ )
				plugin->holders[c].control_memory[i] = value;
		}
		plugin->wet_dry_enabled = mlt_properties_get( filter_properties, "wetness" ) != NULL;
		if ( plugin->wet_dry_enabled )
		{
			value = mlt_properties_anim_get_double( filter_properties, "wetness", position, length );
			for ( c = 0; c < jackrack->channels; c++ )
				plugin->wet_dry_values[c] = value;
		}

		// Configure the buffers
		LADSPA_Data **input_buffers  = mlt_pool_alloc( sizeof( LADSPA_Data* ) * jackrack->channels );
		LADSPA_Data **output_buffers = mlt_pool_alloc( sizeof( LADSPA_Data* ) * jackrack->channels );
		
		// Some plugins crash with too many frames (samples).
		// So, feed the plugin with N samples per loop iteration.
		int samples_offset = 0;
		int sample_count = MIN(*samples, MAX_SAMPLE_COUNT);
		for (i = 0; samples_offset < *samples; i++) {
			int j = 0;
			for (; j < jackrack->channels; j++)
				output_buffers[j] = input_buffers[j] = (LADSPA_Data*) *buffer + j * (*samples) + samples_offset;
			sample_count = MIN(*samples - samples_offset, MAX_SAMPLE_COUNT);
			// Do LADSPA processing
			error = process_ladspa( jackrack->procinfo, sample_count, input_buffers, output_buffers );
			samples_offset += MAX_SAMPLE_COUNT;
		}

		mlt_pool_release( input_buffers );
		mlt_pool_release( output_buffers );

		// read the status port values
		for ( i = 0; i < plugin->desc->status_port_count; i++ )
		{
			char key[20];
			int p = plugin->desc->status_port_indicies[i];
			for ( c = 0; c < plugin->copies; c++ )
			{
				snprintf( key, sizeof(key), "%d[%d]", p, c );
				value = plugin->holders[c].status_memory[i];
				mlt_properties_set_double( filter_properties, key, value );
			}
		}
	}
	else
	{
		// Nothing to do.
		error = mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
	}

	return error;
}
コード例 #8
0
ファイル: filter_ladspa.c プロジェクト: amongll/mlt
static int ladspa_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
	int error = 0;

	// Get the filter service
	mlt_filter filter = mlt_frame_pop_audio( frame );

	// Get the filter properties
	mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );

	// Initialise LADSPA if needed
	jack_rack_t *jackrack = mlt_properties_get_data( filter_properties, "jackrack", NULL );
	if ( jackrack == NULL )
	{
		sample_rate = *frequency; // global inside jack_rack
		jackrack = initialise_jack_rack( filter_properties, *channels );
	}

	if ( jackrack && jackrack->procinfo && jackrack->procinfo->chain &&
		 mlt_properties_get_int64( filter_properties, "_pluginid" ) )
	{
		plugin_t *plugin = jackrack->procinfo->chain;
		LADSPA_Data value;
		int i, c;
		mlt_position position = mlt_filter_get_position( filter, frame );
		mlt_position length = mlt_filter_get_length2( filter, frame );

		// Get the producer's audio
		*channels = jackrack->channels;
		*format = mlt_audio_float;
		mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );

		for ( i = 0; i < plugin->desc->control_port_count; i++ )
		{
			// Apply the control port values
			char key[20];
			value = plugin_desc_get_default_control_value( plugin->desc, i, sample_rate );
			snprintf( key, sizeof(key), "%d", i );
			if ( mlt_properties_get( filter_properties, key ) )
				value = mlt_properties_anim_get_double( filter_properties, key, position, length );
			for ( c = 0; c < plugin->copies; c++ )
				plugin->holders[c].control_memory[i] = value;
		}
		plugin->wet_dry_enabled = mlt_properties_get( filter_properties, "wetness" ) != NULL;
		if ( plugin->wet_dry_enabled )
		{
			value = mlt_properties_anim_get_double( filter_properties, "wetness", position, length );
			for ( c = 0; c < *channels; c++ )
				plugin->wet_dry_values[c] = value;
		}

		// Configure the buffers
		LADSPA_Data **input_buffers  = mlt_pool_alloc( sizeof( LADSPA_Data* ) * *channels );
		LADSPA_Data **output_buffers = mlt_pool_alloc( sizeof( LADSPA_Data* ) * *channels );

		for ( i = 0; i < *channels; i++ )
		{
			input_buffers[i]  = (LADSPA_Data*) *buffer + i * *samples;
			output_buffers[i] = (LADSPA_Data*) *buffer + i * *samples;
		}

		// Do LADSPA processing
		error = process_ladspa( jackrack->procinfo, *samples, input_buffers, output_buffers );

		mlt_pool_release( input_buffers );
		mlt_pool_release( output_buffers );

		// read the status port values
		for ( i = 0; i < plugin->desc->status_port_count; i++ )
		{
			char key[20];
			int p = plugin->desc->status_port_indicies[i];
			for ( c = 0; c < plugin->copies; c++ )
			{
				snprintf( key, sizeof(key), "%d[%d]", p, c );
				value = plugin->holders[c].status_memory[i];
				mlt_properties_set_double( filter_properties, key, value );
			}
		}
	}
	else
	{
		// Nothing to do.
		error = mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
	}

	return error;
}