Example #1
0
static gboolean
gst_iir_equalizer_setup (GstAudioFilter * audio, const GstAudioInfo * info)
{
    GstIirEqualizer *equ = GST_IIR_EQUALIZER (audio);

    switch (GST_AUDIO_INFO_FORMAT (info)) {
    case GST_AUDIO_FORMAT_S16:
        equ->history_size = history_size_gint16;
        equ->process = gst_iir_equ_process_gint16;
        break;
    case GST_AUDIO_FORMAT_F32:
        equ->history_size = history_size_gfloat;
        equ->process = gst_iir_equ_process_gfloat;
        break;
    case GST_AUDIO_FORMAT_F64:
        equ->history_size = history_size_gdouble;
        equ->process = gst_iir_equ_process_gdouble;
        break;
    default:
        return FALSE;
    }

    alloc_history (equ, info);
    return TRUE;
}
Example #2
0
static gboolean
gst_iir_equalizer_setup (GstAudioFilter * audio, GstRingBufferSpec * fmt)
{
  GstIirEqualizer *equ = GST_IIR_EQUALIZER (audio);

  switch (fmt->type) {
    case GST_BUFTYPE_LINEAR:
      switch (fmt->width) {
        case 16:
          equ->history_size = history_size_gint16;
          equ->process = gst_iir_equ_process_gint16;
          break;
        default:
          return FALSE;
      }
      break;
    case GST_BUFTYPE_FLOAT:
      switch (fmt->width) {
        case 32:
          equ->history_size = history_size_gfloat;
          equ->process = gst_iir_equ_process_gfloat;
          break;
        case 64:
          equ->history_size = history_size_gdouble;
          equ->process = gst_iir_equ_process_gdouble;
          break;
        default:
          return FALSE;
      }
      break;
    default:
      return FALSE;
  }

  alloc_history (equ);
  return TRUE;
}
Example #3
0
void
gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
{
  guint old_count, i;
  gdouble freq0, freq1, step;
  gchar name[20];

  if (equ->freq_band_count == new_count)
    return;

  BANDS_LOCK (equ);

  if (G_UNLIKELY (equ->freq_band_count == new_count)) {
    BANDS_UNLOCK (equ);
    return;
  }

  old_count = equ->freq_band_count;
  equ->freq_band_count = new_count;
  GST_DEBUG ("bands %u -> %u", old_count, new_count);

  if (old_count < new_count) {
    /* add new bands */
    equ->bands = g_realloc (equ->bands, sizeof (GstObject *) * new_count);
    for (i = old_count; i < new_count; i++) {
      /* otherwise they get names like 'iirequalizerband5' */
      sprintf (name, "band%u", i);
      equ->bands[i] = g_object_new (GST_TYPE_IIR_EQUALIZER_BAND,
          "name", name, NULL);
      GST_DEBUG ("adding band[%d]=%p", i, equ->bands[i]);

      gst_object_set_parent (GST_OBJECT (equ->bands[i]), GST_OBJECT (equ));
      gst_child_proxy_child_added (GST_OBJECT (equ),
          GST_OBJECT (equ->bands[i]));
    }
  } else {
    /* free unused bands */
    for (i = new_count; i < old_count; i++) {
      GST_DEBUG ("removing band[%d]=%p", i, equ->bands[i]);
      gst_child_proxy_child_removed (GST_OBJECT (equ),
          GST_OBJECT (equ->bands[i]));
      gst_object_unparent (GST_OBJECT (equ->bands[i]));
      equ->bands[i] = NULL;
    }
  }

  alloc_history (equ);

  /* set center frequencies and name band objects
   * FIXME: arg! we can't change the name of parented objects :(
   *   application should read band->freq to get the name
   */

  step = pow (HIGHEST_FREQ / LOWEST_FREQ, 1.0 / new_count);
  freq0 = LOWEST_FREQ;
  for (i = 0; i < new_count; i++) {
    freq1 = freq0 * step;

    if (i == 0)
      equ->bands[i]->type = BAND_TYPE_LOW_SHELF;
    else if (i == new_count - 1)
      equ->bands[i]->type = BAND_TYPE_HIGH_SHELF;
    else
      equ->bands[i]->type = BAND_TYPE_PEAK;

    equ->bands[i]->freq = freq0 + ((freq1 - freq0) / 2.0);
    equ->bands[i]->width = freq1 - freq0;
    GST_DEBUG ("band[%2d] = '%lf'", i, equ->bands[i]->freq);

    g_object_notify (G_OBJECT (equ->bands[i]), "bandwidth");
    g_object_notify (G_OBJECT (equ->bands[i]), "freq");
    g_object_notify (G_OBJECT (equ->bands[i]), "type");

    /*
       if(equ->bands[i]->freq<10000.0)
       sprintf (name,"%dHz",(gint)equ->bands[i]->freq);
       else
       sprintf (name,"%dkHz",(gint)(equ->bands[i]->freq/1000.0));
       gst_object_set_name( GST_OBJECT (equ->bands[i]), name);
       GST_DEBUG ("band[%2d] = '%s'",i,name);
     */
    freq0 = freq1;
  }

  equ->need_new_coefficients = TRUE;
  BANDS_UNLOCK (equ);
}
Example #4
0
static int judge_backwards(struct gspan *gs, GList *right_most_path, GList *projection,
						GHashTable *pm_backwards)
{
	GList *l1, *l2, *l3, *values = NULL;
	int i;
	int rmp0;

	rmp0 = 	GPOINTER_TO_INT(g_list_nth_data(right_most_path, 0));

	for (i=g_list_length(right_most_path)-2,l1=g_list_last(right_most_path);
					i >= 0; i--, l1 = g_list_previous(l1)) {
		int rmp = GPOINTER_TO_INT(l1->data);
		int rmpi = GPOINTER_TO_INT(g_list_nth_data(right_most_path, i));


		for(l2 = g_list_first(projection); l2; l2 = g_list_next(l2)) {
			struct pre_dfs *p = (struct pre_dfs *)l2->data;
			struct history *h;
			struct edge *last_edge;
			struct node *last_node, *to_node, *from_node;
			struct edge *edge;
			
			h = alloc_history();
			build_history(h, p);

			last_edge = (struct edge *)
					g_list_nth_data(h->edges, rmp0);
			last_node = graph_get_node(gs->min_graph, 
								last_edge->to);
			edge = (struct edge *)
					g_list_nth_data(h->edges, rmpi);
			to_node = graph_get_node(gs->min_graph, edge->to);
			from_node = graph_get_node(gs->min_graph, edge->from);

			for (l3 = g_list_first(last_node->edges); l3; 
							l3 = g_list_next(l3)) {
				struct edge *e = (struct edge *)l3->data;

				if (g_list_find(h->has_edges, 
							GINT_TO_POINTER(e->id)))
					continue;

				if (!g_list_find(h->has_nodes, 
							GINT_TO_POINTER(e->to)))
					continue;

				if (e->to == edge->from && 
						(e->label > edge->label || 
						(e->label == edge->label &&
							last_node->label > 
							to_node->label))) {
					struct dfs_code *dfsc;
					struct pre_dfs *npdfs;
					int from_id;
					int to_id;

					from_id = ((struct dfs_code *)
							g_list_nth_data(
							gs->min_dfs_codes, 
							rmp0))->to;

					to_id = ((struct dfs_code *)
							g_list_nth_data(
							gs->min_dfs_codes,
							rmpi))->from;
#ifdef DEBUG
					printf("!! %d %d %d ", i, rmp, rmpi);
					print_dfs(g_list_nth_data(
							gs->min_dfs_codes,
							rmpi));
					printf("\n");
					print_id_list(right_most_path);
#endif
					dfsc = malloc(sizeof(struct dfs_code));
					if (!dfsc) {
						perror("malloc dfsc in jb()");
						exit(1);
					}
					dfsc->from = from_id;
					dfsc->to = to_id;
					dfsc->from_label = last_node->label;
					dfsc->edge_label = e->label;
					dfsc->to_label = from_node->label;

					npdfs = malloc(sizeof(struct pre_dfs));
					if (!npdfs) {
						perror("malloc npdfs in jb()");
						exit(1);
					}
					npdfs->id = 0;
					npdfs->edge = e;
					npdfs->prev = p;

					if (g_hash_table_contains(pm_backwards, 
									dfsc))
						values = g_hash_table_lookup(
							pm_backwards,dfsc);
					values = g_list_append(values, npdfs);
					g_hash_table_insert(pm_backwards, dfsc,
									values);
					values = NULL;

				}
			}
			free_history(h);
		}

		if (g_hash_table_size(pm_backwards) > 0)
			return 1;
	}

	return 0;
}
Example #5
0
static int judge_forwards(struct gspan *gs, GList *right_most_path, GList *projection,
					GHashTable *pm_forwards, int min_label)
{
	int rmp0;
	struct history *h;
	GList *l1, *l2, *l3, *l4, *values = NULL;

	rmp0 = 	GPOINTER_TO_INT(g_list_nth_data(right_most_path, 0));

	for(l1 = g_list_first(projection); l1; l1 = g_list_next(l1)) {
		struct pre_dfs *p = (struct pre_dfs *)l1->data;
		struct node *last_node;
		struct edge *last_edge;
	
		h = alloc_history();
		build_history(h,p);

		last_edge = g_list_nth_data(h->edges, rmp0);
		last_node = graph_get_node(gs->min_graph, last_edge->to);
		for (l2 = g_list_first(last_node->edges); l2; 
						l2 = g_list_next(l2)) {
			struct edge *e = (struct edge *)l2->data;
			struct node *to_node;
			struct dfs_code *dfsc;
			struct pre_dfs *npdfs;
			int to_id;
			
			to_node = graph_get_node(gs->min_graph, e->to);

			if (g_list_find(h->has_nodes, 
						GINT_TO_POINTER(e->to)) || 
						to_node->label < min_label) {
#ifdef DEBUG
				printf("here1\n");
#endif
				continue;
			}
			
			to_id = ((struct dfs_code *)g_list_nth_data(
						gs->min_dfs_codes, rmp0))->to;

			dfsc = malloc(sizeof(struct dfs_code));
			if (!dfsc) {
				perror("malloc dfsc in jf()");
				exit(1);
			}
			dfsc->from = to_id;
			dfsc->to = to_id + 1;
			dfsc->from_label = last_node->label;
			dfsc->edge_label = e->label;
			dfsc->to_label = to_node->label;

			npdfs = malloc(sizeof(struct pre_dfs));
			if (!npdfs) {
				perror("malloc npdfs in jf()");
				exit(1);
			}
			npdfs->id = 0;
			npdfs->edge = e;
			npdfs->prev = p;

			if (g_hash_table_contains(pm_forwards, dfsc))
				values = g_hash_table_lookup(
							pm_forwards,dfsc);
			values = g_list_append(values, npdfs);
			g_hash_table_insert(pm_forwards, dfsc, values);
			values = NULL;

		}

		free_history(h);
	}

	
	if (g_hash_table_size(pm_forwards) == 0) {
		for(l1 = g_list_first(right_most_path); l1; 
							l1 = g_list_next(l1)) {
			int rmp = GPOINTER_TO_INT(l1->data);
			
			for (l2=g_list_first(projection); l2; l2 = g_list_next(l2)) {
				struct pre_dfs *p = (struct pre_dfs *)l2->data;
				struct edge *cur_edge;
				struct node *cur_node;
				struct node *cur_to;

				h = alloc_history();
				build_history(h, p);

				cur_edge = g_list_nth_data(h->edges, rmp);
				cur_node = graph_get_node(gs->min_graph, 
								cur_edge->from);
				cur_to = graph_get_node(gs->min_graph, 
								cur_edge->to);

				for (l3 = g_list_first(cur_node->edges); l3;
							l3 = g_list_next(l3)) {
					struct edge *e = (struct edge *)l3->data;
					struct node *to_node;
					
					to_node = graph_get_node(gs->min_graph, e->to);

					if (cur_edge->to == to_node->id || 
							g_list_find(h->has_nodes, 
									GINT_TO_POINTER(to_node->id)) || 
									to_node->label < min_label) {
#ifdef DEBUG
						printf("here2\n");
#endif
						continue;
					}

					if (cur_edge->label < e->label || 
							(cur_edge->label == e->label &&
							cur_to->label <= to_node->label)) {
						int from_id, to_id;
						struct dfs_code *dfsc;
						struct pre_dfs *npdfs;
						

						from_id = ((struct dfs_code *)g_list_nth_data(
								gs->min_dfs_codes, rmp))->from;

						to_id = ((struct dfs_code *)g_list_nth_data(
								gs->min_dfs_codes, rmp0))->to;

						dfsc = malloc(sizeof(struct dfs_code));
						if (!dfsc) {
							perror("malloc dfsc in jf()");
							exit(1);
						}
						dfsc->from = from_id;
						dfsc->to = to_id + 1;
						dfsc->from_label = cur_node->label;
						dfsc->edge_label = e->label;
						dfsc->to_label = to_node->label;

						npdfs = malloc(sizeof(struct pre_dfs));
						if (!npdfs) {
							perror("malloc npdfs in jf()");
							exit(1);
						}
						npdfs->id = 0;
						npdfs->edge = e;
						npdfs->prev = p;

						if (g_hash_table_contains(pm_forwards, dfsc))
							values = g_hash_table_lookup(
									pm_forwards,dfsc);
						values = g_list_append(values, npdfs);
						g_hash_table_insert(pm_forwards, dfsc, values);
						values = NULL;
					}
				}

				free_history(h);
			}

			if (g_hash_table_size(pm_forwards) > 0) 
				break;
		}
	}

	if (g_hash_table_size(pm_forwards) > 0) 
		return 1;
	return 0;
}