marlin r1301 - in trunk: marlin src src/dialogs



Author: iain
Date: Thu Oct  9 00:38:57 2008
New Revision: 1301
URL: http://svn.gnome.org/viewvc/marlin?rev=1301&view=rev

Log:
When removing a channel with mixing, mix the channels together at half 
volume so that they don't instantly clip


Modified:
   trunk/marlin/ChangeLog
   trunk/marlin/marlin-channel.c
   trunk/marlin/marlin-channel.h
   trunk/marlin/marlin-sample.c
   trunk/marlin/marlin-utils.c
   trunk/marlin/marlin-utils.h
   trunk/src/dialogs/marlin-adjust-channel-dialogs.c
   trunk/src/marlin-window-menu.c

Modified: trunk/marlin/marlin-channel.c
==============================================================================
--- trunk/marlin/marlin-channel.c	(original)
+++ trunk/marlin/marlin-channel.c	Thu Oct  9 00:38:57 2008
@@ -1370,8 +1370,8 @@
  * marlin_channel_mix:
  * @dest:
  * @src:
- * @src_db:
- * @dest_db:
+ * @s_ratio:
+ * @d_ratio:
  * @start_frame:
  * @end_frame:
  * @clip:
@@ -1388,8 +1388,8 @@
 gboolean
 marlin_channel_mix (MarlinChannel *dest,
 		    MarlinChannel *src,
-		    double src_db,
-		    double dest_db,
+		    double s_ratio,
+		    double d_ratio,
 		    guint64 start_frame,
 		    guint64 end_frame,
 		    gboolean clip,
@@ -1398,7 +1398,6 @@
 		    GError **error)
 {
 	MarlinBlock *s_block, *d_block, *d;
-	float s_ratio, d_ratio;
 	guint64 dest_length, frames_needed, limit;
 	guint64 end_offset, s_frame;
 	float *s_buf, *d_buf;
@@ -1413,7 +1412,7 @@
 	end_offset = start_frame + src->frames - 1;
 	/* If clip == TRUE, then we're only going to end_frame
 	   otherwise we go to the end of the sample */
-	limit = clip ? MIN (end_frame, end_offset) : 
+	limit = clip ? MIN (end_frame, end_offset) :
 		MIN (dest->frames - 1, end_offset);
 
 	dest_length = (limit - start_frame) + 1;
@@ -1423,9 +1422,6 @@
 		frames_needed = clip ? dest_length : src->frames;
 	}
 
-	s_ratio = marlin_db_to_ratio (src_db);
-	d_ratio = marlin_db_to_ratio (dest_db);
-
 	/* Unlink all the blocks we're going to mix. */
 	lockless_unlink_range (dest, start_frame, limit, &d, ctxt);
 	d_block = d;
@@ -1448,18 +1444,18 @@
 		}
 
 		frames_avail = MIN (frames_needed, MARLIN_BLOCK_SIZE);
