Ejemplo n.º 1
0
LILV_API
LilvState*
lilv_state_new_from_instance(const LilvPlugin*          plugin,
                             LilvInstance*              instance,
                             LV2_URID_Map*              map,
                             const char*                file_dir,
                             const char*                copy_dir,
                             const char*                link_dir,
                             const char*                save_dir,
                             LilvGetPortValueFunc       get_value,
                             void*                      user_data,
                             uint32_t                   flags,
                             const LV2_Feature *const * features)
{
	const LV2_Feature** sfeatures = NULL;
	LilvWorld* const    world     = plugin->world;
	LilvState* const    state     = (LilvState*)malloc(sizeof(LilvState));
	memset(state, '\0', sizeof(LilvState));
	state->plugin_uri = lilv_node_duplicate(lilv_plugin_get_uri(plugin));
	state->abs2rel    = zix_tree_new(false, abs_cmp, NULL, path_rel_free);
	state->rel2abs    = zix_tree_new(false, rel_cmp, NULL, NULL);
	state->file_dir   = file_dir ? absolute_dir(file_dir) : NULL;
	state->copy_dir   = copy_dir ? absolute_dir(copy_dir) : NULL;
	state->link_dir   = link_dir ? absolute_dir(link_dir) : NULL;
	state->dir        = save_dir ? absolute_dir(save_dir) : NULL;
	state->atom_Path  = map->map(map->handle, LV2_ATOM__Path);

	LV2_State_Map_Path  pmap          = { state, abstract_path, absolute_path };
	LV2_Feature         pmap_feature  = { LV2_STATE__mapPath, &pmap };
	LV2_State_Make_Path pmake         = { state, make_path };
	LV2_Feature         pmake_feature = { LV2_STATE__makePath, &pmake };
	features = sfeatures = add_features(features, &pmap_feature,
	                                    save_dir ? &pmake_feature : NULL);

	// Store port values
	if (get_value) {
		LilvNode* lv2_ControlPort = lilv_new_uri(world, LILV_URI_CONTROL_PORT);
		LilvNode* lv2_InputPort   = lilv_new_uri(world, LILV_URI_INPUT_PORT);
		for (uint32_t i = 0; i < plugin->num_ports; ++i) {
			const LilvPort* const port = plugin->ports[i];
			if (lilv_port_is_a(plugin, port, lv2_ControlPort)
			    && lilv_port_is_a(plugin, port, lv2_InputPort)) {
				uint32_t size, type;
				const char* sym   = lilv_node_as_string(port->symbol);
				const void* value = get_value(sym, user_data, &size, &type);
				append_port_value(state, sym, value, size, type);
			}
		}
		lilv_node_free(lv2_ControlPort);
		lilv_node_free(lv2_InputPort);
	}

	// Store properties
	const LV2_Descriptor*      desc  = instance->lv2_descriptor;
	const LV2_State_Interface* iface = (desc->extension_data)
		? (LV2_State_Interface*)desc->extension_data(LV2_STATE__interface)
		: NULL;

	if (iface) {
		LV2_State_Status st = iface->save(
			instance->lv2_handle, store_callback, state, flags, features);
		if (st) {
			LILV_ERRORF("Error saving plugin state: %s\n", state_strerror(st));
			free(state->props);
			state->props     = NULL;
			state->num_props = 0;
		} else {
			qsort(state->props, state->num_props, sizeof(Property), property_cmp);
		}
	}

	qsort(state->values, state->num_values, sizeof(PortValue), value_cmp);

	free(sfeatures);
	return state;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: petersn/tsr
int main(int argc, char **argv) {
    Audio    *audio_input = NULL;
    Features features;

#ifdef SUB_RUNNING_AVERAGE
    Features running_average;
    Features features_temporary;
    zero_features( &running_average );
#endif

    printf("Tiny Speech Recognizer\n");

    // Initialize
    microphone_init();

    audio_input = NULL;

    size_t read_samples;

    while (1) {

        audio_free( audio_input );
        audio_input = audio_make_buffer( SAMPLES_IN_TIME_SLICE, MIC_FORMAT );

        // Read in a slice of audio
        read_samples = microphone_read( SAMPLES_IN_TIME_SLICE, audio_input );

        audio_convert( audio_input, DOUBLE_REAL );

        features = features_extract( audio_input );

#ifdef SUB_RUNNING_AVERAGE
        // First, copy the current feature vector, weighted by tau
        // We copy these before applying the running average subtraction to get them untainted
        copy_scaled_features( &features_temporary, &features, ((Real)1.0-(Real)RUNNING_AVERAGE_TAU) );
        // Apply the running average subtraction to the current feature vector now that we've saved it
        subtract_features( &features, &running_average );
        // Next, scale the current running average down a little bit
        scale_features( &running_average, (Real)RUNNING_AVERAGE_TAU );
        // Add the saved scaled features into running_average
        add_features( &running_average, &features_temporary );
#endif

#ifdef SQUARE_SUPPRESS
        square_suppress( &features );
#endif

        if (above_threshold( &features )) {
            features_pretty( features );
        }

        //fourier_transform( audio_input, frequencies, SAMPLES_IN_TIME_SLICE );

    }

    // Clean up
    microphone_deinit();

    return 0;

}