1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../mixmagic/pitch.patch
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
8 # More information can be found in the files COPYING and README.
10 # This patch file is dual-licensed. It is available under the license the
11 # patched project is licensed under, as long as it is an OpenSource license
12 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
13 # of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
16 # --- T2-COPYRIGHT-NOTE-END ---
19 This patch adds pitch shifting to mixmagic. (by Clifford)
21 --- ./src/block.c.orig Sat Mar 9 11:06:32 2002
22 +++ ./src/block.c Mon May 13 20:16:56 2002
25 b->start = block->start + MIN (block->selection_start, block->selection_end);
26 b->length = ABS (block->selection_start - block->selection_end);
27 + block->length_unpitched = block->length * block->pitch;
28 b->sample = sample_ref (block->sample);
29 b->position = block->position + MIN (block->selection_start, block->selection_end);
32 newBlock->sample = sample_ref (block->sample);
33 newBlock->start = block->start;
34 newBlock->length = block->length;
35 + newBlock->length_unpitched = block->length_unpitched;
36 + newBlock->pitch = block->pitch;
38 /* Position it on the same place as the popup menu */
39 newBlock->position = block->position;
41 block_draw (Block *block)
43 gint i, width, height;
45 - GString * start_gs , * len_gs ;
46 + gint offset, offset_start, value;
47 + GString * start_gs , * len_gs , * pitch_gs;
49 g_assert (IS_BLOCK(block));
51 @@ -1210,11 +1213,13 @@
55 - offset = block->start / INDEX_RATIO;
56 + offset_start = block->start / INDEX_RATIO;
59 for (i = 0; i < width;i++) {
60 value = index_get_average (block->sample->index,
61 - offset, block->start / INDEX_RATIO,
62 + offset_start + offset * block->pitch,
63 + block->start / INDEX_RATIO,
64 block->track->song->x_scale / INDEX_RATIO,
65 block->sample->length / INDEX_RATIO / 2) / ((float)0x7f / height);
66 gdk_draw_line (block->pixmap,
67 @@ -1254,13 +1259,42 @@
71 + gdk_draw_text (block->pixmap,
72 + GTK_WIDGET(block)->style->font,
73 + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
78 gdk_draw_text (block->pixmap,
79 GTK_WIDGET(block)->style->font,
80 GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
84 strlen (block->sample->id));
86 + /* Draw Pitch Value */
88 + pitch_gs = g_string_sized_new(20);
90 + pitch_gs->len = g_snprintf(pitch_gs->str, 20, "%c%02d.%02d %%",
91 + block->pitch == 0 ? '0' : (block->pitch > 0 ? '+' : '-'),
92 + abs(block->pitch*10000 - 10000) / 100,
93 + abs(block->pitch*10000 - 10000) % 100);
95 + gdk_draw_text (block->pixmap,
96 + GTK_WIDGET(block)->style->font,
97 + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
102 + gdk_draw_text (block->pixmap,
103 + GTK_WIDGET(block)->style->font,
104 + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
109 /* Draw start time */
111 @@ -1281,14 +1315,14 @@
112 gdk_draw_text (block->pixmap,
113 GTK_WIDGET(block)->style->font,
114 GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
120 gdk_draw_text (block->pixmap,
121 GTK_WIDGET(block)->style->font,
122 GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
128 @@ -1313,14 +1347,14 @@
129 gdk_draw_text (block->pixmap,
130 GTK_WIDGET(block)->style->font,
131 GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
137 gdk_draw_text (block->pixmap,
138 GTK_WIDGET(block)->style->font,
139 GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
145 @@ -1481,6 +1515,73 @@
146 gtk_widget_draw (GTK_WIDGET (block), NULL);
149 +static void block_set_pitch (GtkWidget *widget, Block *block, gfloat newpitch) {
150 + block->pitch = newpitch;
151 + block->length = block->length_unpitched / newpitch;
152 + block_update (block);
153 + song_set_dirty (block->track->song, TRUE);
156 +static void block_dec_pitch_1 (GtkWidget *widget, Block *block)
157 + { block_set_pitch (widget, block, block->pitch - 0.0001); }
159 +static void block_dec_pitch_3 (GtkWidget *widget, Block *block)
160 + { block_set_pitch (widget, block, block->pitch - 0.0003); }
162 +static void block_dec_pitch_5 (GtkWidget *widget, Block *block)
163 + { block_set_pitch (widget, block, block->pitch - 0.0005); }
165 +static void block_dec_pitch_10 (GtkWidget *widget, Block *block)
166 + { block_set_pitch (widget, block, block->pitch - 0.0010); }
168 +static void block_dec_pitch_30 (GtkWidget *widget, Block *block)
169 + { block_set_pitch (widget, block, block->pitch - 0.0030); }
171 +static void block_dec_pitch_50 (GtkWidget *widget, Block *block)
172 + { block_set_pitch (widget, block, block->pitch - 0.0050); }
174 +static void block_dec_pitch_100 (GtkWidget *widget, Block *block)
175 + { block_set_pitch (widget, block, block->pitch - 0.0100); }
177 +static void block_dec_pitch_300 (GtkWidget *widget, Block *block)
178 + { block_set_pitch (widget, block, block->pitch - 0.0300); }
180 +static void block_dec_pitch_500 (GtkWidget *widget, Block *block)
181 + { block_set_pitch (widget, block, block->pitch - 0.0500); }
184 +static void block_pitch_reset (GtkWidget *widget, Block *block)
185 + { block_set_pitch (widget, block, 1); }
188 +static void block_inc_pitch_1 (GtkWidget *widget, Block *block)
189 + { block_set_pitch (widget, block, block->pitch + 0.0001); }
191 +static void block_inc_pitch_3 (GtkWidget *widget, Block *block)
192 + { block_set_pitch (widget, block, block->pitch + 0.0003); }
194 +static void block_inc_pitch_5 (GtkWidget *widget, Block *block)
195 + { block_set_pitch (widget, block, block->pitch + 0.0005); }
197 +static void block_inc_pitch_10 (GtkWidget *widget, Block *block)
198 + { block_set_pitch (widget, block, block->pitch + 0.0010); }
200 +static void block_inc_pitch_30 (GtkWidget *widget, Block *block)
201 + { block_set_pitch (widget, block, block->pitch + 0.0030); }
203 +static void block_inc_pitch_50 (GtkWidget *widget, Block *block)
204 + { block_set_pitch (widget, block, block->pitch + 0.0050); }
206 +static void block_inc_pitch_100 (GtkWidget *widget, Block *block)
207 + { block_set_pitch (widget, block, block->pitch + 0.0100); }
209 +static void block_inc_pitch_300 (GtkWidget *widget, Block *block)
210 + { block_set_pitch (widget, block, block->pitch + 0.0300); }
212 +static void block_inc_pitch_500 (GtkWidget *widget, Block *block)
213 + { block_set_pitch (widget, block, block->pitch + 0.0500); }
217 block_select_all (GtkWidget *widget, Block *block)
219 @@ -1534,6 +1635,26 @@
220 GNOMEUIINFO_SEPARATOR,
221 GNOMEUIINFO_ITEM_NONE (N_("Convert to loopblock"), N_("Convert to loopblock"), block_convert_to_loopblock),
222 GNOMEUIINFO_SEPARATOR,
223 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -5.00"), N_(""), block_dec_pitch_500),
224 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -3.00"), N_(""), block_dec_pitch_300),
225 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -1.00"), N_(""), block_dec_pitch_100),
226 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.50"), N_(""), block_dec_pitch_50),
227 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.30"), N_(""), block_dec_pitch_30),
228 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.10"), N_(""), block_dec_pitch_10),
229 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.05"), N_(""), block_dec_pitch_5),
230 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.03"), N_(""), block_dec_pitch_3),
231 + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.01"), N_(""), block_dec_pitch_1),
232 + GNOMEUIINFO_ITEM_NONE (N_("Reset Pitch"), N_(""), block_pitch_reset),
233 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.01"), N_(""), block_inc_pitch_1),
234 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.03"), N_(""), block_inc_pitch_3),
235 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.05"), N_(""), block_inc_pitch_5),
236 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.10"), N_(""), block_inc_pitch_10),
237 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.30"), N_(""), block_inc_pitch_30),
238 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.50"), N_(""), block_inc_pitch_50),
239 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +1.00"), N_(""), block_inc_pitch_100),
240 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +3.00"), N_(""), block_inc_pitch_300),
241 + GNOMEUIINFO_ITEM_NONE (N_("Pitch +5.00"), N_(""), block_inc_pitch_500),
242 + GNOMEUIINFO_SEPARATOR,
243 GNOMEUIINFO_ITEM_NONE (N_("Select all"), N_("Make the selection cover the whole block"), block_select_all),
246 @@ -1640,24 +1761,30 @@
247 mix_into_buffer (Block *block, gint16 *buffer, gint position, gint length)
251 + gint i, data_offset, data_xoffset;
253 - data = (gint16 *)(block->sample->data +
254 - (block->start + position - block->position) * block->sample->byte_p_spl);
256 - for (i = 0;i < length / (sizeof (guint16) * 2);i++) {
257 + data = (gint16 *)(block->sample->data +
258 + (block->start - block->position) *
259 + block->sample->byte_p_spl);
260 + data_offset = position;
262 + for (i = 0; i < length / (sizeof (guint16) * 2); i++) {
264 + data_xoffset = data_offset * block->pitch;
265 + data_xoffset *= block->sample->num_channels;
267 mixer_mix_sample_into_buffer (buffer,
269 + data + data_xoffset,
274 - position - block->position + i, block->sample->num_channels);
275 + position - block->position + i,
276 + block->sample->num_channels);
278 - data += block->sample->num_channels;
285 @@ -1675,8 +1813,11 @@
287 block->start = atoi ((ptr = xmlGetProp (node, "start")));
289 - block->length = atoi ((ptr = xmlGetProp (node, "length")));
290 + block->length_unpitched = atoi ((ptr = xmlGetProp (node, "length")));
292 + block->pitch = (float)atoi ((ptr = xmlGetProp (node, "pitch"))) / 10000;
294 + block->length = (float)block->length_unpitched * block->pitch;
295 block->position = atoi ((ptr = xmlGetProp (node, "position")));
297 ptr = xmlGetProp (node, "sample");
298 --- ./src/track.c.orig Tue Mar 12 06:39:42 2002
299 +++ ./src/track.c Mon Mar 11 20:53:32 2002
303 block->length = sample_get_length(block->sample);
304 + block->length_unpitched = sample_get_length(block->sample);
307 /* Position it on the same place as the popup menu */
308 block->position = (x + (gint)(GTK_LAYOUT (track->layout)->hadjustment->value)) * track->song->x_scale;
309 --- ./src/block.h.orig Mon Mar 11 20:47:57 2002
310 +++ ./src/block.h Mon Mar 11 20:37:16 2002
312 gint length; /* The length of this block */
313 gint position; /* Position in time */
315 + gfloat pitch; /* Pitch shifting (in %) */
316 + gint length_unpitched; /* The length before pitch is applied */
318 Sample *sample; /* The sample assosiated with this block */
320 GList *amp_env; /* Pointer to this blocks amplitude envelope or NULL */