marlin r1290 - in trunk: marlin plugins



Author: iain
Date: Thu Oct  2 23:40:35 2008
New Revision: 1290
URL: http://svn.gnome.org/viewvc/marlin?rev=1290&view=rev

Log:
Update GObject boilerplate


Modified:
   trunk/marlin/ChangeLog
   trunk/marlin/marlin-sample.c
   trunk/plugins/marlin-green-noise.c

Modified: trunk/marlin/marlin-sample.c
==============================================================================
--- trunk/marlin/marlin-sample.c	(original)
+++ trunk/marlin/marlin-sample.c	Thu Oct  2 23:40:35 2008
@@ -99,7 +99,8 @@
 				to save last time */
 };
 
-static GObjectClass *parent_class = NULL;
+#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MARLIN_SAMPLE_TYPE, MarlinSamplePrivate))
+G_DEFINE_TYPE (MarlinSample, marlin_sample, G_TYPE_OBJECT);
 static guint32 signals[LAST_SIGNAL] = {0};
 
 GQuark
@@ -123,10 +124,6 @@
 	sample = MARLIN_SAMPLE (object);
 	priv = sample->priv;
 
-	if (priv == NULL) {
-		return;
-	}
-
 	/* Lock ... */
 	WRITE_LOCK (priv->lock);
 	g_print ("Destroying sample %p\n", sample);
@@ -144,10 +141,7 @@
 	WRITE_UNLOCK (priv->lock);
 	marlin_read_write_lock_destroy (priv->lock);
 
-	g_free (priv);
-	sample->priv = NULL;
-
-	G_OBJECT_CLASS (parent_class)->finalize (object);
+	G_OBJECT_CLASS (marlin_sample_parent_class)->finalize (object);
 }
 
 static void
@@ -179,7 +173,7 @@
 		priv->markers = NULL;
 	}
 
-	G_OBJECT_CLASS (parent_class)->dispose (object);
+	G_OBJECT_CLASS (marlin_sample_parent_class)->dispose (object);
 }
 
 static void
@@ -504,18 +498,18 @@
 }
 
 static void
