1
0
Fork 0
forked from len0rd/rockbox

Allow use of timestretch with semitones in the pitchscreen. Rename variables to clarify the meaning of 'speed'.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21468 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Steve Bavin 2009-06-22 18:52:14 +00:00
parent 659425f23e
commit 40d9b218e5
3 changed files with 41 additions and 57 deletions

View file

@ -50,14 +50,10 @@
#define PITCH_BIG_DELTA 10 #define PITCH_BIG_DELTA 10
#define PITCH_NUDGE_DELTA 20 #define PITCH_NUDGE_DELTA 20
static enum static bool pitch_mode_semitone = false;
{
PITCH_MODE_ABSOLUTE,
PITCH_MODE_SEMITONE,
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
PITCH_MODE_TIMESTRETCH, static bool pitch_mode_timestretch = false;
#endif #endif
} pitch_mode = PITCH_MODE_ABSOLUTE;
enum enum
{ {
@ -113,7 +109,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
struct viewport pitch_viewports[PITCH_ITEM_COUNT], struct viewport pitch_viewports[PITCH_ITEM_COUNT],
int pitch int pitch
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
,int speedxpitch ,int speed
#endif #endif
) )
{ {
@ -127,7 +123,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
{ {
/* UP: Pitch Up */ /* UP: Pitch Up */
display->set_viewport(&pitch_viewports[PITCH_TOP]); display->set_viewport(&pitch_viewports[PITCH_TOP]);
if (pitch_mode == PITCH_MODE_SEMITONE) if (pitch_mode_semitone)
ptr = str(LANG_PITCH_UP_SEMITONE); ptr = str(LANG_PITCH_UP_SEMITONE);
else else
ptr = str(LANG_PITCH_UP); ptr = str(LANG_PITCH_UP);
@ -140,7 +136,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
/* DOWN: Pitch Down */ /* DOWN: Pitch Down */
display->set_viewport(&pitch_viewports[PITCH_BOTTOM]); display->set_viewport(&pitch_viewports[PITCH_BOTTOM]);
if (pitch_mode == PITCH_MODE_SEMITONE) if (pitch_mode_semitone)
ptr = str(LANG_PITCH_DOWN_SEMITONE); ptr = str(LANG_PITCH_DOWN_SEMITONE);
else else
ptr = str(LANG_PITCH_DOWN); ptr = str(LANG_PITCH_DOWN);
@ -161,7 +157,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
if ((show_lang_pitch = (max_lines >= 3))) if ((show_lang_pitch = (max_lines >= 3)))
{ {
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (pitch_mode != PITCH_MODE_TIMESTRETCH) if (!pitch_mode_timestretch)
{ {
#endif #endif
/* LANG_PITCH */ /* LANG_PITCH */
@ -184,7 +180,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
/* Middle section lower line */ /* Middle section lower line */
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (pitch_mode != PITCH_MODE_TIMESTRETCH) if (!pitch_mode_timestretch)
{ {
#endif #endif
/* "XXX.X%" */ /* "XXX.X%" */
@ -196,7 +192,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
{ {
/* "Speed:XXX%" */ /* "Speed:XXX%" */
snprintf(buf, sizeof(buf), "%s:%d%%", str(LANG_SPEED), snprintf(buf, sizeof(buf), "%s:%d%%", str(LANG_SPEED),
speedxpitch / 1000); speed / 1000);
} }
#endif #endif
display->getstringsize(buf, &w, &h); display->getstringsize(buf, &w, &h);
@ -209,7 +205,7 @@ static void pitchscreen_draw(struct screen *display, int max_lines,
const char *leftlabel = "-2%"; const char *leftlabel = "-2%";
const char *rightlabel = "+2%"; const char *rightlabel = "+2%";
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (pitch_mode == PITCH_MODE_TIMESTRETCH) if (pitch_mode_timestretch)
{ {
leftlabel = "<<"; leftlabel = "<<";
rightlabel = ">>"; rightlabel = ">>";
@ -316,8 +312,8 @@ int gui_syncpitchscreen_run(void)
int button, i; int button, i;
int pitch = sound_get_pitch(); int pitch = sound_get_pitch();
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
int speed = dsp_get_timestretch(); int stretch = dsp_get_timestretch();
int maintain_speed_pitch = speed * pitch; /* speed * pitch to maintain */ int speed = stretch * pitch; /* speed to maintain */
#endif #endif
int new_pitch; int new_pitch;
int pitch_delta; int pitch_delta;
@ -349,7 +345,7 @@ int gui_syncpitchscreen_run(void)
pitchscreen_draw(&screens[i], max_lines[i], pitchscreen_draw(&screens[i], max_lines[i],
pitch_viewports[i], pitch pitch_viewports[i], pitch
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
, maintain_speed_pitch , speed
#endif #endif
); );
pitch_delta = 0; pitch_delta = 0;
@ -374,7 +370,7 @@ int gui_syncpitchscreen_run(void)
case ACTION_PS_NUDGE_RIGHT: case ACTION_PS_NUDGE_RIGHT:
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (pitch_mode != PITCH_MODE_TIMESTRETCH) if (!pitch_mode_timestretch)
{ {
#endif #endif
new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false); new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false);
@ -385,14 +381,11 @@ int gui_syncpitchscreen_run(void)
} }
case ACTION_PS_FASTER: case ACTION_PS_FASTER:
if (pitch_mode == PITCH_MODE_TIMESTRETCH) if (pitch_mode_timestretch && stretch < STRETCH_MAX)
{ {
if (speed < SPEED_MAX) stretch++;
{ dsp_set_timestretch(stretch);
speed++; speed = stretch * pitch;
dsp_set_timestretch(speed);
maintain_speed_pitch = speed * pitch;
}
} }
break; break;
#endif #endif
@ -407,7 +400,7 @@ int gui_syncpitchscreen_run(void)
case ACTION_PS_NUDGE_LEFT: case ACTION_PS_NUDGE_LEFT:
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (pitch_mode != PITCH_MODE_TIMESTRETCH) if (!pitch_mode_timestretch)
{ {
#endif #endif
new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false); new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false);
@ -418,14 +411,11 @@ int gui_syncpitchscreen_run(void)
} }
case ACTION_PS_SLOWER: case ACTION_PS_SLOWER:
if (pitch_mode == PITCH_MODE_TIMESTRETCH) if (pitch_mode_timestretch && stretch > STRETCH_MIN)
{ {
if (speed > SPEED_MIN) stretch--;
{ dsp_set_timestretch(stretch);
speed--; speed = stretch * pitch;
dsp_set_timestretch(speed);
maintain_speed_pitch = speed * pitch;
}
} }
break; break;
#endif #endif
@ -442,24 +432,18 @@ int gui_syncpitchscreen_run(void)
pitch = 1000; pitch = 1000;
sound_set_pitch(pitch); sound_set_pitch(pitch);
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
speed = 100; stretch = 100;
dsp_set_timestretch(speed); dsp_set_timestretch(stretch);
maintain_speed_pitch = speed * pitch; speed = stretch * pitch;
#endif #endif
break; break;
case ACTION_PS_TOGGLE_MODE: case ACTION_PS_TOGGLE_MODE:
++pitch_mode;
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (dsp_timestretch_available()) if (dsp_timestretch_available() && pitch_mode_semitone)
{ pitch_mode_timestretch = !pitch_mode_timestretch;
if (pitch_mode > PITCH_MODE_TIMESTRETCH)
pitch_mode = PITCH_MODE_ABSOLUTE;
break;
}
#endif #endif
if (pitch_mode > PITCH_MODE_SEMITONE) pitch_mode_semitone = !pitch_mode_semitone;
pitch_mode = PITCH_MODE_ABSOLUTE;
break; break;
case ACTION_PS_EXIT: case ACTION_PS_EXIT:
@ -473,24 +457,24 @@ int gui_syncpitchscreen_run(void)
} }
if (pitch_delta) if (pitch_delta)
{ {
if (pitch_mode == PITCH_MODE_SEMITONE) if (pitch_mode_semitone)
pitch = pitch_increase_semitone(pitch, pitch_delta > 0); pitch = pitch_increase_semitone(pitch, pitch_delta > 0);
else else
pitch = pitch_increase(pitch, pitch_delta, true); pitch = pitch_increase(pitch, pitch_delta, true);
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
if (pitch_mode == PITCH_MODE_TIMESTRETCH) if (pitch_mode_timestretch)
{ {
/* Set speed to maintain time dimension */ /* Set stretch to maintain speed */
/* i.e. increase pitch, slow down speed */ /* i.e. increase pitch, reduce stretch */
int new_speed = maintain_speed_pitch / pitch; int new_stretch = speed / pitch;
if (new_speed >= SPEED_MIN && new_speed <= SPEED_MAX) if (new_stretch >= STRETCH_MIN && new_stretch <= STRETCH_MAX)
{ {
speed = new_speed; stretch = new_stretch;
dsp_set_timestretch(speed); dsp_set_timestretch(stretch);
} }
} }
else else
maintain_speed_pitch = speed * pitch; speed = stretch * new_pitch;
#endif #endif
} }
} }

View file

@ -88,7 +88,7 @@ bool tdspeed_config(int samplerate, bool stereo, int factor)
return false; return false;
if (samplerate < MIN_RATE || samplerate > MAX_RATE) if (samplerate < MIN_RATE || samplerate > MAX_RATE)
return false; return false;
if (factor < SPEED_MIN || factor > SPEED_MAX) if (factor < STRETCH_MIN || factor > STRETCH_MAX)
return false; return false;
st->stereo = stereo; st->stereo = stereo;

View file

@ -31,7 +31,7 @@ long tdspeed_est_output_size(void);
long tdspeed_est_input_size(long size); long tdspeed_est_input_size(long size);
int tdspeed_doit(int32_t *src[], int count); int tdspeed_doit(int32_t *src[], int count);
#define SPEED_MAX 250 #define STRETCH_MAX 250
#define SPEED_MIN 35 #define STRETCH_MIN 35
#endif #endif