summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/pitchscreen.c92
1 files changed, 38 insertions, 54 deletions
diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c
index cd970d795d..f25448176f 100644
--- a/apps/gui/pitchscreen.c
+++ b/apps/gui/pitchscreen.c
@@ -50,14 +50,10 @@
50#define PITCH_BIG_DELTA 10 50#define PITCH_BIG_DELTA 10
51#define PITCH_NUDGE_DELTA 20 51#define PITCH_NUDGE_DELTA 20
52 52
53static enum 53static bool pitch_mode_semitone = false;
54{
55 PITCH_MODE_ABSOLUTE,
56 PITCH_MODE_SEMITONE,
57#if CONFIG_CODEC == SWCODEC 54#if CONFIG_CODEC == SWCODEC
58 PITCH_MODE_TIMESTRETCH, 55static bool pitch_mode_timestretch = false;
59#endif 56#endif
60} pitch_mode = PITCH_MODE_ABSOLUTE;
61 57
62enum 58enum
63{ 59{
@@ -113,7 +109,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
113 struct viewport pitch_viewports[PITCH_ITEM_COUNT], 109 struct viewport pitch_viewports[PITCH_ITEM_COUNT],
114 int pitch 110 int pitch
115#if CONFIG_CODEC == SWCODEC 111#if CONFIG_CODEC == SWCODEC
116 ,int speedxpitch 112 ,int speed
117#endif 113#endif
118 ) 114 )
119{ 115{
@@ -127,7 +123,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
127 { 123 {
128 /* UP: Pitch Up */ 124 /* UP: Pitch Up */
129 display->set_viewport(&pitch_viewports[PITCH_TOP]); 125 display->set_viewport(&pitch_viewports[PITCH_TOP]);
130 if (pitch_mode == PITCH_MODE_SEMITONE) 126 if (pitch_mode_semitone)
131 ptr = str(LANG_PITCH_UP_SEMITONE); 127 ptr = str(LANG_PITCH_UP_SEMITONE);
132 else 128 else
133 ptr = str(LANG_PITCH_UP); 129 ptr = str(LANG_PITCH_UP);
@@ -140,7 +136,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
140 136
141 /* DOWN: Pitch Down */ 137 /* DOWN: Pitch Down */
142 display->set_viewport(&pitch_viewports[PITCH_BOTTOM]); 138 display->set_viewport(&pitch_viewports[PITCH_BOTTOM]);
143 if (pitch_mode == PITCH_MODE_SEMITONE) 139 if (pitch_mode_semitone)
144 ptr = str(LANG_PITCH_DOWN_SEMITONE); 140 ptr = str(LANG_PITCH_DOWN_SEMITONE);
145 else 141 else
146 ptr = str(LANG_PITCH_DOWN); 142 ptr = str(LANG_PITCH_DOWN);
@@ -161,7 +157,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
161 if ((show_lang_pitch = (max_lines >= 3))) 157 if ((show_lang_pitch = (max_lines >= 3)))
162 { 158 {
163#if CONFIG_CODEC == SWCODEC 159#if CONFIG_CODEC == SWCODEC
164 if (pitch_mode != PITCH_MODE_TIMESTRETCH) 160 if (!pitch_mode_timestretch)
165 { 161 {
166#endif 162#endif
167 /* LANG_PITCH */ 163 /* LANG_PITCH */
@@ -184,7 +180,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
184 180
185 /* Middle section lower line */ 181 /* Middle section lower line */
186#if CONFIG_CODEC == SWCODEC 182#if CONFIG_CODEC == SWCODEC
187 if (pitch_mode != PITCH_MODE_TIMESTRETCH) 183 if (!pitch_mode_timestretch)
188 { 184 {
189#endif 185#endif
190 /* "XXX.X%" */ 186 /* "XXX.X%" */
@@ -196,7 +192,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
196 { 192 {
197 /* "Speed:XXX%" */ 193 /* "Speed:XXX%" */
198 snprintf(buf, sizeof(buf), "%s:%d%%", str(LANG_SPEED), 194 snprintf(buf, sizeof(buf), "%s:%d%%", str(LANG_SPEED),
199 speedxpitch / 1000); 195 speed / 1000);
200 } 196 }
201#endif 197#endif
202 display->getstringsize(buf, &w, &h); 198 display->getstringsize(buf, &w, &h);
@@ -209,7 +205,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
209 const char *leftlabel = "-2%"; 205 const char *leftlabel = "-2%";
210 const char *rightlabel = "+2%"; 206 const char *rightlabel = "+2%";
211#if CONFIG_CODEC == SWCODEC 207#if CONFIG_CODEC == SWCODEC
212 if (pitch_mode == PITCH_MODE_TIMESTRETCH) 208 if (pitch_mode_timestretch)
213 { 209 {
214 leftlabel = "<<"; 210 leftlabel = "<<";
215 rightlabel = ">>"; 211 rightlabel = ">>";
@@ -316,8 +312,8 @@ int gui_syncpitchscreen_run(void)
316 int button, i; 312 int button, i;
317 int pitch = sound_get_pitch(); 313 int pitch = sound_get_pitch();
318#if CONFIG_CODEC == SWCODEC 314#if CONFIG_CODEC == SWCODEC
319 int speed = dsp_get_timestretch(); 315 int stretch = dsp_get_timestretch();
320 int maintain_speed_pitch = speed * pitch; /* speed * pitch to maintain */ 316 int speed = stretch * pitch; /* speed to maintain */
321#endif 317#endif
322 int new_pitch; 318 int new_pitch;
323 int pitch_delta; 319 int pitch_delta;
@@ -349,7 +345,7 @@ int gui_syncpitchscreen_run(void)
349 pitchscreen_draw(&screens[i], max_lines[i], 345 pitchscreen_draw(&screens[i], max_lines[i],
350 pitch_viewports[i], pitch 346 pitch_viewports[i], pitch
351#if CONFIG_CODEC == SWCODEC 347#if CONFIG_CODEC == SWCODEC
352 , maintain_speed_pitch 348 , speed
353#endif 349#endif
354 ); 350 );
355 pitch_delta = 0; 351 pitch_delta = 0;
@@ -374,7 +370,7 @@ int gui_syncpitchscreen_run(void)
374 370
375 case ACTION_PS_NUDGE_RIGHT: 371 case ACTION_PS_NUDGE_RIGHT:
376#if CONFIG_CODEC == SWCODEC 372#if CONFIG_CODEC == SWCODEC
377 if (pitch_mode != PITCH_MODE_TIMESTRETCH) 373 if (!pitch_mode_timestretch)
378 { 374 {
379#endif 375#endif
380 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false); 376 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
@@ -385,14 +381,11 @@ int gui_syncpitchscreen_run(void)
385 } 381 }
386 382
387 case ACTION_PS_FASTER: 383 case ACTION_PS_FASTER:
388 if (pitch_mode == PITCH_MODE_TIMESTRETCH) 384 if (pitch_mode_timestretch && stretch < STRETCH_MAX)
389 { 385 {
390 if (speed < SPEED_MAX) 386 stretch++;
391 { 387 dsp_set_timestretch(stretch);
392 speed++; 388 speed = stretch * pitch;
393 dsp_set_timestretch(speed);
394 maintain_speed_pitch = speed * pitch;
395 }
396 } 389 }
397 break; 390 break;
398#endif 391#endif
@@ -407,7 +400,7 @@ int gui_syncpitchscreen_run(void)
407 400
408 case ACTION_PS_NUDGE_LEFT: 401 case ACTION_PS_NUDGE_LEFT:
409#if CONFIG_CODEC == SWCODEC 402#if CONFIG_CODEC == SWCODEC
410 if (pitch_mode != PITCH_MODE_TIMESTRETCH) 403 if (!pitch_mode_timestretch)
411 { 404 {
412#endif 405#endif
413 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false); 406 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
@@ -418,14 +411,11 @@ int gui_syncpitchscreen_run(void)
418 } 411 }
419 412
420 case ACTION_PS_SLOWER: 413 case ACTION_PS_SLOWER:
421 if (pitch_mode == PITCH_MODE_TIMESTRETCH) 414 if (pitch_mode_timestretch && stretch > STRETCH_MIN)
422 { 415 {
423 if (speed > SPEED_MIN) 416 stretch--;
424 { 417 dsp_set_timestretch(stretch);
425 speed--; 418 speed = stretch * pitch;
426 dsp_set_timestretch(speed);
427 maintain_speed_pitch = speed * pitch;
428 }
429 } 419 }
430 break; 420 break;
431#endif 421#endif
@@ -442,24 +432,18 @@ int gui_syncpitchscreen_run(void)
442 pitch = 1000; 432 pitch = 1000;
443 sound_set_pitch(pitch); 433 sound_set_pitch(pitch);
444#if CONFIG_CODEC == SWCODEC 434#if CONFIG_CODEC == SWCODEC
445 speed = 100; 435 stretch = 100;
446 dsp_set_timestretch(speed); 436 dsp_set_timestretch(stretch);
447 maintain_speed_pitch = speed * pitch; 437 speed = stretch * pitch;
448#endif 438#endif
449 break; 439 break;
450 440
451 case ACTION_PS_TOGGLE_MODE: 441 case ACTION_PS_TOGGLE_MODE:
452 ++pitch_mode;
453#if CONFIG_CODEC == SWCODEC 442#if CONFIG_CODEC == SWCODEC
454 if (dsp_timestretch_available()) 443 if (dsp_timestretch_available() && pitch_mode_semitone)
455 { 444 pitch_mode_timestretch = !pitch_mode_timestretch;
456 if (pitch_mode > PITCH_MODE_TIMESTRETCH)
457 pitch_mode = PITCH_MODE_ABSOLUTE;
458 break;
459 }
460#endif 445#endif
461 if (pitch_mode > PITCH_MODE_SEMITONE) 446 pitch_mode_semitone = !pitch_mode_semitone;
462 pitch_mode = PITCH_MODE_ABSOLUTE;
463 break; 447 break;
464 448
465 case ACTION_PS_EXIT: 449 case ACTION_PS_EXIT:
@@ -473,25 +457,25 @@ int gui_syncpitchscreen_run(void)
473 } 457 }
474 if (pitch_delta) 458 if (pitch_delta)
475 { 459 {
476 if (pitch_mode == PITCH_MODE_SEMITONE) 460 if (pitch_mode_semitone)
477 pitch = pitch_increase_semitone(pitch, pitch_delta > 0); 461 pitch = pitch_increase_semitone(pitch, pitch_delta > 0);
478 else 462 else
479 pitch = pitch_increase(pitch, pitch_delta, true); 463 pitch = pitch_increase(pitch, pitch_delta, true);
480#if CONFIG_CODEC == SWCODEC 464#if CONFIG_CODEC == SWCODEC
481 if (pitch_mode == PITCH_MODE_TIMESTRETCH) 465 if (pitch_mode_timestretch)
482 { 466 {
483 /* Set speed to maintain time dimension */ 467 /* Set stretch to maintain speed */
484 /* i.e. increase pitch, slow down speed */ 468 /* i.e. increase pitch, reduce stretch */
485 int new_speed = maintain_speed_pitch / pitch; 469 int new_stretch = speed / pitch;
486 if (new_speed >= SPEED_MIN && new_speed <= SPEED_MAX) 470 if (new_stretch >= STRETCH_MIN && new_stretch <= STRETCH_MAX)
487 { 471 {
488 speed = new_speed; 472 stretch = new_stretch;
489 dsp_set_timestretch(speed); 473 dsp_set_timestretch(stretch);
490 } 474 }
491 } 475 }
492 else 476 else
493 maintain_speed_pitch = speed * pitch; 477 speed = stretch * new_pitch;
494#endif 478#endif
495 } 479 }
496 } 480 }
497#if CONFIG_CODEC == SWCODEC 481#if CONFIG_CODEC == SWCODEC