OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

320 lines
11 KiB

  1. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # T2 SDE: package/.../mixmagic/pitch.patch
  5. # Copyright (C) 2004 - 2006 The T2 SDE Project
  6. # Copyright (C) 1998 - 2003 Clifford Wolf
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  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
  15. # version.
  16. # --- T2-COPYRIGHT-NOTE-END ---
  17. This patch adds pitch shifting to mixmagic. (by Clifford)
  18. --- ./src/block.c.orig Sat Mar 9 11:06:32 2002
  19. +++ ./src/block.c Mon May 13 20:16:56 2002
  20. @@ -834,6 +834,7 @@
  21. b->start = block->start + MIN (block->selection_start, block->selection_end);
  22. b->length = ABS (block->selection_start - block->selection_end);
  23. + block->length_unpitched = block->length * block->pitch;
  24. b->sample = sample_ref (block->sample);
  25. b->position = block->position + MIN (block->selection_start, block->selection_end);
  26. @@ -1143,6 +1144,8 @@
  27. newBlock->sample = sample_ref (block->sample);
  28. newBlock->start = block->start;
  29. newBlock->length = block->length;
  30. + newBlock->length_unpitched = block->length_unpitched;
  31. + newBlock->pitch = block->pitch;
  32. /* Position it on the same place as the popup menu */
  33. newBlock->position = block->position;
  34. @@ -1183,8 +1186,8 @@
  35. block_draw (Block *block)
  36. {
  37. gint i, width, height;
  38. - gint offset, value;
  39. - GString * start_gs , * len_gs ;
  40. + gint offset, offset_start, value;
  41. + GString * start_gs , * len_gs , * pitch_gs;
  42. g_assert (IS_BLOCK(block));
  43. @@ -1210,11 +1213,13 @@
  44. width,
  45. height);
  46. - offset = block->start / INDEX_RATIO;
  47. + offset_start = block->start / INDEX_RATIO;
  48. + offset = 0;
  49. for (i = 0; i < width;i++) {
  50. value = index_get_average (block->sample->index,
  51. - offset, block->start / INDEX_RATIO,
  52. + offset_start + offset * block->pitch,
  53. + block->start / INDEX_RATIO,
  54. block->track->song->x_scale / INDEX_RATIO,
  55. block->sample->length / INDEX_RATIO / 2) / ((float)0x7f / height);
  56. gdk_draw_line (block->pixmap,
  57. @@ -1254,13 +1259,42 @@
  58. /* Draw title */
  59. + gdk_draw_text (block->pixmap,
  60. + GTK_WIDGET(block)->style->font,
  61. + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  62. + 10, 15,
  63. + "F:",
  64. + 2);
  65. +
  66. gdk_draw_text (block->pixmap,
  67. GTK_WIDGET(block)->style->font,
  68. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  69. - 0, 10,
  70. + 25, 15,
  71. block->sample->id,
  72. strlen (block->sample->id));
  73. + /* Draw Pitch Value */
  74. +
  75. + pitch_gs = g_string_sized_new(20);
  76. +
  77. + pitch_gs->len = g_snprintf(pitch_gs->str, 20, "%c%02d.%02d %%",
  78. + block->pitch == 0 ? '0' : (block->pitch > 0 ? '+' : '-'),
  79. + abs(block->pitch*10000 - 10000) / 100,
  80. + abs(block->pitch*10000 - 10000) % 100);
  81. +
  82. + gdk_draw_text (block->pixmap,
  83. + GTK_WIDGET(block)->style->font,
  84. + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  85. + 10, 30,
  86. + "P:",
  87. + 2);
  88. +
  89. + gdk_draw_text (block->pixmap,
  90. + GTK_WIDGET(block)->style->font,
  91. + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  92. + 25, 30,
  93. + pitch_gs->str,
  94. + pitch_gs->len);
  95. /* Draw start time */
  96. @@ -1281,14 +1315,14 @@
  97. gdk_draw_text (block->pixmap,
  98. GTK_WIDGET(block)->style->font,
  99. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  100. - 0, height - 20,
  101. + 10, height - 20,
  102. "S:",
  103. 2);
  104. gdk_draw_text (block->pixmap,
  105. GTK_WIDGET(block)->style->font,
  106. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  107. - 15, height - 20,
  108. + 25, height - 20,
  109. start_gs->str,
  110. start_gs->len);
  111. @@ -1313,14 +1347,14 @@
  112. gdk_draw_text (block->pixmap,
  113. GTK_WIDGET(block)->style->font,
  114. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  115. - 0, height - 5,
  116. + 10, height - 5,
  117. "L:",
  118. 2);
  119. gdk_draw_text (block->pixmap,
  120. GTK_WIDGET(block)->style->font,
  121. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  122. - 15, height - 5,
  123. + 25, height - 5,
  124. len_gs->str,
  125. len_gs->len);
  126. @@ -1481,6 +1515,73 @@
  127. gtk_widget_draw (GTK_WIDGET (block), NULL);
  128. }
  129. +static void block_set_pitch (GtkWidget *widget, Block *block, gfloat newpitch) {
  130. + block->pitch = newpitch;
  131. + block->length = block->length_unpitched / newpitch;
  132. + block_update (block);
  133. + song_set_dirty (block->track->song, TRUE);
  134. +}
  135. +
  136. +static void block_dec_pitch_1 (GtkWidget *widget, Block *block)
  137. + { block_set_pitch (widget, block, block->pitch - 0.0001); }
  138. +
  139. +static void block_dec_pitch_3 (GtkWidget *widget, Block *block)
  140. + { block_set_pitch (widget, block, block->pitch - 0.0003); }
  141. +
  142. +static void block_dec_pitch_5 (GtkWidget *widget, Block *block)
  143. + { block_set_pitch (widget, block, block->pitch - 0.0005); }
  144. +
  145. +static void block_dec_pitch_10 (GtkWidget *widget, Block *block)
  146. + { block_set_pitch (widget, block, block->pitch - 0.0010); }
  147. +
  148. +static void block_dec_pitch_30 (GtkWidget *widget, Block *block)
  149. + { block_set_pitch (widget, block, block->pitch - 0.0030); }
  150. +
  151. +static void block_dec_pitch_50 (GtkWidget *widget, Block *block)
  152. + { block_set_pitch (widget, block, block->pitch - 0.0050); }
  153. +
  154. +static void block_dec_pitch_100 (GtkWidget *widget, Block *block)
  155. + { block_set_pitch (widget, block, block->pitch - 0.0100); }
  156. +
  157. +static void block_dec_pitch_300 (GtkWidget *widget, Block *block)
  158. + { block_set_pitch (widget, block, block->pitch - 0.0300); }
  159. +
  160. +static void block_dec_pitch_500 (GtkWidget *widget, Block *block)
  161. + { block_set_pitch (widget, block, block->pitch - 0.0500); }
  162. +
  163. +
  164. +static void block_pitch_reset (GtkWidget *widget, Block *block)
  165. + { block_set_pitch (widget, block, 1); }
  166. +
  167. +
  168. +static void block_inc_pitch_1 (GtkWidget *widget, Block *block)
  169. + { block_set_pitch (widget, block, block->pitch + 0.0001); }
  170. +
  171. +static void block_inc_pitch_3 (GtkWidget *widget, Block *block)
  172. + { block_set_pitch (widget, block, block->pitch + 0.0003); }
  173. +
  174. +static void block_inc_pitch_5 (GtkWidget *widget, Block *block)
  175. + { block_set_pitch (widget, block, block->pitch + 0.0005); }
  176. +
  177. +static void block_inc_pitch_10 (GtkWidget *widget, Block *block)
  178. + { block_set_pitch (widget, block, block->pitch + 0.0010); }
  179. +
  180. +static void block_inc_pitch_30 (GtkWidget *widget, Block *block)
  181. + { block_set_pitch (widget, block, block->pitch + 0.0030); }
  182. +
  183. +static void block_inc_pitch_50 (GtkWidget *widget, Block *block)
  184. + { block_set_pitch (widget, block, block->pitch + 0.0050); }
  185. +
  186. +static void block_inc_pitch_100 (GtkWidget *widget, Block *block)
  187. + { block_set_pitch (widget, block, block->pitch + 0.0100); }
  188. +
  189. +static void block_inc_pitch_300 (GtkWidget *widget, Block *block)
  190. + { block_set_pitch (widget, block, block->pitch + 0.0300); }
  191. +
  192. +static void block_inc_pitch_500 (GtkWidget *widget, Block *block)
  193. + { block_set_pitch (widget, block, block->pitch + 0.0500); }
  194. +
  195. +
  196. static void
  197. block_select_all (GtkWidget *widget, Block *block)
  198. {
  199. @@ -1534,6 +1635,26 @@
  200. GNOMEUIINFO_SEPARATOR,
  201. GNOMEUIINFO_ITEM_NONE (N_("Convert to loopblock"), N_("Convert to loopblock"), block_convert_to_loopblock),
  202. GNOMEUIINFO_SEPARATOR,
  203. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -5.00"), N_(""), block_dec_pitch_500),
  204. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -3.00"), N_(""), block_dec_pitch_300),
  205. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -1.00"), N_(""), block_dec_pitch_100),
  206. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.50"), N_(""), block_dec_pitch_50),
  207. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.30"), N_(""), block_dec_pitch_30),
  208. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.10"), N_(""), block_dec_pitch_10),
  209. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.05"), N_(""), block_dec_pitch_5),
  210. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.03"), N_(""), block_dec_pitch_3),
  211. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.01"), N_(""), block_dec_pitch_1),
  212. + GNOMEUIINFO_ITEM_NONE (N_("Reset Pitch"), N_(""), block_pitch_reset),
  213. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.01"), N_(""), block_inc_pitch_1),
  214. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.03"), N_(""), block_inc_pitch_3),
  215. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.05"), N_(""), block_inc_pitch_5),
  216. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.10"), N_(""), block_inc_pitch_10),
  217. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.30"), N_(""), block_inc_pitch_30),
  218. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.50"), N_(""), block_inc_pitch_50),
  219. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +1.00"), N_(""), block_inc_pitch_100),
  220. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +3.00"), N_(""), block_inc_pitch_300),
  221. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +5.00"), N_(""), block_inc_pitch_500),
  222. + GNOMEUIINFO_SEPARATOR,
  223. GNOMEUIINFO_ITEM_NONE (N_("Select all"), N_("Make the selection cover the whole block"), block_select_all),
  224. GNOMEUIINFO_END
  225. };
  226. @@ -1640,24 +1761,30 @@
  227. mix_into_buffer (Block *block, gint16 *buffer, gint position, gint length)
  228. {
  229. gint16 *data;
  230. - gint i;
  231. + gint i, data_offset, data_xoffset;
  232. - data = (gint16 *)(block->sample->data +
  233. - (block->start + position - block->position) * block->sample->byte_p_spl);
  234. -
  235. - for (i = 0;i < length / (sizeof (guint16) * 2);i++) {
  236. + data = (gint16 *)(block->sample->data +
  237. + (block->start - block->position) *
  238. + block->sample->byte_p_spl);
  239. + data_offset = position;
  240. +
  241. + for (i = 0; i < length / (sizeof (guint16) * 2); i++) {
  242. +
  243. + data_xoffset = data_offset * block->pitch;
  244. + data_xoffset *= block->sample->num_channels;
  245. mixer_mix_sample_into_buffer (buffer,
  246. - data,
  247. + data + data_xoffset,
  248. block->amp_env,
  249. block->pan_env,
  250. block->track->amp,
  251. block->track->pan,
  252. - position - block->position + i, block->sample->num_channels);
  253. + position - block->position + i,
  254. + block->sample->num_channels);
  255. - data += block->sample->num_channels;
  256. + data_offset++;
  257. buffer += 2;
  258. }
  259. }
  260. /*
  261. @@ -1675,8 +1813,11 @@
  262. block->start = atoi ((ptr = xmlGetProp (node, "start")));
  263. g_free (ptr);
  264. - block->length = atoi ((ptr = xmlGetProp (node, "length")));
  265. + block->length_unpitched = atoi ((ptr = xmlGetProp (node, "length")));
  266. g_free (ptr);
  267. + block->pitch = (float)atoi ((ptr = xmlGetProp (node, "pitch"))) / 10000;
  268. + g_free (ptr);
  269. + block->length = (float)block->length_unpitched * block->pitch;
  270. block->position = atoi ((ptr = xmlGetProp (node, "position")));
  271. g_free (ptr);
  272. ptr = xmlGetProp (node, "sample");
  273. --- ./src/track.c.orig Tue Mar 12 06:39:42 2002
  274. +++ ./src/track.c Mon Mar 11 20:53:32 2002
  275. @@ -328,6 +328,8 @@
  276. block->start = 0;
  277. block->length = sample_get_length(block->sample);
  278. + block->length_unpitched = sample_get_length(block->sample);
  279. + block->pitch=1;
  280. /* Position it on the same place as the popup menu */
  281. block->position = (x + (gint)(GTK_LAYOUT (track->layout)->hadjustment->value)) * track->song->x_scale;
  282. --- ./src/block.h.orig Mon Mar 11 20:47:57 2002
  283. +++ ./src/block.h Mon Mar 11 20:37:16 2002
  284. @@ -89,6 +89,9 @@
  285. gint length; /* The length of this block */
  286. gint position; /* Position in time */
  287. + gfloat pitch; /* Pitch shifting (in %) */
  288. + gint length_unpitched; /* The length before pitch is applied */
  289. +
  290. Sample *sample; /* The sample assosiated with this block */
  291. GList *amp_env; /* Pointer to this blocks amplitude envelope or NULL */