summaryrefslogtreecommitdiff
path: root/apps/gui/pitchscreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/pitchscreen.c')
-rw-r--r--apps/gui/pitchscreen.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c
index b5b719ef02..a6e6e42c43 100644
--- a/apps/gui/pitchscreen.c
+++ b/apps/gui/pitchscreen.c
@@ -64,13 +64,13 @@ enum
64}; 64};
65 65
66 66
67/* This is a table of semitone percentage values of the appropriate 67/* This is a table of semitone percentage values of the appropriate
68 precision (based on PITCH_SPEED_PRECISION). Note that these are 68 precision (based on PITCH_SPEED_PRECISION). Note that these are
69 all constant expressions, which will be evaluated at compile time, 69 all constant expressions, which will be evaluated at compile time,
70 so no need to worry about how complex the expressions look. 70 so no need to worry about how complex the expressions look.
71 That's just to get the precision right. 71 That's just to get the precision right.
72 72
73 I calculated these values, starting from 50, as 73 I calculated these values, starting from 50, as
74 74
75 x(n) = 50 * 2^(n/12) 75 x(n) = 50 * 2^(n/12)
76 76
@@ -81,7 +81,7 @@ enum
81*/ 81*/
82#define TO_INT_WITH_PRECISION(x) \ 82#define TO_INT_WITH_PRECISION(x) \
83 ( (unsigned short)(((x) * PITCH_SPEED_PRECISION * 10 + 5) / 10) ) 83 ( (unsigned short)(((x) * PITCH_SPEED_PRECISION * 10 + 5) / 10) )
84 84
85static const unsigned short semitone_table[] = 85static const unsigned short semitone_table[] =
86{ 86{
87 TO_INT_WITH_PRECISION(50.00000000), /* Octave lower */ 87 TO_INT_WITH_PRECISION(50.00000000), /* Octave lower */
@@ -115,12 +115,12 @@ static const unsigned short semitone_table[] =
115#define SEMITONE_END (NUM_SEMITONES/2) 115#define SEMITONE_END (NUM_SEMITONES/2)
116#define SEMITONE_START (-SEMITONE_END) 116#define SEMITONE_START (-SEMITONE_END)
117 117
118/* A table of values for approximating the cent curve with 118/* A table of values for approximating the cent curve with
119 linear interpolation. Multipy the next lowest semitone 119 linear interpolation. Multipy the next lowest semitone
120 by this much to find the corresponding cent percentage. 120 by this much to find the corresponding cent percentage.
121 121
122 These values were calculated as 122 These values were calculated as
123 x(n) = 100 * 2^(n * 20/1200) 123 x(n) = 100 * 2^(n * 20/1200)
124*/ 124*/
125 125
126static const unsigned short cent_interp[] = 126static const unsigned short cent_interp[] =
@@ -308,16 +308,16 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
308 { 308 {
309 snprintf(buf, sizeof(buf), "%s: %s%d.%02d", str(LANG_PITCH), 309 snprintf(buf, sizeof(buf), "%s: %s%d.%02d", str(LANG_PITCH),
310 semitone >= 0 ? "+" : "-", 310 semitone >= 0 ? "+" : "-",
311 abs(semitone / PITCH_SPEED_PRECISION), 311 abs(semitone / PITCH_SPEED_PRECISION),
312 abs((semitone % PITCH_SPEED_PRECISION) / 312 abs((semitone % PITCH_SPEED_PRECISION) /
313 (PITCH_SPEED_PRECISION / 100)) 313 (PITCH_SPEED_PRECISION / 100))
314 ); 314 );
315 } 315 }
316 else 316 else
317 { 317 {
318 snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_PITCH), 318 snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_PITCH),
319 pitch / PITCH_SPEED_PRECISION, 319 pitch / PITCH_SPEED_PRECISION,
320 (pitch % PITCH_SPEED_PRECISION) / 320 (pitch % PITCH_SPEED_PRECISION) /
321 (PITCH_SPEED_PRECISION / 10)); 321 (PITCH_SPEED_PRECISION / 10));
322 } 322 }
323 } 323 }
@@ -337,8 +337,8 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
337 /* "Speed:XXX%" */ 337 /* "Speed:XXX%" */
338 if(global_settings.pitch_mode_timestretch) 338 if(global_settings.pitch_mode_timestretch)
339 { 339 {
340 snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_SPEED), 340 snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_SPEED),
341 speed / PITCH_SPEED_PRECISION, 341 speed / PITCH_SPEED_PRECISION,
342 (speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10)); 342 (speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
343 } 343 }
344 else 344 else
@@ -347,23 +347,23 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
347 { 347 {
348 snprintf(buf, sizeof(buf), "%s%d.%02d", 348 snprintf(buf, sizeof(buf), "%s%d.%02d",
349 semitone >= 0 ? "+" : "-", 349 semitone >= 0 ? "+" : "-",
350 abs(semitone / PITCH_SPEED_PRECISION), 350 abs(semitone / PITCH_SPEED_PRECISION),
351 abs((semitone % PITCH_SPEED_PRECISION) / 351 abs((semitone % PITCH_SPEED_PRECISION) /
352 (PITCH_SPEED_PRECISION / 100)) 352 (PITCH_SPEED_PRECISION / 100))
353 ); 353 );
354 } 354 }
355 else 355 else
356 { 356 {
357 snprintf(buf, sizeof(buf), "%ld.%ld%%", 357 snprintf(buf, sizeof(buf), "%ld.%ld%%",
358 pitch / PITCH_SPEED_PRECISION, 358 pitch / PITCH_SPEED_PRECISION,
359 (pitch % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10)); 359 (pitch % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
360 } 360 }
361 } 361 }
362 362
363 display->getstringsize(buf, &w, &h); 363 display->getstringsize(buf, &w, &h);
364 display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2), 364 display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2),
365 show_lang_pitch ? (pitch_viewports[PITCH_MID].height / 2) : 365 show_lang_pitch ? (pitch_viewports[PITCH_MID].height / 2) :
366 (pitch_viewports[PITCH_MID].height / 2) - (h / 2), 366 (pitch_viewports[PITCH_MID].height / 2) - (h / 2),
367 buf); 367 buf);
368 if (w > width_used) 368 if (w > width_used)
369 width_used = w; 369 width_used = w;
@@ -401,8 +401,8 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
401 { 401 {
402 display->putsxy(0, (pitch_viewports[PITCH_MID].height / 2) - (h / 2), 402 display->putsxy(0, (pitch_viewports[PITCH_MID].height / 2) - (h / 2),
403 leftlabel); 403 leftlabel);
404 display->putsxy((pitch_viewports[PITCH_MID].width - w), 404 display->putsxy((pitch_viewports[PITCH_MID].width - w),
405 (pitch_viewports[PITCH_MID].height / 2) - (h / 2), 405 (pitch_viewports[PITCH_MID].height / 2) - (h / 2),
406 rightlabel); 406 rightlabel);
407 } 407 }
408 display->update_viewport(); 408 display->update_viewport();
@@ -421,7 +421,7 @@ static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cut
421 if (pitch_delta < 0) 421 if (pitch_delta < 0)
422 { 422 {
423 /* for large jumps, snap up to whole numbers */ 423 /* for large jumps, snap up to whole numbers */
424 if(allow_cutoff && pitch_delta <= -PITCH_SPEED_PRECISION && 424 if(allow_cutoff && pitch_delta <= -PITCH_SPEED_PRECISION &&
425 (pitch + pitch_delta) % PITCH_SPEED_PRECISION != 0) 425 (pitch + pitch_delta) % PITCH_SPEED_PRECISION != 0)
426 { 426 {
427 pitch_delta += PITCH_SPEED_PRECISION - ((pitch + pitch_delta) % PITCH_SPEED_PRECISION); 427 pitch_delta += PITCH_SPEED_PRECISION - ((pitch + pitch_delta) % PITCH_SPEED_PRECISION);
@@ -442,7 +442,7 @@ static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cut
442 else if (pitch_delta > 0) 442 else if (pitch_delta > 0)
443 { 443 {
444 /* for large jumps, snap down to whole numbers */ 444 /* for large jumps, snap down to whole numbers */
445 if(allow_cutoff && pitch_delta >= PITCH_SPEED_PRECISION && 445 if(allow_cutoff && pitch_delta >= PITCH_SPEED_PRECISION &&
446 (pitch + pitch_delta) % PITCH_SPEED_PRECISION != 0) 446 (pitch + pitch_delta) % PITCH_SPEED_PRECISION != 0)
447 { 447 {
448 pitch_delta -= (pitch + pitch_delta) % PITCH_SPEED_PRECISION; 448 pitch_delta -= (pitch + pitch_delta) % PITCH_SPEED_PRECISION;
@@ -480,7 +480,7 @@ static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cut
480 new_pitch = GET_PITCH(speed, STRETCH_MAX); 480 new_pitch = GET_PITCH(speed, STRETCH_MAX);
481 } 481 }
482 482
483 if(new_stretch >= STRETCH_MAX || 483 if(new_stretch >= STRETCH_MAX ||
484 new_stretch <= STRETCH_MIN) 484 new_stretch <= STRETCH_MIN)
485 { 485 {
486 at_limit = true; 486 at_limit = true;
@@ -505,7 +505,7 @@ static int32_t get_semitone_from_pitch(int32_t pitch)
505 505
506 506
507 /* now find the fractional part */ 507 /* now find the fractional part */
508 while(pitch > (cent_interp[fractional_index + 1] * 508 while(pitch > (cent_interp[fractional_index + 1] *
509 semitone_table[semitone] / PITCH_SPEED_100)) 509 semitone_table[semitone] / PITCH_SPEED_100))
510 { 510 {
511 /* Check to make sure fractional_index isn't too big */ 511 /* Check to make sure fractional_index isn't too big */
@@ -517,17 +517,17 @@ static int32_t get_semitone_from_pitch(int32_t pitch)
517 fractional_index++; 517 fractional_index++;
518 } 518 }
519 519
520 int32_t semitone_pitch_a = cent_interp[fractional_index] * 520 int32_t semitone_pitch_a = cent_interp[fractional_index] *
521 semitone_table[semitone] / 521 semitone_table[semitone] /
522 PITCH_SPEED_100; 522 PITCH_SPEED_100;
523 int32_t semitone_pitch_b = cent_interp[fractional_index + 1] * 523 int32_t semitone_pitch_b = cent_interp[fractional_index + 1] *
524 semitone_table[semitone] / 524 semitone_table[semitone] /
525 PITCH_SPEED_100; 525 PITCH_SPEED_100;
526 /* this will be the integer offset from the cent_interp entry */ 526 /* this will be the integer offset from the cent_interp entry */
527 int32_t semitone_frac_ofs = (pitch - semitone_pitch_a) * CENT_INTERP_INTERVAL / 527 int32_t semitone_frac_ofs = (pitch - semitone_pitch_a) * CENT_INTERP_INTERVAL /
528 (semitone_pitch_b - semitone_pitch_a); 528 (semitone_pitch_b - semitone_pitch_a);
529 semitone = (semitone + SEMITONE_START) * PITCH_SPEED_PRECISION + 529 semitone = (semitone + SEMITONE_START) * PITCH_SPEED_PRECISION +
530 fractional_index * CENT_INTERP_INTERVAL + 530 fractional_index * CENT_INTERP_INTERVAL +
531 semitone_frac_ofs; 531 semitone_frac_ofs;
532 532
533 return semitone; 533 return semitone;
@@ -543,14 +543,14 @@ static int32_t get_pitch_from_semitone(int32_t semitone)
543 /* set pitch to the semitone's integer part value */ 543 /* set pitch to the semitone's integer part value */
544 int32_t pitch = semitone_table[semitone_index]; 544 int32_t pitch = semitone_table[semitone_index];
545 /* get the range of the cent modification for future calculation */ 545 /* get the range of the cent modification for future calculation */
546 int32_t pitch_mod_a = 546 int32_t pitch_mod_a =
547 cent_interp[(adjusted_semitone % PITCH_SPEED_PRECISION) / 547 cent_interp[(adjusted_semitone % PITCH_SPEED_PRECISION) /
548 CENT_INTERP_INTERVAL]; 548 CENT_INTERP_INTERVAL];
549 int32_t pitch_mod_b = 549 int32_t pitch_mod_b =
550 cent_interp[(adjusted_semitone % PITCH_SPEED_PRECISION) / 550 cent_interp[(adjusted_semitone % PITCH_SPEED_PRECISION) /
551 CENT_INTERP_INTERVAL + 1]; 551 CENT_INTERP_INTERVAL + 1];
552 /* figure out the cent mod amount based on the semitone fractional value */ 552 /* figure out the cent mod amount based on the semitone fractional value */
553 int32_t pitch_mod = pitch_mod_a + (pitch_mod_b - pitch_mod_a) * 553 int32_t pitch_mod = pitch_mod_a + (pitch_mod_b - pitch_mod_a) *
554 (adjusted_semitone % CENT_INTERP_INTERVAL) / CENT_INTERP_INTERVAL; 554 (adjusted_semitone % CENT_INTERP_INTERVAL) / CENT_INTERP_INTERVAL;
555 555
556 /* modify pitch based on the mod amount we just calculated */ 556 /* modify pitch based on the mod amount we just calculated */
@@ -558,7 +558,7 @@ static int32_t get_pitch_from_semitone(int32_t semitone)
558} 558}
559 559
560static int32_t pitch_increase_semitone(int32_t pitch, 560static int32_t pitch_increase_semitone(int32_t pitch,
561 int32_t current_semitone, 561 int32_t current_semitone,
562 int32_t semitone_delta 562 int32_t semitone_delta
563 , int32_t speed 563 , int32_t speed
564 ) 564 )
@@ -618,7 +618,7 @@ static int32_t pitch_increase_semitone(int32_t pitch,
618#ifdef HAVE_TOUCHSCREEN 618#ifdef HAVE_TOUCHSCREEN
619/* 619/*
620 * Check for touchscreen presses as per sketch above in this file 620 * Check for touchscreen presses as per sketch above in this file
621 * 621 *
622 * goes through each row of the, checks whether the touchscreen 622 * goes through each row of the, checks whether the touchscreen
623 * was pressed in it. Then it looks the columns of each row for specific actions 623 * was pressed in it. Then it looks the columns of each row for specific actions
624 */ 624 */
@@ -638,7 +638,7 @@ static int pitchscreen_do_touchscreen(struct viewport vps[])
638 if ((x < column || x > (2*column)) && (ret == BUTTON_REL)) 638 if ((x < column || x > (2*column)) && (ret == BUTTON_REL))
639 return ACTION_PS_TOGGLE_MODE; 639 return ACTION_PS_TOGGLE_MODE;
640 640
641 641
642 else if (x >= column && x <= (2*column)) 642 else if (x >= column && x <= (2*column))
643 { /* center column pressed */ 643 { /* center column pressed */
644 if (ret == BUTTON_REPEAT) 644 if (ret == BUTTON_REPEAT)
@@ -828,7 +828,7 @@ int gui_syncpitchscreen_run(void)
828 updated = 0; 828 updated = 0;
829 829
830 button = get_action(CONTEXT_PITCHSCREEN, HZ); 830 button = get_action(CONTEXT_PITCHSCREEN, HZ);
831 831
832#ifdef HAVE_TOUCHSCREEN 832#ifdef HAVE_TOUCHSCREEN
833 if (button == ACTION_TOUCHSCREEN) 833 if (button == ACTION_TOUCHSCREEN)
834 { 834 {
@@ -841,7 +841,7 @@ int gui_syncpitchscreen_run(void)
841 case ACTION_PS_INC_SMALL: 841 case ACTION_PS_INC_SMALL:
842 if(global_settings.pitch_mode_semitone) 842 if(global_settings.pitch_mode_semitone)
843 pitch_delta = SEMITONE_SMALL_DELTA; 843 pitch_delta = SEMITONE_SMALL_DELTA;
844 else 844 else
845 pitch_delta = PITCH_SMALL_DELTA; 845 pitch_delta = PITCH_SMALL_DELTA;
846 updated = 1; 846 updated = 1;
847 break; 847 break;
@@ -849,7 +849,7 @@ int gui_syncpitchscreen_run(void)
849 case ACTION_PS_INC_BIG: 849 case ACTION_PS_INC_BIG:
850 if(global_settings.pitch_mode_semitone) 850 if(global_settings.pitch_mode_semitone)
851 pitch_delta = SEMITONE_BIG_DELTA; 851 pitch_delta = SEMITONE_BIG_DELTA;
852 else 852 else
853 pitch_delta = PITCH_BIG_DELTA; 853 pitch_delta = PITCH_BIG_DELTA;
854 updated = 1; 854 updated = 1;
855 break; 855 break;
@@ -857,7 +857,7 @@ int gui_syncpitchscreen_run(void)
857 case ACTION_PS_DEC_SMALL: 857 case ACTION_PS_DEC_SMALL:
858 if(global_settings.pitch_mode_semitone) 858 if(global_settings.pitch_mode_semitone)
859 pitch_delta = -SEMITONE_SMALL_DELTA; 859 pitch_delta = -SEMITONE_SMALL_DELTA;
860 else 860 else
861 pitch_delta = -PITCH_SMALL_DELTA; 861 pitch_delta = -PITCH_SMALL_DELTA;
862 updated = 1; 862 updated = 1;
863 break; 863 break;
@@ -865,7 +865,7 @@ int gui_syncpitchscreen_run(void)
865 case ACTION_PS_DEC_BIG: 865 case ACTION_PS_DEC_BIG:
866 if(global_settings.pitch_mode_semitone) 866 if(global_settings.pitch_mode_semitone)
867 pitch_delta = -SEMITONE_BIG_DELTA; 867 pitch_delta = -SEMITONE_BIG_DELTA;
868 else 868 else
869 pitch_delta = -PITCH_BIG_DELTA; 869 pitch_delta = -PITCH_BIG_DELTA;
870 updated = 1; 870 updated = 1;
871 break; 871 break;
@@ -1045,7 +1045,7 @@ int gui_syncpitchscreen_run(void)
1045 } 1045 }
1046 1046
1047 new_stretch = GET_STRETCH(pitch, new_speed); 1047 new_stretch = GET_STRETCH(pitch, new_speed);
1048 if(new_stretch >= STRETCH_MAX || 1048 if(new_stretch >= STRETCH_MAX ||
1049 new_stretch <= STRETCH_MIN) 1049 new_stretch <= STRETCH_MIN)
1050 { 1050 {
1051 at_limit = true; 1051 at_limit = true;