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.c78
1 files changed, 0 insertions, 78 deletions
diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c
index bf016fdd5f..0d31193fa6 100644
--- a/apps/gui/pitchscreen.c
+++ b/apps/gui/pitchscreen.c
@@ -38,9 +38,7 @@
38#include "misc.h" 38#include "misc.h"
39#include "pitchscreen.h" 39#include "pitchscreen.h"
40#include "settings.h" 40#include "settings.h"
41#if CONFIG_CODEC == SWCODEC
42#include "tdspeed.h" 41#include "tdspeed.h"
43#endif
44 42
45#define ICON_BORDER 12 /* icons are currently 7x8, so add ~2 pixels */ 43#define ICON_BORDER 12 /* icons are currently 7x8, so add ~2 pixels */
46 /* on both sides when drawing */ 44 /* on both sides when drawing */
@@ -167,13 +165,9 @@ static bool at_limit = false;
167 165
168static void speak_pitch_mode(bool enqueue) 166static void speak_pitch_mode(bool enqueue)
169{ 167{
170#if CONFIG_CODEC == SWCODEC
171 bool timestretch_mode = global_settings.pitch_mode_timestretch && dsp_timestretch_available(); 168 bool timestretch_mode = global_settings.pitch_mode_timestretch && dsp_timestretch_available();
172 if (timestretch_mode) 169 if (timestretch_mode)
173 talk_id(VOICE_PITCH_TIMESTRETCH_MODE, enqueue); 170 talk_id(VOICE_PITCH_TIMESTRETCH_MODE, enqueue);
174#else
175#define timestretch_mode 0
176#endif
177 if (global_settings.pitch_mode_semitone) 171 if (global_settings.pitch_mode_semitone)
178 talk_id(VOICE_PITCH_SEMITONE_MODE, timestretch_mode ? true : enqueue); 172 talk_id(VOICE_PITCH_SEMITONE_MODE, timestretch_mode ? true : enqueue);
179 else 173 else
@@ -238,9 +232,7 @@ static void pitchscreen_draw_icons(struct screen *display,
238static void pitchscreen_draw(struct screen *display, int max_lines, 232static void pitchscreen_draw(struct screen *display, int max_lines,
239 struct viewport pitch_viewports[PITCH_ITEM_COUNT], 233 struct viewport pitch_viewports[PITCH_ITEM_COUNT],
240 int32_t pitch, int32_t semitone 234 int32_t pitch, int32_t semitone
241#if CONFIG_CODEC == SWCODEC
242 ,int32_t speed 235 ,int32_t speed
243#endif
244 ) 236 )
245{ 237{
246 const char* ptr; 238 const char* ptr;
@@ -308,7 +300,6 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
308 /* Middle section upper line - hide for a small screen */ 300 /* Middle section upper line - hide for a small screen */
309 if ((show_lang_pitch = (max_lines >= 3))) 301 if ((show_lang_pitch = (max_lines >= 3)))
310 { 302 {
311#if CONFIG_CODEC == SWCODEC
312 if(global_settings.pitch_mode_timestretch) 303 if(global_settings.pitch_mode_timestretch)
313 { 304 {
314 /* Pitch:XXX.X% */ 305 /* Pitch:XXX.X% */
@@ -330,7 +321,6 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
330 } 321 }
331 } 322 }
332 else 323 else
333#endif
334 { 324 {
335 /* Rate */ 325 /* Rate */
336 snprintf(buf, sizeof(buf), "%s:", str(LANG_PLAYBACK_RATE)); 326 snprintf(buf, sizeof(buf), "%s:", str(LANG_PLAYBACK_RATE));
@@ -344,7 +334,6 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
344 334
345 /* Middle section lower line */ 335 /* Middle section lower line */
346 /* "Speed:XXX%" */ 336 /* "Speed:XXX%" */
347#if CONFIG_CODEC == SWCODEC
348 if(global_settings.pitch_mode_timestretch) 337 if(global_settings.pitch_mode_timestretch)
349 { 338 {
350 snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_SPEED), 339 snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_SPEED),
@@ -352,7 +341,6 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
352 (speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10)); 341 (speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
353 } 342 }
354 else 343 else
355#endif
356 { 344 {
357 if(global_settings.pitch_mode_semitone) 345 if(global_settings.pitch_mode_semitone)
358 { 346 {
@@ -396,13 +384,11 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
396 /* Middle section left/right labels */ 384 /* Middle section left/right labels */
397 const char *leftlabel = "-2%"; 385 const char *leftlabel = "-2%";
398 const char *rightlabel = "+2%"; 386 const char *rightlabel = "+2%";
399#if CONFIG_CODEC == SWCODEC
400 if (global_settings.pitch_mode_timestretch) 387 if (global_settings.pitch_mode_timestretch)
401 { 388 {
402 leftlabel = "<<"; 389 leftlabel = "<<";
403 rightlabel = ">>"; 390 rightlabel = ">>";
404 } 391 }
405#endif
406 392
407 /* Only display if they fit */ 393 /* Only display if they fit */
408 display->getstringsize(leftlabel, &w, &h); 394 display->getstringsize(leftlabel, &w, &h);
@@ -423,16 +409,12 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
423} 409}
424 410
425static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cutoff 411static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cutoff
426#if CONFIG_CODEC == SWCODEC
427 /* need this to maintain correct pitch/speed caps */ 412 /* need this to maintain correct pitch/speed caps */
428 , int32_t speed 413 , int32_t speed
429#endif
430 ) 414 )
431{ 415{
432 int32_t new_pitch; 416 int32_t new_pitch;
433#if CONFIG_CODEC == SWCODEC
434 int32_t new_stretch; 417 int32_t new_stretch;
435#endif
436 at_limit = false; 418 at_limit = false;
437 419
438 if (pitch_delta < 0) 420 if (pitch_delta < 0)
@@ -480,7 +462,6 @@ static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cut
480 /* pitch_delta == 0 -> no real change */ 462 /* pitch_delta == 0 -> no real change */
481 return pitch; 463 return pitch;
482 } 464 }
483#if CONFIG_CODEC == SWCODEC
484 if (dsp_timestretch_available()) 465 if (dsp_timestretch_available())
485 { 466 {
486 /* increase the multiple to increase precision of this calculation */ 467 /* increase the multiple to increase precision of this calculation */
@@ -504,7 +485,6 @@ static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cut
504 at_limit = true; 485 at_limit = true;
505 } 486 }
506 } 487 }
507#endif
508 488
509 sound_set_pitch(new_pitch); 489 sound_set_pitch(new_pitch);
510 490
@@ -579,9 +559,7 @@ static int32_t get_pitch_from_semitone(int32_t semitone)
579static int32_t pitch_increase_semitone(int32_t pitch, 559static int32_t pitch_increase_semitone(int32_t pitch,
580 int32_t current_semitone, 560 int32_t current_semitone,
581 int32_t semitone_delta 561 int32_t semitone_delta
582#if CONFIG_CODEC == SWCODEC
583 , int32_t speed 562 , int32_t speed
584#endif
585 ) 563 )
586{ 564{
587 int32_t new_semitone = current_semitone; 565 int32_t new_semitone = current_semitone;
@@ -613,7 +591,6 @@ static int32_t pitch_increase_semitone(int32_t pitch,
613 591
614 int32_t new_pitch = get_pitch_from_semitone(new_semitone); 592 int32_t new_pitch = get_pitch_from_semitone(new_semitone);
615 593
616#if CONFIG_CODEC == SWCODEC
617 int32_t new_stretch = GET_STRETCH(new_pitch, speed); 594 int32_t new_stretch = GET_STRETCH(new_pitch, speed);
618 595
619 /* clamp the pitch so it doesn't go beyond the stretch limits */ 596 /* clamp the pitch so it doesn't go beyond the stretch limits */
@@ -629,12 +606,9 @@ static int32_t pitch_increase_semitone(int32_t pitch,
629 new_semitone = get_semitone_from_pitch(new_pitch); 606 new_semitone = get_semitone_from_pitch(new_pitch);
630 at_limit = true; 607 at_limit = true;
631 } 608 }
632#endif
633 609
634 pitch_increase(pitch, new_pitch - pitch, false 610 pitch_increase(pitch, new_pitch - pitch, false
635#if CONFIG_CODEC == SWCODEC
636 , speed 611 , speed
637#endif
638 ); 612 );
639 613
640 return new_semitone; 614 return new_semitone;
@@ -765,7 +739,6 @@ int gui_syncpitchscreen_run(void)
765 739
766 push_current_activity(ACTIVITY_PITCHSCREEN); 740 push_current_activity(ACTIVITY_PITCHSCREEN);
767 741
768#if CONFIG_CODEC == SWCODEC
769 int32_t new_speed = 0, new_stretch; 742 int32_t new_speed = 0, new_stretch;
770 743
771 /* the speed variable holds the apparent speed of the playback */ 744 /* the speed variable holds the apparent speed of the playback */
@@ -785,7 +758,6 @@ int gui_syncpitchscreen_run(void)
785 global_settings.pitch_mode_timestretch = false; 758 global_settings.pitch_mode_timestretch = false;
786 settings_save(); 759 settings_save();
787 } 760 }
788#endif
789 761
790 /* Count decimals for speaking */ 762 /* Count decimals for speaking */
791 for (i = PITCH_SPEED_PRECISION; i >= 10; i /= 10) 763 for (i = PITCH_SPEED_PRECISION; i >= 10; i /= 10)
@@ -806,23 +778,17 @@ int gui_syncpitchscreen_run(void)
806 /* also, draw the icons now, it's only needed once */ 778 /* also, draw the icons now, it's only needed once */
807 pitchscreen_draw_icons(&screens[i], &parent[i]); 779 pitchscreen_draw_icons(&screens[i], &parent[i]);
808 } 780 }
809#if CONFIG_CODEC == SWCODEC
810 pcmbuf_set_low_latency(true); 781 pcmbuf_set_low_latency(true);
811#endif
812 782
813 while (!exit) 783 while (!exit)
814 { 784 {
815 FOR_NB_SCREENS(i) 785 FOR_NB_SCREENS(i)
816 pitchscreen_draw(&screens[i], max_lines[i], 786 pitchscreen_draw(&screens[i], max_lines[i],
817 pitch_viewports[i], pitch, semitone 787 pitch_viewports[i], pitch, semitone
818#if CONFIG_CODEC == SWCODEC
819 , speed 788 , speed
820#endif
821 ); 789 );
822 pitch_delta = 0; 790 pitch_delta = 0;
823#if CONFIG_CODEC == SWCODEC
824 new_speed = 0; 791 new_speed = 0;
825#endif
826 792
827 if (global_settings.talk_menu && updated) 793 if (global_settings.talk_menu && updated)
828 { 794 {
@@ -835,29 +801,23 @@ int gui_syncpitchscreen_run(void)
835 else 801 else
836 talk_value_decimal(pitch, UNIT_PERCENT, decimals, false); 802 talk_value_decimal(pitch, UNIT_PERCENT, decimals, false);
837 break; 803 break;
838#if CONFIG_CODEC == SWCODEC
839 case 2: 804 case 2:
840 talk_value_decimal(speed, UNIT_PERCENT, decimals, false); 805 talk_value_decimal(speed, UNIT_PERCENT, decimals, false);
841 break; 806 break;
842#endif
843 case 3: 807 case 3:
844 speak_pitch_mode(false); 808 speak_pitch_mode(false);
845 break; 809 break;
846 case 4: 810 case 4:
847#if CONFIG_CODEC == SWCODEC
848 if (global_settings.pitch_mode_timestretch && dsp_timestretch_available()) 811 if (global_settings.pitch_mode_timestretch && dsp_timestretch_available())
849 talk_id(LANG_PITCH, false); 812 talk_id(LANG_PITCH, false);
850 else 813 else
851#endif
852 talk_id(LANG_PLAYBACK_RATE, false); 814 talk_id(LANG_PLAYBACK_RATE, false);
853 talk_value_decimal(pitch, UNIT_PERCENT, decimals, true); 815 talk_value_decimal(pitch, UNIT_PERCENT, decimals, true);
854#if CONFIG_CODEC == SWCODEC
855 if (global_settings.pitch_mode_timestretch && dsp_timestretch_available()) 816 if (global_settings.pitch_mode_timestretch && dsp_timestretch_available())
856 { 817 {
857 talk_id(LANG_SPEED, true); 818 talk_id(LANG_SPEED, true);
858 talk_value_decimal(speed, UNIT_PERCENT, decimals, true); 819 talk_value_decimal(speed, UNIT_PERCENT, decimals, true);
859 } 820 }
860#endif
861 speak_pitch_mode(true); 821 speak_pitch_mode(true);
862 break; 822 break;
863 default: 823 default:
@@ -910,24 +870,17 @@ int gui_syncpitchscreen_run(void)
910 break; 870 break;
911 871
912 case ACTION_PS_NUDGE_RIGHT: 872 case ACTION_PS_NUDGE_RIGHT:
913#if CONFIG_CODEC == SWCODEC
914 if (!global_settings.pitch_mode_timestretch) 873 if (!global_settings.pitch_mode_timestretch)
915 { 874 {
916#endif
917 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false 875 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false
918#if CONFIG_CODEC == SWCODEC
919 , speed 876 , speed
920#endif
921 ); 877 );
922 nudged = (new_pitch != pitch); 878 nudged = (new_pitch != pitch);
923 pitch = new_pitch; 879 pitch = new_pitch;
924 semitone = get_semitone_from_pitch(pitch); 880 semitone = get_semitone_from_pitch(pitch);
925#if CONFIG_CODEC == SWCODEC
926 speed = pitch; 881 speed = pitch;
927#endif
928 updated = nudged ? 1 : 0; 882 updated = nudged ? 1 : 0;
929 break; 883 break;
930#if CONFIG_CODEC == SWCODEC
931 } 884 }
932 else 885 else
933 { 886 {
@@ -948,19 +901,14 @@ int gui_syncpitchscreen_run(void)
948 updated = 2; 901 updated = 2;
949 } 902 }
950 break; 903 break;
951#endif
952 904
953 case ACTION_PS_NUDGE_RIGHTOFF: 905 case ACTION_PS_NUDGE_RIGHTOFF:
954 if (nudged) 906 if (nudged)
955 { 907 {
956 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false 908 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false
957#if CONFIG_CODEC == SWCODEC
958 , speed 909 , speed
959#endif
960 ); 910 );
961#if CONFIG_CODEC == SWCODEC
962 speed = pitch; 911 speed = pitch;
963#endif
964 semitone = get_semitone_from_pitch(pitch); 912 semitone = get_semitone_from_pitch(pitch);
965 nudged = false; 913 nudged = false;
966 updated = 1; 914 updated = 1;
@@ -968,24 +916,17 @@ int gui_syncpitchscreen_run(void)
968 break; 916 break;
969 917
970 case ACTION_PS_NUDGE_LEFT: 918 case ACTION_PS_NUDGE_LEFT:
971#if CONFIG_CODEC == SWCODEC
972 if (!global_settings.pitch_mode_timestretch) 919 if (!global_settings.pitch_mode_timestretch)
973 { 920 {
974#endif
975 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false 921 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false
976#if CONFIG_CODEC == SWCODEC
977 , speed 922 , speed
978#endif
979 ); 923 );
980 nudged = (new_pitch != pitch); 924 nudged = (new_pitch != pitch);
981 pitch = new_pitch; 925 pitch = new_pitch;
982 semitone = get_semitone_from_pitch(pitch); 926 semitone = get_semitone_from_pitch(pitch);
983#if CONFIG_CODEC == SWCODEC
984 speed = pitch; 927 speed = pitch;
985#endif
986 updated = nudged ? 1 : 0; 928 updated = nudged ? 1 : 0;
987 break; 929 break;
988#if CONFIG_CODEC == SWCODEC
989 } 930 }
990 else 931 else
991 { 932 {
@@ -1006,19 +947,14 @@ int gui_syncpitchscreen_run(void)
1006 updated = 2; 947 updated = 2;
1007 } 948 }
1008 break; 949 break;
1009#endif
1010 950
1011 case ACTION_PS_NUDGE_LEFTOFF: 951 case ACTION_PS_NUDGE_LEFTOFF:
1012 if (nudged) 952 if (nudged)
1013 { 953 {
1014 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false 954 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false
1015#if CONFIG_CODEC == SWCODEC
1016 , speed 955 , speed
1017#endif
1018 ); 956 );
1019#if CONFIG_CODEC == SWCODEC
1020 speed = pitch; 957 speed = pitch;
1021#endif
1022 semitone = get_semitone_from_pitch(pitch); 958 semitone = get_semitone_from_pitch(pitch);
1023 nudged = false; 959 nudged = false;
1024 updated = 1; 960 updated = 1;
@@ -1028,21 +964,18 @@ int gui_syncpitchscreen_run(void)
1028 case ACTION_PS_RESET: 964 case ACTION_PS_RESET:
1029 pitch = PITCH_SPEED_100; 965 pitch = PITCH_SPEED_100;
1030 sound_set_pitch(pitch); 966 sound_set_pitch(pitch);
1031#if CONFIG_CODEC == SWCODEC
1032 speed = PITCH_SPEED_100; 967 speed = PITCH_SPEED_100;
1033 if (dsp_timestretch_available()) 968 if (dsp_timestretch_available())
1034 { 969 {
1035 dsp_set_timestretch(PITCH_SPEED_100); 970 dsp_set_timestretch(PITCH_SPEED_100);
1036 at_limit = false; 971 at_limit = false;
1037 } 972 }
1038#endif
1039 semitone = get_semitone_from_pitch(pitch); 973 semitone = get_semitone_from_pitch(pitch);
1040 updated = 4; 974 updated = 4;
1041 break; 975 break;
1042 976
1043 case ACTION_PS_TOGGLE_MODE: 977 case ACTION_PS_TOGGLE_MODE:
1044 global_settings.pitch_mode_semitone = !global_settings.pitch_mode_semitone; 978 global_settings.pitch_mode_semitone = !global_settings.pitch_mode_semitone;
1045#if CONFIG_CODEC == SWCODEC
1046 979
1047 if (dsp_timestretch_available() && !global_settings.pitch_mode_semitone) 980 if (dsp_timestretch_available() && !global_settings.pitch_mode_semitone)
1048 { 981 {
@@ -1055,7 +988,6 @@ int gui_syncpitchscreen_run(void)
1055 } 988 }
1056 } 989 }
1057 settings_save(); 990 settings_save();
1058#endif
1059 updated = 3; 991 updated = 3;
1060 break; 992 break;
1061 993
@@ -1073,22 +1005,17 @@ int gui_syncpitchscreen_run(void)
1073 if (global_settings.pitch_mode_semitone) 1005 if (global_settings.pitch_mode_semitone)
1074 { 1006 {
1075 semitone = pitch_increase_semitone(pitch, semitone, pitch_delta 1007 semitone = pitch_increase_semitone(pitch, semitone, pitch_delta
1076#if CONFIG_CODEC == SWCODEC
1077 , speed 1008 , speed
1078#endif
1079 ); 1009 );
1080 pitch = get_pitch_from_semitone(semitone); 1010 pitch = get_pitch_from_semitone(semitone);
1081 } 1011 }
1082 else 1012 else
1083 { 1013 {
1084 pitch = pitch_increase(pitch, pitch_delta, true 1014 pitch = pitch_increase(pitch, pitch_delta, true
1085#if CONFIG_CODEC == SWCODEC
1086 , speed 1015 , speed
1087#endif
1088 ); 1016 );
1089 semitone = get_semitone_from_pitch(pitch); 1017 semitone = get_semitone_from_pitch(pitch);
1090 } 1018 }
1091#if CONFIG_CODEC == SWCODEC
1092 if (global_settings.pitch_mode_timestretch) 1019 if (global_settings.pitch_mode_timestretch)
1093 { 1020 {
1094 /* do this to make sure we properly obey the stretch limits */ 1021 /* do this to make sure we properly obey the stretch limits */
@@ -1098,10 +1025,8 @@ int gui_syncpitchscreen_run(void)
1098 { 1025 {
1099 speed = pitch; 1026 speed = pitch;
1100 } 1027 }
1101#endif
1102 } 1028 }
1103 1029
1104#if CONFIG_CODEC == SWCODEC
1105 if(new_speed) 1030 if(new_speed)
1106 { 1031 {
1107 new_stretch = GET_STRETCH(pitch, new_speed); 1032 new_stretch = GET_STRETCH(pitch, new_speed);
@@ -1135,11 +1060,8 @@ int gui_syncpitchscreen_run(void)
1135 /* when needed */ 1060 /* when needed */
1136 new_speed = 0; 1061 new_speed = 0;
1137 } 1062 }
1138#endif
1139 } 1063 }
1140#if CONFIG_CODEC == SWCODEC
1141 pcmbuf_set_low_latency(false); 1064 pcmbuf_set_low_latency(false);
1142#endif
1143 pop_current_activity(); 1065 pop_current_activity();
1144 return 0; 1066 return 0;
1145} 1067}