-		s_length = marlin_block_get_buffer (s_block, s_buf, 
+		s_length = marlin_block_get_buffer (s_block, s_buf,
 						    s_frame, frames_avail,
 						    &next_s_block);
 		if (d_block != NULL) {
 			d_length = marlin_block_get_buffer (d_block, d_buf,
-							    start_frame, 
+							    start_frame,
 							    frames_avail,
 							    &next_d_block);
 		} else {
 			d_length = 0;
 		}
-		
+
 		/* Mix the buffers */
 		for (i = 0; i < frames_avail; i++) {
 			d_buf[i] = (d_buf[i] * d_ratio) + (s_buf[i] * s_ratio);

Modified: trunk/marlin/marlin-channel.h
==============================================================================
--- trunk/marlin/marlin-channel.h	(original)
+++ trunk/marlin/marlin-channel.h	Thu Oct  9 00:38:57 2008
@@ -115,8 +115,8 @@
 				   GError **error);
 gboolean marlin_channel_mix (MarlinChannel *dest,
 			     MarlinChannel *src,
-			     double src_db,
-			     double dest_db,
+			     double s_ratio,
+			     double d_ratio,
 			     guint64 start_frame,
 			     guint64 end_frame,
 			     gboolean clip,

Modified: trunk/marlin/marlin-sample.c
==============================================================================
--- trunk/marlin/marlin-sample.c	(original)
+++ trunk/marlin/marlin-sample.c	Thu Oct  9 00:38:57 2008
@@ -1299,18 +1299,23 @@
 
 	WRITE_LOCK (s_priv->lock);
 	READ_LOCK (d_priv->lock);
-	
+
 	for (chan = 0; chan < s_priv->channels; chan++) {
 		MarlinChannel *s_chan, *d_chan;
+		double s_ratio, d_ratio;
 
 		s_chan = s_priv->channel_data->pdata[chan];
 		d_chan = d_priv->channel_data->pdata[chan];
 
-		marlin_channel_mix (d_chan, s_chan, src_db, dest_db, range->start, range->finish, clip, operation, ctxt, error);
+		s_ratio = marlin_db_to_ratio (src_db);
+		d_ratio = marlin_db_to_ratio (dest_db);
+		marlin_channel_mix (d_chan, s_chan, s_ratio, d_ratio,
+				    range->start, range->finish, clip,
+				    operation, ctxt, error);
 	}
 
 	channel = d_priv->channel_data->pdata[0];
-	
+
 	WRITE_UNLOCK (s_priv->lock);
 	READ_UNLOCK (d_priv->lock);
 
@@ -1842,7 +1847,9 @@
 		dest = sample->priv->channel_data->pdata[MARLIN_CHANNEL_LEFT];
 		src = sample->priv->channel_data->pdata[MARLIN_CHANNEL_RIGHT];
 
-		ret = marlin_channel_mix (dest, src, 0.0, 0.0, (guint64) 0, src->frames, FALSE, operation, ctxt, error);
+		ret = marlin_channel_mix (dest, src, 0.5, 0.5,
+					  (guint64) 0, src->frames, FALSE,
+					  operation, ctxt, error);
 		if (ret == FALSE) {
 			WRITE_UNLOCK (sample->priv->lock);
 			return FALSE;
@@ -1854,7 +1861,7 @@
 	if (ctxt) {
 		c = g_new (struct _remove_channel_closure, 1);
 		c->sample = sample;
-		
+
 		/* Create a new channel and copy the old one */
 		chan = sample->priv->channel_data->pdata[1];
 		c->channel = marlin_channel_new (sample->priv->filename, NULL);
@@ -1863,13 +1870,13 @@
 					 remove_channel_redo,
 					 remove_channel_destroy,
 					 c);
-		
+
 		marlin_undo_context_add (ctxt, u);
 	}
 
 	/* Can't be dirty if there's no samples */
 	if (sample->priv->number_of_frames == 0) {
-		g_object_set (G_OBJECT (sample), 
+		g_object_set (G_OBJECT (sample),
 			      "channels", 1,
 			      NULL);
 	} else {

Modified: trunk/marlin/marlin-utils.c
==============================================================================
--- trunk/marlin/marlin-utils.c	(original)
+++ trunk/marlin/marlin-utils.c	Thu Oct  9 00:38:57 2008
@@ -421,6 +421,12 @@
 	return 20 * log (abs (percentage) / 100.0);
 }
 
+double
+marlin_ratio_to_db (double ratio)
+{
+	return 20 * log (abs (ratio));
+}
+
 /**
  * marlin_gconf_get_int:
  * @key: The int key.

Modified: trunk/marlin/marlin-utils.h
==============================================================================
--- trunk/marlin/marlin-utils.h	(original)
+++ trunk/marlin/marlin-utils.h	Thu Oct  9 00:38:57 2008
@@ -50,6 +50,7 @@
 guint64 marlin_time_frame_string_to_ms (const char *str);
 
 double marlin_db_to_ratio (double db);
+double marlin_ratio_to_db (double db);
 double marlin_db_to_percent (double db);
 double marlin_percent_to_db (double percentage);
 

Modified: trunk/src/dialogs/marlin-adjust-channel-dialogs.c
==============================================================================
--- trunk/src/dialogs/marlin-adjust-channel-dialogs.c	(original)
+++ trunk/src/dialogs/marlin-adjust-channel-dialogs.c	Thu Oct  9 00:38:57 2008
@@ -73,7 +73,7 @@
 			g_assert_not_reached ();
 		}
 
-		ctxt = marlin_undo_manager_context_begin (rcd->undo_manager, 
+		ctxt = marlin_undo_manager_context_begin (rcd->undo_manager,
 							  _("Remove Channel"));
 		marlin_sample_remove_channel (rcd->sample,
 					      channel, 

Modified: trunk/src/marlin-window-menu.c
==============================================================================
--- trunk/src/marlin-window-menu.c	(original)
+++ trunk/src/marlin-window-menu.c	Thu Oct  9 00:38:57 2008
@@ -618,8 +618,8 @@
 		model = marlin_get_toolbars_model ();
 		position = egg_toolbars_model_add_toolbar (EGG_TOOLBARS_MODEL (model),
 							   -1, "UserCreated");
-		egg_toolbars_model_set_flags (EGG_TOOLBARS_MODEL (model), 
-					      EGG_TB_MODEL_ICONS_ONLY, 
+		egg_toolbars_model_set_flags (EGG_TOOLBARS_MODEL (model),
+					      EGG_TB_MODEL_ICONS_ONLY,
 					      position);
 		break;
 
@@ -672,7 +672,7 @@
 	g_signal_connect (G_OBJECT (dialog), "response",
 			  G_CALLBACK (toolbar_editor_response_cb), NULL);
 	gtk_widget_show (dialog);
-					 
+
 	egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR (toolbar), TRUE);
 }
 



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