-class_init (GObjectClass *klass)
+marlin_sample_class_init (MarlinSampleClass *klass)
 {
-	klass->finalize = finalize;
-	klass->dispose = dispose;
-	klass->set_property = set_property;
-	klass->get_property = get_property;
+	GObjectClass *o_class = (GObjectClass *) klass;
 
-	parent_class = g_type_class_peek_parent (klass);
+	o_class->finalize = finalize;
+	o_class->dispose = dispose;
+	o_class->set_property = set_property;
+	o_class->get_property = get_property;
 
+	g_type_class_add_private (o_class, sizeof (MarlinSamplePrivate));
 	/* Properties */
-	g_object_class_install_property (klass,
-					 PROP_NUMBER_OF_FRAMES,
+	g_object_class_install_property (o_class, PROP_NUMBER_OF_FRAMES,
 					 g_param_spec_uint64 ("total_frames",
 							      "",
 							      "",
@@ -523,8 +517,7 @@
 							      G_MAXUINT64,
 							      0,
 							      G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_SAMPLE_RATE,
+	g_object_class_install_property (o_class, PROP_SAMPLE_RATE,
 					 g_param_spec_uint ("sample_rate",
 							    "",
 							    "",
@@ -532,21 +525,18 @@
 							    G_MAXUINT,
 							    0,
 							    G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_FILENAME,
+	g_object_class_install_property (o_class, PROP_FILENAME,
 					 g_param_spec_string ("filename",
 							      "",
 							      "",
 							      "Untitled",
 							      G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_REALNAME,
+	g_object_class_install_property (o_class, PROP_REALNAME,
 					 g_param_spec_string ("name",
 							      "", "",
 							      "Untitled",
 							      G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_CHANNELS,
+	g_object_class_install_property (o_class, PROP_CHANNELS,
 					 g_param_spec_uint ("channels",
 							    "",
 							    "",
@@ -554,8 +544,7 @@
 							    MAX_NUM_CHANNELS,
 							    2,
 							    G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_DEPTH,
+	g_object_class_install_property (o_class, PROP_DEPTH,
 					 g_param_spec_int ("depth",
 							   "",
 							   "",
@@ -563,8 +552,7 @@
 							   G_MAXINT,
 							   1,
 							   G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_LENGTH,
+	g_object_class_install_property (o_class, PROP_LENGTH,
 					 g_param_spec_float ("length",
 							     "",
 							     "",
@@ -572,46 +560,39 @@
 							     G_MAXFLOAT,
 							     0,
 							     G_PARAM_READABLE));
-	g_object_class_install_property (klass,
-					 PROP_DIRTY,
+	g_object_class_install_property (o_class, PROP_DIRTY,
 					 g_param_spec_boolean ("dirty",
 							       "",
 							       "",
 							       FALSE,
 							       G_PARAM_READWRITE));
 
-	g_object_class_install_property (klass,
-					 PROP_WRITABLE,
+	g_object_class_install_property (o_class, PROP_WRITABLE,
 					 g_param_spec_boolean ("writable",
 							       "", "",
 							       FALSE,
 							       G_PARAM_READABLE));
-	g_object_class_install_property (klass,
-					 PROP_SELECTION,
+	g_object_class_install_property (o_class, PROP_SELECTION,
 					 g_param_spec_object ("selection",
 							      "",
 							      "",
 							      MARLIN_SAMPLE_SELECTION_TYPE,
 							      G_PARAM_READABLE));
-	g_object_class_install_property (klass,
-					 PROP_MARKER_MODEL,
+	g_object_class_install_property (o_class, PROP_MARKER_MODEL,
 					 g_param_spec_object ("markers",
 							      "", "",
 							      MARLIN_MARKER_MODEL_TYPE,
 							      G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_TAGLIST,
+	g_object_class_install_property (o_class, PROP_TAGLIST,
 					 g_param_spec_pointer ("tags",
 							       "", "",
 							       G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_ENCODER,
+	g_object_class_install_property (o_class, PROP_ENCODER,
 					 g_param_spec_object ("encoder",
 							      "", "",
 							      GST_TYPE_ELEMENT,
 							      G_PARAM_READWRITE));
-	g_object_class_install_property (klass,
-					 PROP_BPM,
+	g_object_class_install_property (o_class, PROP_BPM,
 					 g_param_spec_uint ("bpm",
 							    "", "",
 							    1, G_MAXUINT, 120,
@@ -629,54 +610,33 @@
 }
 
 static void
-init (MarlinSample *sample)
+marlin_sample_init (MarlinSample *sample)
 {
-	sample->priv = g_new0 (MarlinSamplePrivate, 1);
+	MarlinSamplePrivate *priv;
 
-	/* Create the lock */
-	sample->priv->lock = marlin_read_write_lock_new ();
-	
-	sample->priv->channel_data = g_ptr_array_new ();
-	
-	sample->priv->selection = marlin_sample_selection_new ();
+	priv = sample->priv = GET_PRIVATE (sample);
 
-	sample->priv->markers = marlin_marker_model_new ();
-	sample->priv->change_id = g_signal_connect (sample->priv->markers, 
-						    "marker-changed",
-						    G_CALLBACK (marker_changed),
-						    sample);
-	sample->priv->add_id = g_signal_connect (sample->priv->markers,
-						 "marker-added",
-						 G_CALLBACK (marker_changed),
-						 sample);
-	sample->priv->remove_id = g_signal_connect (sample->priv->markers,
-						    "marker-removed",
-						    G_CALLBACK (marker_changed),
-						    sample);
+	/* Create the lock */
+	priv->lock = marlin_read_write_lock_new ();
 
-	sample->priv->realname = NULL;
+	priv->channel_data = g_ptr_array_new ();
 
-	sample->priv->taglist = gst_tag_list_new ();
-}
+	priv->selection = marlin_sample_selection_new ();
 
-GType
-marlin_sample_get_type (void)
-{
-	static GType type = 0;
+	priv->markers = marlin_marker_model_new ();
+	priv->change_id = g_signal_connect (priv->markers, "marker-changed",
+					    G_CALLBACK (marker_changed),
+					    sample);
+	priv->add_id = g_signal_connect (priv->markers, "marker-added",
+					 G_CALLBACK (marker_changed),
+					 sample);
+	priv->remove_id = g_signal_connect (priv->markers, "marker-removed",
+					    G_CALLBACK (marker_changed),
+					    sample);
 
-	if (type == 0) {
-		GTypeInfo info = {
-			sizeof (MarlinSampleClass), NULL, NULL,
-			(GClassInitFunc) class_init, NULL, NULL,
-			sizeof (MarlinSample), 0, (GInstanceInitFunc) init
-		};
-
-		type = g_type_register_static (G_TYPE_OBJECT,
-					       "MarlinSample",
-					       &info, 0);
-	}
+	priv->realname = NULL;
 
-	return type;
+	priv->taglist = gst_tag_list_new ();
 }
 
 /**

Modified: trunk/plugins/marlin-green-noise.c
==============================================================================
--- trunk/plugins/marlin-green-noise.c	(original)
+++ trunk/plugins/marlin-green-noise.c	Thu Oct  2 23:40:35 2008
@@ -2,7 +2,7 @@
 /*
  *  Authors: Iain Holmes <iain gnome org>
  *
- *  Copyright 2007 Iain Holmes
+ *  Copyright 2007 - 2008 Iain Holmes
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of version 2 of the GNU General Public
@@ -52,11 +52,13 @@
 			      int            window_length,
 			      int            sources)
 {
-	guint64 frames_needed, insert_point;
-	float *out_buf;
+	guint64 frames_needed, insert_point, offset;
+	float *out_buf, total;
+	float cache[sources];
+
 	struct _source *offsets[sources];
 	MarlinBlock *block;
-	int j;
+	int j, running;
 
 	frames_needed = src->frames;
 	insert_point = 0;
@@ -65,12 +67,73 @@
 
 	block = src->first;
 
+	offset = 0;
+	running = 0;
+	total = 0.0;
+
+#if 0
+	/* This is a fast algorithm, but it produces very bad green noise
+	   It is more like an analogue delay */
+	while (frames_needed > 0) {
+		guint frames_avail;
+		int i;
+
+		frames_avail = MIN (frames_needed, MARLIN_BLOCK_SIZE);
+
+		for (i = 0; i < frames_avail; i++) {
+			guint offset_in_block;
+			float *buf;
+
+			running++;
+
+			buf = marlin_block_get_frame_data (block);
+			offset_in_block = offset - block->start;
+
+			if (running <= sources) {
+				total += buf [offset_in_block];
+			} else {
+				float remove;
+
+				total += buf [offset_in_block];
+				if (offset_in_block < sources) {
+					guint offset_in_cache;
+
+					offset_in_cache = sources - (sources - offset_in_block);
+					remove = cache[offset_in_cache];
+				} else {
+					remove = buf [offset_in_block - sources];
+				}
+				total -= remove;
+			}
+
+			out_buf[i] = total / sqrt (sources);
+
+			offset++;
+			if (offset > block->end) {
+				/* Cache the last frames of the buffer so that
+				   we can still reference them when we need to
+				   subtract them later */
+				memcpy (cache,
+					buf + (block->num_frames - sources),
+					sizeof (float) * sources);
+				block = block->next;
+			}
+		}
+
+		marlin_channel_insert_data (dest, out_buf, frames_avail,
+					    insert_point, NULL, NULL);
+
+		frames_needed -= frames_avail;
+		insert_point += frames_avail;
+	}
+#endif
+
 	for (j = 0; j < sources; j++) {
 		struct _source *source;
 
 		source = g_new (struct _source, 1);
 		source->offset = random () % window_length;
-		source->block = marlin_channel_get_block_for_frame 
+		source->block = marlin_channel_get_block_for_frame
 			(src, source->offset);
 
 		offsets[j] = source;
@@ -99,7 +162,7 @@
 				offset_in_block = source->offset - source->block->start;
 				total += buf [offset_in_block];
 				source->offset++;
-				
+
 				if (source->offset > source->block->end) {
 					source->block = source->block->next;
 				}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]