2008-05-05 07:07:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2002 Björn Stenberg
|
2008-05-05 07:07:19 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-05-05 07:07:19 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2009-07-11 16:46:19 +00:00
|
|
|
#include <math.h>
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <stdlib.h> /* for abs() */
|
2008-05-05 07:07:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "action.h"
|
|
|
|
#include "dsp.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "pcmbuf.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "icons.h"
|
2008-05-08 20:37:26 +00:00
|
|
|
#include "screens.h"
|
2008-10-05 13:01:54 +00:00
|
|
|
#include "viewport.h"
|
2009-03-08 18:37:32 +00:00
|
|
|
#include "font.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "misc.h"
|
2008-10-05 13:01:54 +00:00
|
|
|
#include "pitchscreen.h"
|
2009-07-11 16:46:19 +00:00
|
|
|
#include "settings.h"
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
#include "tdspeed.h"
|
|
|
|
#endif
|
|
|
|
|
2008-10-05 13:45:21 +00:00
|
|
|
#define ICON_BORDER 12 /* icons are currently 7x8, so add ~2 pixels */
|
|
|
|
/* on both sides when drawing */
|
2008-05-05 07:07:19 +00:00
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
#define PITCH_MAX (200 * PITCH_SPEED_PRECISION)
|
|
|
|
#define PITCH_MIN (50 * PITCH_SPEED_PRECISION)
|
|
|
|
#define PITCH_SMALL_DELTA (PITCH_SPEED_PRECISION / 10) /* .1% */
|
|
|
|
#define PITCH_BIG_DELTA (PITCH_SPEED_PRECISION) /* 1% */
|
|
|
|
#define PITCH_NUDGE_DELTA (2 * PITCH_SPEED_PRECISION) /* 2% */
|
2008-10-05 13:01:54 +00:00
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
#define SPEED_SMALL_DELTA (PITCH_SPEED_PRECISION / 10) /* .1% */
|
|
|
|
#define SPEED_BIG_DELTA (PITCH_SPEED_PRECISION) /* 1% */
|
|
|
|
|
|
|
|
#define SEMITONE_SMALL_DELTA (PITCH_SPEED_PRECISION / 10) /* 10 cents */
|
|
|
|
#define SEMITONE_BIG_DELTA PITCH_SPEED_PRECISION /* 1 semitone */
|
2008-10-05 13:45:21 +00:00
|
|
|
|
2008-10-05 13:13:55 +00:00
|
|
|
enum
|
2008-10-05 13:01:54 +00:00
|
|
|
{
|
|
|
|
PITCH_TOP = 0,
|
|
|
|
PITCH_MID,
|
|
|
|
PITCH_BOTTOM,
|
|
|
|
PITCH_ITEM_COUNT,
|
|
|
|
};
|
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
|
|
|
|
/* This is a table of semitone percentage values of the appropriate
|
|
|
|
precision (based on PITCH_SPEED_PRECISION). Note that these are
|
|
|
|
all constant expressions, which will be evaluated at compile time,
|
|
|
|
so no need to worry about how complex the expressions look.
|
|
|
|
That's just to get the precision right.
|
|
|
|
|
|
|
|
I calculated these values, starting from 50, as
|
|
|
|
|
|
|
|
x(n) = 50 * 2^(n/12)
|
|
|
|
|
|
|
|
All that math in each entry simply converts the float constant
|
|
|
|
to an integer equal to PITCH_SPEED_PRECISION times the float value,
|
2009-07-12 17:14:01 +00:00
|
|
|
with as little precision loss as possible (i.e. correctly rounding
|
|
|
|
the last digit).
|
2009-07-11 16:46:19 +00:00
|
|
|
*/
|
2009-07-12 17:14:01 +00:00
|
|
|
#define TO_INT_WITH_PRECISION(x) \
|
2009-07-13 14:48:02 +00:00
|
|
|
( (unsigned short)(((x) * PITCH_SPEED_PRECISION * 10 + 5) / 10) )
|
2009-07-11 16:46:19 +00:00
|
|
|
|
2009-07-13 14:48:02 +00:00
|
|
|
static const unsigned short semitone_table[] =
|
2009-07-11 16:46:19 +00:00
|
|
|
{
|
2009-07-12 17:14:01 +00:00
|
|
|
TO_INT_WITH_PRECISION(50.00000000), /* Octave lower */
|
|
|
|
TO_INT_WITH_PRECISION(52.97315472),
|
|
|
|
TO_INT_WITH_PRECISION(56.12310242),
|
|
|
|
TO_INT_WITH_PRECISION(59.46035575),
|
|
|
|
TO_INT_WITH_PRECISION(62.99605249),
|
|
|
|
TO_INT_WITH_PRECISION(66.74199271),
|
|
|
|
TO_INT_WITH_PRECISION(70.71067812),
|
|
|
|
TO_INT_WITH_PRECISION(74.91535384),
|
|
|
|
TO_INT_WITH_PRECISION(79.37005260),
|
|
|
|
TO_INT_WITH_PRECISION(84.08964153),
|
|
|
|
TO_INT_WITH_PRECISION(89.08987181),
|
|
|
|
TO_INT_WITH_PRECISION(94.38743127),
|
|
|
|
TO_INT_WITH_PRECISION(100.0000000), /* Normal sound */
|
|
|
|
TO_INT_WITH_PRECISION(105.9463094),
|
|
|
|
TO_INT_WITH_PRECISION(112.2462048),
|
|
|
|
TO_INT_WITH_PRECISION(118.9207115),
|
|
|
|
TO_INT_WITH_PRECISION(125.9921049),
|
|
|
|
TO_INT_WITH_PRECISION(133.4839854),
|
|
|
|
TO_INT_WITH_PRECISION(141.4213562),
|
|
|
|
TO_INT_WITH_PRECISION(149.8307077),
|
|
|
|
TO_INT_WITH_PRECISION(158.7401052),
|
|
|
|
TO_INT_WITH_PRECISION(168.1792831),
|
|
|
|
TO_INT_WITH_PRECISION(178.1797436),
|
|
|
|
TO_INT_WITH_PRECISION(188.7748625),
|
|
|
|
TO_INT_WITH_PRECISION(200.0000000) /* Octave higher */
|
2009-07-11 16:46:19 +00:00
|
|
|
};
|
|
|
|
|
2009-07-13 14:20:39 +00:00
|
|
|
#define NUM_SEMITONES ((int)(sizeof(semitone_table)/sizeof(semitone_table[0])))
|
2009-07-12 17:14:01 +00:00
|
|
|
#define SEMITONE_END (NUM_SEMITONES/2)
|
|
|
|
#define SEMITONE_START (-SEMITONE_END)
|
2009-07-11 16:46:19 +00:00
|
|
|
|
|
|
|
/* A table of values for approximating the cent curve with
|
|
|
|
linear interpolation. Multipy the next lowest semitone
|
|
|
|
by this much to find the corresponding cent percentage.
|
|
|
|
|
|
|
|
These values were calculated as
|
|
|
|
x(n) = 100 * 2^(n * 20/1200)
|
|
|
|
*/
|
|
|
|
|
2009-07-13 14:48:02 +00:00
|
|
|
static const unsigned short cent_interp[] =
|
2009-07-11 16:46:19 +00:00
|
|
|
{
|
2009-07-12 17:14:01 +00:00
|
|
|
TO_INT_WITH_PRECISION(100.0000000),
|
|
|
|
TO_INT_WITH_PRECISION(101.1619440),
|
|
|
|
TO_INT_WITH_PRECISION(102.3373892),
|
|
|
|
TO_INT_WITH_PRECISION(103.5264924),
|
|
|
|
TO_INT_WITH_PRECISION(104.7294123),
|
2009-07-11 16:46:19 +00:00
|
|
|
/* this one's the next semitone but we have it here for convenience */
|
2009-07-12 17:14:01 +00:00
|
|
|
TO_INT_WITH_PRECISION(105.9463094),
|
2009-07-11 16:46:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Number of cents between entries in the cent_interp table */
|
|
|
|
#define CENT_INTERP_INTERVAL 20
|
2009-07-13 14:20:39 +00:00
|
|
|
#define CENT_INTERP_NUM ((int)(sizeof(cent_interp)/sizeof(cent_interp[0])))
|
2009-07-11 16:46:19 +00:00
|
|
|
|
|
|
|
/* This stores whether the pitch and speed are at their own limits */
|
|
|
|
/* or that of the timestretching algorithm */
|
|
|
|
static bool at_limit = false;
|
|
|
|
|
2010-10-25 21:20:04 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* The pitchscreen is divided into 3 viewports (each row is a viewport)
|
|
|
|
* Then each viewport is again divided into 3 colums, each showsing some infos
|
|
|
|
* Additionally, on touchscreen, each cell represents a button
|
|
|
|
*
|
|
|
|
* Below a sketch describing what each cell will show (what's drawn on it)
|
|
|
|
* --------------------------
|
|
|
|
* | | | | <-- pitch up in the middle (text and button)
|
|
|
|
* | | | | <-- arrows for mode toggling on the sides for touchscreen
|
|
|
|
* |------------------------|
|
|
|
|
* | | | | <-- semitone/speed up/down on the sides
|
|
|
|
* | | | | <-- reset pitch&speed in the middle
|
|
|
|
* |------------------------|
|
|
|
|
* | | | | <-- pitch down in the middle
|
|
|
|
* | | | | <-- Two "OK" for exit on the sides for touchscreen
|
|
|
|
* |------------------------|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixes the viewports so they represent the 3 rows, and adds a little margin
|
|
|
|
* on all sides for the icons (which are drawn outside of the grid
|
|
|
|
*
|
|
|
|
* The modified viewports need to be passed to the touchscreen handling function
|
|
|
|
**/
|
2008-10-05 13:45:21 +00:00
|
|
|
static void pitchscreen_fix_viewports(struct viewport *parent,
|
|
|
|
struct viewport pitch_viewports[PITCH_ITEM_COUNT])
|
2008-10-05 13:01:54 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
int i, font_height;
|
|
|
|
font_height = font_get(parent->font)->height;
|
2009-01-28 20:14:01 +00:00
|
|
|
for (i = 0; i < PITCH_ITEM_COUNT; i++)
|
2008-10-05 13:01:54 +00:00
|
|
|
{
|
2009-01-28 20:14:01 +00:00
|
|
|
pitch_viewports[i] = *parent;
|
2010-10-25 21:20:04 +00:00
|
|
|
pitch_viewports[i].height = parent->height / PITCH_ITEM_COUNT;
|
|
|
|
pitch_viewports[i].x += ICON_BORDER;
|
|
|
|
pitch_viewports[i].width -= 2*ICON_BORDER;
|
2008-10-05 13:01:54 +00:00
|
|
|
}
|
2010-10-25 21:20:04 +00:00
|
|
|
pitch_viewports[PITCH_TOP].y += ICON_BORDER;
|
|
|
|
pitch_viewports[PITCH_TOP].height -= ICON_BORDER;
|
2008-10-05 13:01:54 +00:00
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
if(pitch_viewports[PITCH_MID].height < font_height * 2)
|
|
|
|
pitch_viewports[PITCH_MID].height = font_height * 2;
|
2009-01-28 20:14:01 +00:00
|
|
|
|
2010-10-25 21:20:04 +00:00
|
|
|
pitch_viewports[PITCH_MID].y = pitch_viewports[PITCH_TOP].y
|
|
|
|
+ pitch_viewports[PITCH_TOP].height;
|
|
|
|
|
|
|
|
pitch_viewports[PITCH_BOTTOM].y = pitch_viewports[PITCH_MID].y
|
|
|
|
+ pitch_viewports[PITCH_MID].height;
|
|
|
|
|
|
|
|
pitch_viewports[PITCH_BOTTOM].height -= ICON_BORDER;
|
2008-10-05 13:01:54 +00:00
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
|
2008-10-05 13:01:54 +00:00
|
|
|
/* must be called before pitchscreen_draw, or within
|
|
|
|
* since it neither clears nor updates the display */
|
2009-06-12 07:20:50 +00:00
|
|
|
static void pitchscreen_draw_icons(struct screen *display,
|
|
|
|
struct viewport *parent)
|
2008-10-05 13:01:54 +00:00
|
|
|
{
|
|
|
|
display->set_viewport(parent);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
|
|
|
|
parent->width/2 - 3,
|
|
|
|
2, 7, 8);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
|
|
|
|
parent->width /2 - 3,
|
|
|
|
parent->height - 10, 7, 8);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
|
|
|
|
parent->width - 10,
|
|
|
|
parent->height /2 - 4, 7, 8);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
|
|
|
|
2,
|
|
|
|
parent->height /2 - 4, 7, 8);
|
2009-02-05 00:14:52 +00:00
|
|
|
display->update_viewport();
|
2008-10-05 13:01:54 +00:00
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
|
2009-06-12 07:20:50 +00:00
|
|
|
static void pitchscreen_draw(struct screen *display, int max_lines,
|
|
|
|
struct viewport pitch_viewports[PITCH_ITEM_COUNT],
|
2009-07-11 16:46:19 +00:00
|
|
|
int32_t pitch, int32_t semitone
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
,int32_t speed
|
2009-06-12 07:20:50 +00:00
|
|
|
#endif
|
|
|
|
)
|
2008-05-05 07:07:19 +00:00
|
|
|
{
|
2009-10-10 09:57:03 +00:00
|
|
|
const char* ptr;
|
2009-06-12 07:20:50 +00:00
|
|
|
char buf[32];
|
|
|
|
int w, h;
|
2008-10-05 13:01:54 +00:00
|
|
|
bool show_lang_pitch;
|
2008-05-05 07:07:19 +00:00
|
|
|
|
2009-10-15 21:30:19 +00:00
|
|
|
/* "Pitch up/Pitch down" - hide for a small screen,
|
2010-10-25 21:20:04 +00:00
|
|
|
* the text is drawn centered automatically
|
|
|
|
*
|
|
|
|
* note: this assumes 5 lines always fit on a touchscreen (should be
|
|
|
|
* reasonable) */
|
2008-10-05 13:01:54 +00:00
|
|
|
if (max_lines >= 5)
|
2008-05-05 07:07:19 +00:00
|
|
|
{
|
2010-10-25 21:20:04 +00:00
|
|
|
int w, h;
|
|
|
|
struct viewport *vp = &pitch_viewports[PITCH_TOP];
|
|
|
|
display->set_viewport(vp);
|
|
|
|
display->clear_viewport();
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
/* two arrows in the top row, left and right column */
|
|
|
|
char *arrows[] = { "<", ">"};
|
|
|
|
display->getstringsize(arrows[0], &w, &h);
|
|
|
|
display->putsxy(0, vp->height/2 - h/2, arrows[0]);
|
|
|
|
display->putsxy(vp->width - w, vp->height/2 - h/2, arrows[1]);
|
|
|
|
#endif
|
2008-05-05 07:07:19 +00:00
|
|
|
/* UP: Pitch Up */
|
2009-07-11 16:46:19 +00:00
|
|
|
if (global_settings.pitch_mode_semitone)
|
2008-05-05 07:07:19 +00:00
|
|
|
ptr = str(LANG_PITCH_UP_SEMITONE);
|
2009-06-12 07:20:50 +00:00
|
|
|
else
|
|
|
|
ptr = str(LANG_PITCH_UP);
|
2010-10-25 21:20:04 +00:00
|
|
|
|
|
|
|
display->getstringsize(ptr, &w, NULL);
|
2008-10-05 13:01:54 +00:00
|
|
|
/* draw text */
|
2010-10-25 21:20:04 +00:00
|
|
|
display->putsxy(vp->width/2 - w/2, 0, ptr);
|
2009-01-28 20:14:01 +00:00
|
|
|
display->update_viewport();
|
2008-05-05 07:07:19 +00:00
|
|
|
|
|
|
|
/* DOWN: Pitch Down */
|
2010-10-25 21:20:04 +00:00
|
|
|
vp = &pitch_viewports[PITCH_BOTTOM];
|
|
|
|
display->set_viewport(vp);
|
|
|
|
display->clear_viewport();
|
|
|
|
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
ptr = str(LANG_KBD_OK);
|
|
|
|
display->getstringsize(ptr, &w, &h);
|
|
|
|
/* one OK in the middle first column of the vp (at half height) */
|
|
|
|
display->putsxy(vp->width/6 - w/2, vp->height/2 - h/2, ptr);
|
|
|
|
/* one OK in the middle of the last column of the vp (at half height) */
|
|
|
|
display->putsxy(5*vp->width/6 - w/2, vp->height/2 - h/2, ptr);
|
|
|
|
#endif
|
2009-07-11 16:46:19 +00:00
|
|
|
if (global_settings.pitch_mode_semitone)
|
2008-05-05 07:07:19 +00:00
|
|
|
ptr = str(LANG_PITCH_DOWN_SEMITONE);
|
2009-06-12 07:20:50 +00:00
|
|
|
else
|
|
|
|
ptr = str(LANG_PITCH_DOWN);
|
2010-10-25 21:20:04 +00:00
|
|
|
display->getstringsize(ptr, &w, &h);
|
2008-10-05 13:01:54 +00:00
|
|
|
/* draw text */
|
2010-10-25 21:20:04 +00:00
|
|
|
display->putsxy(vp->width/2 - w/2, vp->height - h, ptr);
|
2009-01-28 20:14:01 +00:00
|
|
|
display->update_viewport();
|
2008-10-05 13:01:54 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 07:20:50 +00:00
|
|
|
/* Middle section */
|
|
|
|
display->set_viewport(&pitch_viewports[PITCH_MID]);
|
2008-10-05 13:01:54 +00:00
|
|
|
display->clear_viewport();
|
2009-06-12 07:20:50 +00:00
|
|
|
int width_used = 0;
|
|
|
|
|
|
|
|
/* Middle section upper line - hide for a small screen */
|
2008-10-05 13:01:54 +00:00
|
|
|
if ((show_lang_pitch = (max_lines >= 3)))
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
/* Pitch:XXX.X% */
|
|
|
|
if(global_settings.pitch_mode_semitone)
|
|
|
|
{
|
2010-05-06 21:04:40 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s: %s%d.%02d", str(LANG_PITCH),
|
2009-07-11 16:46:19 +00:00
|
|
|
semitone >= 0 ? "+" : "-",
|
2010-05-06 21:04:40 +00:00
|
|
|
abs(semitone / PITCH_SPEED_PRECISION),
|
|
|
|
abs((semitone % PITCH_SPEED_PRECISION) /
|
2009-07-11 16:46:19 +00:00
|
|
|
(PITCH_SPEED_PRECISION / 100))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_PITCH),
|
|
|
|
pitch / PITCH_SPEED_PRECISION,
|
|
|
|
(pitch % PITCH_SPEED_PRECISION) /
|
|
|
|
(PITCH_SPEED_PRECISION / 10));
|
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
|
|
|
else
|
2009-07-11 16:46:19 +00:00
|
|
|
#endif
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
/* Rate */
|
|
|
|
snprintf(buf, sizeof(buf), "%s:", str(LANG_PLAYBACK_RATE));
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
|
|
|
display->getstringsize(buf, &w, &h);
|
2009-07-11 16:46:19 +00:00
|
|
|
display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2),
|
|
|
|
(pitch_viewports[PITCH_MID].height / 2) - h, buf);
|
2009-06-12 07:20:50 +00:00
|
|
|
if (w > width_used)
|
|
|
|
width_used = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Middle section lower line */
|
2009-07-11 16:46:19 +00:00
|
|
|
/* "Speed:XXX%" */
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s: %ld.%ld%%", str(LANG_SPEED),
|
|
|
|
speed / PITCH_SPEED_PRECISION,
|
|
|
|
(speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
|
|
|
else
|
2009-07-11 16:46:19 +00:00
|
|
|
#endif
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_semitone)
|
|
|
|
{
|
2010-05-06 21:04:40 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s%d.%02d",
|
2009-07-11 16:46:19 +00:00
|
|
|
semitone >= 0 ? "+" : "-",
|
2010-05-06 21:04:40 +00:00
|
|
|
abs(semitone / PITCH_SPEED_PRECISION),
|
|
|
|
abs((semitone % PITCH_SPEED_PRECISION) /
|
2009-07-11 16:46:19 +00:00
|
|
|
(PITCH_SPEED_PRECISION / 100))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%ld.%ld%%",
|
|
|
|
pitch / PITCH_SPEED_PRECISION,
|
|
|
|
(pitch % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
|
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
2009-07-11 16:46:19 +00:00
|
|
|
|
2009-06-12 07:20:50 +00:00
|
|
|
display->getstringsize(buf, &w, &h);
|
|
|
|
display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2),
|
2009-07-11 16:46:19 +00:00
|
|
|
show_lang_pitch ? (pitch_viewports[PITCH_MID].height / 2) :
|
|
|
|
(pitch_viewports[PITCH_MID].height / 2) - (h / 2),
|
|
|
|
buf);
|
2009-06-12 07:20:50 +00:00
|
|
|
if (w > width_used)
|
|
|
|
width_used = w;
|
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
/* "limit" and "timestretch" labels */
|
|
|
|
if (max_lines >= 7)
|
|
|
|
{
|
|
|
|
if(at_limit)
|
|
|
|
{
|
2009-10-10 09:57:03 +00:00
|
|
|
const char * const p = str(LANG_STRETCH_LIMIT);
|
|
|
|
display->getstringsize(p, &w, &h);
|
2009-07-11 16:46:19 +00:00
|
|
|
display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2),
|
2009-10-10 09:57:03 +00:00
|
|
|
(pitch_viewports[PITCH_MID].height / 2) + h, p);
|
2009-07-11 16:46:19 +00:00
|
|
|
if (w > width_used)
|
|
|
|
width_used = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 07:20:50 +00:00
|
|
|
/* Middle section left/right labels */
|
|
|
|
const char *leftlabel = "-2%";
|
|
|
|
const char *rightlabel = "+2%";
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
if (global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
|
|
|
leftlabel = "<<";
|
|
|
|
rightlabel = ">>";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Only display if they fit */
|
|
|
|
display->getstringsize(leftlabel, &w, &h);
|
|
|
|
width_used += w;
|
|
|
|
display->getstringsize(rightlabel, &w, &h);
|
|
|
|
width_used += w;
|
|
|
|
|
|
|
|
if (width_used <= pitch_viewports[PITCH_MID].width)
|
2008-10-05 13:01:54 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
display->putsxy(0, (pitch_viewports[PITCH_MID].height / 2) - (h / 2),
|
|
|
|
leftlabel);
|
|
|
|
display->putsxy((pitch_viewports[PITCH_MID].width - w),
|
|
|
|
(pitch_viewports[PITCH_MID].height / 2) - (h / 2),
|
|
|
|
rightlabel);
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
2009-01-28 20:14:01 +00:00
|
|
|
display->update_viewport();
|
2008-10-05 13:01:54 +00:00
|
|
|
display->set_viewport(NULL);
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
static int32_t pitch_increase(int32_t pitch, int32_t pitch_delta, bool allow_cutoff
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* need this to maintain correct pitch/speed caps */
|
|
|
|
, int32_t speed
|
|
|
|
#endif
|
|
|
|
)
|
2008-05-05 07:07:19 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
int32_t new_pitch;
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
int32_t new_stretch;
|
|
|
|
#endif
|
|
|
|
at_limit = false;
|
2008-06-28 20:45:21 +00:00
|
|
|
|
2009-06-12 07:20:50 +00:00
|
|
|
if (pitch_delta < 0)
|
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
/* for large jumps, snap up to whole numbers */
|
|
|
|
if(allow_cutoff && pitch_delta <= -PITCH_SPEED_PRECISION &&
|
|
|
|
(pitch + pitch_delta) % PITCH_SPEED_PRECISION != 0)
|
|
|
|
{
|
|
|
|
pitch_delta += PITCH_SPEED_PRECISION - ((pitch + pitch_delta) % PITCH_SPEED_PRECISION);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_pitch = pitch + pitch_delta;
|
|
|
|
|
|
|
|
if (new_pitch < PITCH_MIN)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
|
|
|
if (!allow_cutoff)
|
2009-07-11 16:46:19 +00:00
|
|
|
{
|
2008-05-05 07:07:19 +00:00
|
|
|
return pitch;
|
2009-07-11 16:46:19 +00:00
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
new_pitch = PITCH_MIN;
|
2009-07-11 16:46:19 +00:00
|
|
|
at_limit = true;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
|
|
|
else if (pitch_delta > 0)
|
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
/* for large jumps, snap down to whole numbers */
|
|
|
|
if(allow_cutoff && pitch_delta >= PITCH_SPEED_PRECISION &&
|
|
|
|
(pitch + pitch_delta) % PITCH_SPEED_PRECISION != 0)
|
|
|
|
{
|
|
|
|
pitch_delta -= (pitch + pitch_delta) % PITCH_SPEED_PRECISION;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_pitch = pitch + pitch_delta;
|
|
|
|
|
|
|
|
if (new_pitch > PITCH_MAX)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
|
|
|
if (!allow_cutoff)
|
2008-05-05 07:07:19 +00:00
|
|
|
return pitch;
|
|
|
|
new_pitch = PITCH_MAX;
|
2009-07-11 16:46:19 +00:00
|
|
|
at_limit = true;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* pitch_delta == 0 -> no real change */
|
2008-05-05 07:07:19 +00:00
|
|
|
return pitch;
|
|
|
|
}
|
2009-07-11 16:46:19 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if (dsp_timestretch_available())
|
|
|
|
{
|
|
|
|
/* increase the multiple to increase precision of this calculation */
|
|
|
|
new_stretch = GET_STRETCH(new_pitch, speed);
|
|
|
|
if(new_stretch < STRETCH_MIN)
|
|
|
|
{
|
|
|
|
/* we have to ignore allow_cutoff, because we can't have the */
|
|
|
|
/* stretch go higher than STRETCH_MAX */
|
|
|
|
new_pitch = GET_PITCH(speed, STRETCH_MIN);
|
|
|
|
}
|
|
|
|
else if(new_stretch > STRETCH_MAX)
|
|
|
|
{
|
|
|
|
/* we have to ignore allow_cutoff, because we can't have the */
|
|
|
|
/* stretch go higher than STRETCH_MAX */
|
|
|
|
new_pitch = GET_PITCH(speed, STRETCH_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(new_stretch >= STRETCH_MAX ||
|
|
|
|
new_stretch <= STRETCH_MIN)
|
|
|
|
{
|
|
|
|
at_limit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-05 07:07:19 +00:00
|
|
|
sound_set_pitch(new_pitch);
|
|
|
|
|
|
|
|
return new_pitch;
|
|
|
|
}
|
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
static int32_t get_semitone_from_pitch(int32_t pitch)
|
2008-05-05 07:07:19 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
int semitone = 0;
|
|
|
|
int32_t fractional_index = 0;
|
|
|
|
|
|
|
|
while(semitone < NUM_SEMITONES - 1 &&
|
|
|
|
pitch >= semitone_table[semitone + 1])
|
|
|
|
{
|
|
|
|
semitone++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* now find the fractional part */
|
|
|
|
while(pitch > (cent_interp[fractional_index + 1] *
|
|
|
|
semitone_table[semitone] / PITCH_SPEED_100))
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
/* Check to make sure fractional_index isn't too big */
|
|
|
|
/* This should never happen. */
|
|
|
|
if(fractional_index >= CENT_INTERP_NUM - 1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fractional_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t semitone_pitch_a = cent_interp[fractional_index] *
|
|
|
|
semitone_table[semitone] /
|
|
|
|
PITCH_SPEED_100;
|
|
|
|
int32_t semitone_pitch_b = cent_interp[fractional_index + 1] *
|
|
|
|
semitone_table[semitone] /
|
|
|
|
PITCH_SPEED_100;
|
|
|
|
/* this will be the integer offset from the cent_interp entry */
|
|
|
|
int32_t semitone_frac_ofs = (pitch - semitone_pitch_a) * CENT_INTERP_INTERVAL /
|
|
|
|
(semitone_pitch_b - semitone_pitch_a);
|
|
|
|
semitone = (semitone + SEMITONE_START) * PITCH_SPEED_PRECISION +
|
|
|
|
fractional_index * CENT_INTERP_INTERVAL +
|
|
|
|
semitone_frac_ofs;
|
|
|
|
|
|
|
|
return semitone;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t get_pitch_from_semitone(int32_t semitone)
|
|
|
|
{
|
|
|
|
int32_t adjusted_semitone = semitone - SEMITONE_START * PITCH_SPEED_PRECISION;
|
|
|
|
|
|
|
|
/* Find the index into the semitone table */
|
|
|
|
int32_t semitone_index = (adjusted_semitone / PITCH_SPEED_PRECISION);
|
|
|
|
|
|
|
|
/* set pitch to the semitone's integer part value */
|
|
|
|
int32_t pitch = semitone_table[semitone_index];
|
|
|
|
/* get the range of the cent modification for future calculation */
|
|
|
|
int32_t pitch_mod_a =
|
|
|
|
cent_interp[(adjusted_semitone % PITCH_SPEED_PRECISION) /
|
|
|
|
CENT_INTERP_INTERVAL];
|
|
|
|
int32_t pitch_mod_b =
|
|
|
|
cent_interp[(adjusted_semitone % PITCH_SPEED_PRECISION) /
|
|
|
|
CENT_INTERP_INTERVAL + 1];
|
|
|
|
/* figure out the cent mod amount based on the semitone fractional value */
|
|
|
|
int32_t pitch_mod = pitch_mod_a + (pitch_mod_b - pitch_mod_a) *
|
|
|
|
(adjusted_semitone % CENT_INTERP_INTERVAL) / CENT_INTERP_INTERVAL;
|
|
|
|
|
|
|
|
/* modify pitch based on the mod amount we just calculated */
|
|
|
|
return (pitch * pitch_mod + PITCH_SPEED_100 / 2) / PITCH_SPEED_100;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t pitch_increase_semitone(int32_t pitch,
|
|
|
|
int32_t current_semitone,
|
|
|
|
int32_t semitone_delta
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, int32_t speed
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int32_t new_semitone = current_semitone;
|
|
|
|
|
|
|
|
/* snap to the delta interval */
|
|
|
|
if(current_semitone % semitone_delta != 0)
|
|
|
|
{
|
|
|
|
if(current_semitone > 0 && semitone_delta > 0)
|
|
|
|
new_semitone += semitone_delta;
|
|
|
|
else if(current_semitone < 0 && semitone_delta < 0)
|
|
|
|
new_semitone += semitone_delta;
|
|
|
|
|
|
|
|
new_semitone -= new_semitone % semitone_delta;
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
|
|
|
else
|
2009-07-11 16:46:19 +00:00
|
|
|
new_semitone += semitone_delta;
|
|
|
|
|
|
|
|
/* clamp the pitch so it doesn't go beyond the pitch limits */
|
|
|
|
if(new_semitone < (SEMITONE_START * PITCH_SPEED_PRECISION))
|
|
|
|
{
|
|
|
|
new_semitone = SEMITONE_START * PITCH_SPEED_PRECISION;
|
|
|
|
at_limit = true;
|
|
|
|
}
|
|
|
|
else if(new_semitone > (SEMITONE_END * PITCH_SPEED_PRECISION))
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
new_semitone = SEMITONE_END * PITCH_SPEED_PRECISION;
|
|
|
|
at_limit = true;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
2009-07-11 16:46:19 +00:00
|
|
|
|
|
|
|
int32_t new_pitch = get_pitch_from_semitone(new_semitone);
|
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
int32_t new_stretch = GET_STRETCH(new_pitch, speed);
|
|
|
|
|
|
|
|
/* clamp the pitch so it doesn't go beyond the stretch limits */
|
|
|
|
if( new_stretch > STRETCH_MAX)
|
|
|
|
{
|
|
|
|
new_pitch = GET_PITCH(speed, STRETCH_MAX);
|
|
|
|
new_semitone = get_semitone_from_pitch(new_pitch);
|
|
|
|
at_limit = true;
|
|
|
|
}
|
|
|
|
else if (new_stretch < STRETCH_MIN)
|
|
|
|
{
|
|
|
|
new_pitch = GET_PITCH(speed, STRETCH_MIN);
|
|
|
|
new_semitone = get_semitone_from_pitch(new_pitch);
|
|
|
|
at_limit = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pitch_increase(pitch, new_pitch - pitch, false
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
return new_semitone;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 21:20:04 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
/*
|
|
|
|
* Check for touchscreen presses as per sketch above in this file
|
|
|
|
*
|
|
|
|
* goes through each row of the, checks whether the touchscreen
|
|
|
|
* was pressed in it. Then it looks the columns of each row for specific actions
|
|
|
|
*/
|
|
|
|
static int pitchscreen_do_touchscreen(struct viewport vps[])
|
|
|
|
{
|
|
|
|
short x, y;
|
|
|
|
struct viewport *this_vp = &vps[PITCH_TOP];
|
|
|
|
int ret;
|
2011-01-29 15:34:36 +00:00
|
|
|
static bool wait_for_release = false;
|
2010-10-25 21:20:04 +00:00
|
|
|
ret = action_get_touchscreen_press_in_vp(&x, &y, this_vp);
|
|
|
|
|
|
|
|
/* top row */
|
|
|
|
if (ret > ACTION_UNKNOWN)
|
|
|
|
{ /* press on top row, left or right column
|
|
|
|
* only toggle mode if released */
|
|
|
|
int column = this_vp->width / 3;
|
|
|
|
if ((x < column || x > (2*column)) && (ret == BUTTON_REL))
|
|
|
|
return ACTION_PS_TOGGLE_MODE;
|
|
|
|
|
|
|
|
|
|
|
|
else if (x >= column && x <= (2*column))
|
|
|
|
{ /* center column pressed */
|
|
|
|
if (ret == BUTTON_REPEAT)
|
|
|
|
return ACTION_PS_INC_BIG;
|
2011-01-29 15:34:36 +00:00
|
|
|
else if (ret & BUTTON_REL)
|
2010-10-25 21:20:04 +00:00
|
|
|
return ACTION_PS_INC_SMALL;
|
|
|
|
}
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now the center row */
|
|
|
|
this_vp = &vps[PITCH_MID];
|
|
|
|
ret = action_get_touchscreen_press_in_vp(&x, &y, this_vp);
|
|
|
|
|
|
|
|
if (ret > ACTION_UNKNOWN)
|
|
|
|
{
|
|
|
|
int column = this_vp->width / 3;
|
|
|
|
|
|
|
|
if (x < column)
|
|
|
|
{ /* left column */
|
|
|
|
if (ret & BUTTON_REL)
|
2011-01-29 15:34:36 +00:00
|
|
|
{
|
|
|
|
wait_for_release = false;
|
2010-10-25 21:20:04 +00:00
|
|
|
return ACTION_PS_NUDGE_LEFTOFF;
|
2011-01-29 15:34:36 +00:00
|
|
|
}
|
2010-10-25 21:20:04 +00:00
|
|
|
else if (ret & BUTTON_REPEAT)
|
|
|
|
return ACTION_PS_SLOWER;
|
2011-01-29 15:34:36 +00:00
|
|
|
if (!wait_for_release)
|
|
|
|
{
|
|
|
|
wait_for_release = true;
|
|
|
|
return ACTION_PS_NUDGE_LEFT;
|
|
|
|
}
|
2010-10-25 21:20:04 +00:00
|
|
|
}
|
|
|
|
else if (x > (2*column))
|
|
|
|
{ /* right column */
|
|
|
|
if (ret & BUTTON_REL)
|
2011-01-29 15:34:36 +00:00
|
|
|
{
|
|
|
|
wait_for_release = false;
|
2011-02-01 15:01:44 +00:00
|
|
|
return ACTION_PS_NUDGE_RIGHTOFF;
|
2011-01-29 15:34:36 +00:00
|
|
|
}
|
2010-10-25 21:20:04 +00:00
|
|
|
else if (ret & BUTTON_REPEAT)
|
|
|
|
return ACTION_PS_FASTER;
|
2011-01-29 15:34:36 +00:00
|
|
|
if (!wait_for_release)
|
|
|
|
{
|
|
|
|
wait_for_release = true;
|
2011-02-01 15:01:44 +00:00
|
|
|
return ACTION_PS_NUDGE_RIGHT;
|
2011-01-29 15:34:36 +00:00
|
|
|
}
|
2010-10-25 21:20:04 +00:00
|
|
|
}
|
2011-01-29 15:34:36 +00:00
|
|
|
else
|
|
|
|
/* center column was pressed */
|
|
|
|
return ACTION_PS_RESET;
|
2010-10-25 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now the bottom row */
|
|
|
|
this_vp = &vps[PITCH_BOTTOM];
|
|
|
|
ret = action_get_touchscreen_press_in_vp(&x, &y, this_vp);
|
|
|
|
|
|
|
|
if (ret > ACTION_UNKNOWN)
|
|
|
|
{
|
|
|
|
int column = this_vp->width / 3;
|
|
|
|
|
|
|
|
/* left or right column is exit */
|
|
|
|
if ((x < column || x > (2*column)) && (ret == BUTTON_REL))
|
|
|
|
return ACTION_PS_EXIT;
|
|
|
|
else if (x >= column && x <= (2*column))
|
|
|
|
{ /* center column was pressed */
|
2011-01-29 15:34:36 +00:00
|
|
|
if (ret & BUTTON_REPEAT)
|
2010-10-25 21:20:04 +00:00
|
|
|
return ACTION_PS_DEC_BIG;
|
2011-01-29 15:34:36 +00:00
|
|
|
else if (ret & BUTTON_REL)
|
2010-10-25 21:20:04 +00:00
|
|
|
return ACTION_PS_DEC_SMALL;
|
|
|
|
}
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2008-10-05 13:01:54 +00:00
|
|
|
/*
|
|
|
|
returns:
|
|
|
|
0 on exit
|
|
|
|
1 if USB was connected
|
|
|
|
*/
|
|
|
|
|
|
|
|
int gui_syncpitchscreen_run(void)
|
2008-05-05 07:07:19 +00:00
|
|
|
{
|
2009-01-28 20:14:01 +00:00
|
|
|
int button, i;
|
2009-07-11 16:46:19 +00:00
|
|
|
int32_t pitch = sound_get_pitch();
|
|
|
|
int32_t semitone;
|
|
|
|
|
|
|
|
int32_t new_pitch;
|
|
|
|
int32_t pitch_delta;
|
2008-05-05 07:07:19 +00:00
|
|
|
bool nudged = false;
|
|
|
|
bool exit = false;
|
2009-01-28 20:14:01 +00:00
|
|
|
/* should maybe be passed per parameter later, not needed for now */
|
|
|
|
struct viewport parent[NB_SCREENS];
|
2008-10-05 13:01:54 +00:00
|
|
|
struct viewport pitch_viewports[NB_SCREENS][PITCH_ITEM_COUNT];
|
2009-01-28 20:14:01 +00:00
|
|
|
int max_lines[NB_SCREENS];
|
2008-05-05 07:07:19 +00:00
|
|
|
|
2011-06-13 07:33:20 +00:00
|
|
|
push_current_activity(ACTIVITY_PITCHSCREEN);
|
|
|
|
|
2009-07-11 16:46:19 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
int32_t new_speed = 0, new_stretch;
|
|
|
|
|
|
|
|
/* the speed variable holds the apparent speed of the playback */
|
|
|
|
int32_t speed;
|
|
|
|
if (dsp_timestretch_available())
|
|
|
|
{
|
|
|
|
speed = GET_SPEED(pitch, dsp_get_timestretch());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
speed = pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out whether to be in timestretch mode */
|
|
|
|
if (global_settings.pitch_mode_timestretch && !dsp_timestretch_available())
|
|
|
|
{
|
|
|
|
global_settings.pitch_mode_timestretch = false;
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* set the semitone index based on the current pitch */
|
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
|
|
|
|
2008-10-05 13:01:54 +00:00
|
|
|
/* initialize pitchscreen vps */
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
viewport_set_defaults(&parent[i], i);
|
|
|
|
max_lines[i] = viewport_get_nb_lines(&parent[i]);
|
2008-10-05 13:45:21 +00:00
|
|
|
pitchscreen_fix_viewports(&parent[i], pitch_viewports[i]);
|
2009-10-15 21:13:58 +00:00
|
|
|
screens[i].set_viewport(&parent[i]);
|
|
|
|
screens[i].clear_viewport();
|
2008-10-05 13:01:54 +00:00
|
|
|
|
|
|
|
/* also, draw the icons now, it's only needed once */
|
|
|
|
pitchscreen_draw_icons(&screens[i], &parent[i]);
|
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
pcmbuf_set_low_latency(true);
|
|
|
|
#endif
|
2009-01-28 20:14:01 +00:00
|
|
|
|
2008-05-05 07:07:19 +00:00
|
|
|
while (!exit)
|
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i)
|
2008-10-05 13:01:54 +00:00
|
|
|
pitchscreen_draw(&screens[i], max_lines[i],
|
2009-07-11 16:46:19 +00:00
|
|
|
pitch_viewports[i], pitch, semitone
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-06-22 18:52:14 +00:00
|
|
|
, speed
|
2009-06-12 07:20:50 +00:00
|
|
|
#endif
|
|
|
|
);
|
2009-06-19 11:23:02 +00:00
|
|
|
pitch_delta = 0;
|
2009-07-11 16:46:19 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
new_speed = 0;
|
|
|
|
#endif
|
2009-06-12 07:20:50 +00:00
|
|
|
button = get_action(CONTEXT_PITCHSCREEN, HZ);
|
2010-10-25 21:20:04 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
if (button == ACTION_TOUCHSCREEN)
|
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
button = pitchscreen_do_touchscreen(pitch_viewports[i]);
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-12 07:20:50 +00:00
|
|
|
switch (button)
|
|
|
|
{
|
2008-05-05 07:07:19 +00:00
|
|
|
case ACTION_PS_INC_SMALL:
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_semitone)
|
|
|
|
pitch_delta = SEMITONE_SMALL_DELTA;
|
|
|
|
else
|
|
|
|
pitch_delta = PITCH_SMALL_DELTA;
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_INC_BIG:
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_semitone)
|
|
|
|
pitch_delta = SEMITONE_BIG_DELTA;
|
|
|
|
else
|
|
|
|
pitch_delta = PITCH_BIG_DELTA;
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_DEC_SMALL:
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_semitone)
|
|
|
|
pitch_delta = -SEMITONE_SMALL_DELTA;
|
|
|
|
else
|
|
|
|
pitch_delta = -PITCH_SMALL_DELTA;
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_DEC_BIG:
|
2009-07-11 16:46:19 +00:00
|
|
|
if(global_settings.pitch_mode_semitone)
|
|
|
|
pitch_delta = -SEMITONE_BIG_DELTA;
|
|
|
|
else
|
|
|
|
pitch_delta = -PITCH_BIG_DELTA;
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_NUDGE_RIGHT:
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
if (!global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
|
|
|
#endif
|
2009-07-11 16:46:19 +00:00
|
|
|
new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
2009-06-12 07:20:50 +00:00
|
|
|
nudged = (new_pitch != pitch);
|
|
|
|
pitch = new_pitch;
|
2009-07-11 16:46:19 +00:00
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
speed = pitch;
|
|
|
|
#endif
|
2009-06-12 07:20:50 +00:00
|
|
|
break;
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
}
|
2009-07-11 16:46:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
new_speed = speed + SPEED_SMALL_DELTA;
|
|
|
|
at_limit = false;
|
|
|
|
}
|
|
|
|
break;
|
2009-06-12 07:20:50 +00:00
|
|
|
|
|
|
|
case ACTION_PS_FASTER:
|
2009-07-11 16:46:19 +00:00
|
|
|
if (global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
new_speed = speed + SPEED_BIG_DELTA;
|
|
|
|
/* snap to whole numbers */
|
|
|
|
if(new_speed % PITCH_SPEED_PRECISION != 0)
|
|
|
|
new_speed -= new_speed % PITCH_SPEED_PRECISION;
|
|
|
|
at_limit = false;
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
2009-06-12 07:20:50 +00:00
|
|
|
#endif
|
2008-05-05 07:07:19 +00:00
|
|
|
|
|
|
|
case ACTION_PS_NUDGE_RIGHTOFF:
|
2009-06-12 07:20:50 +00:00
|
|
|
if (nudged)
|
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
speed = pitch;
|
|
|
|
#endif
|
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
2009-06-12 07:20:50 +00:00
|
|
|
nudged = false;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_NUDGE_LEFT:
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
if (!global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
|
|
|
#endif
|
2009-07-11 16:46:19 +00:00
|
|
|
new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
2009-06-12 07:20:50 +00:00
|
|
|
nudged = (new_pitch != pitch);
|
|
|
|
pitch = new_pitch;
|
2009-07-11 16:46:19 +00:00
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
speed = pitch;
|
|
|
|
#endif
|
2009-06-12 07:20:50 +00:00
|
|
|
break;
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
}
|
2009-07-11 16:46:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
new_speed = speed - SPEED_SMALL_DELTA;
|
|
|
|
at_limit = false;
|
|
|
|
}
|
|
|
|
break;
|
2009-06-12 07:20:50 +00:00
|
|
|
|
|
|
|
case ACTION_PS_SLOWER:
|
2009-07-11 16:46:19 +00:00
|
|
|
if (global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
new_speed = speed - SPEED_BIG_DELTA;
|
|
|
|
/* snap to whole numbers */
|
|
|
|
if(new_speed % PITCH_SPEED_PRECISION != 0)
|
|
|
|
new_speed += PITCH_SPEED_PRECISION - speed % PITCH_SPEED_PRECISION;
|
|
|
|
at_limit = false;
|
2009-06-12 07:20:50 +00:00
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
2009-06-12 07:20:50 +00:00
|
|
|
#endif
|
2008-09-07 20:09:11 +00:00
|
|
|
|
2008-05-05 07:07:19 +00:00
|
|
|
case ACTION_PS_NUDGE_LEFTOFF:
|
2009-06-12 07:20:50 +00:00
|
|
|
if (nudged)
|
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
speed = pitch;
|
|
|
|
#endif
|
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
2009-06-12 07:20:50 +00:00
|
|
|
nudged = false;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_RESET:
|
2009-07-11 16:46:19 +00:00
|
|
|
pitch = PITCH_SPEED_100;
|
2009-06-12 07:20:50 +00:00
|
|
|
sound_set_pitch(pitch);
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
speed = PITCH_SPEED_100;
|
|
|
|
if (dsp_timestretch_available())
|
|
|
|
{
|
|
|
|
dsp_set_timestretch(PITCH_SPEED_100);
|
|
|
|
at_limit = false;
|
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
#endif
|
2009-07-11 16:46:19 +00:00
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_TOGGLE_MODE:
|
2009-07-11 16:46:19 +00:00
|
|
|
global_settings.pitch_mode_semitone = !global_settings.pitch_mode_semitone;
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
|
|
|
|
if (dsp_timestretch_available() && !global_settings.pitch_mode_semitone)
|
|
|
|
{
|
|
|
|
global_settings.pitch_mode_timestretch = !global_settings.pitch_mode_timestretch;
|
|
|
|
if(!global_settings.pitch_mode_timestretch)
|
|
|
|
{
|
|
|
|
/* no longer in timestretch mode. Reset speed */
|
|
|
|
speed = pitch;
|
|
|
|
dsp_set_timestretch(PITCH_SPEED_100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings_save();
|
2009-06-12 07:20:50 +00:00
|
|
|
#endif
|
2008-05-05 07:07:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_PS_EXIT:
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-06-12 07:20:50 +00:00
|
|
|
if (default_event_handler(button) == SYS_USB_CONNECTED)
|
2008-05-05 07:07:19 +00:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
if (pitch_delta)
|
2008-05-05 07:07:19 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
if (global_settings.pitch_mode_semitone)
|
|
|
|
{
|
|
|
|
semitone = pitch_increase_semitone(pitch, semitone, pitch_delta
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
pitch = get_pitch_from_semitone(semitone);
|
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
else
|
2009-07-11 16:46:19 +00:00
|
|
|
{
|
|
|
|
pitch = pitch_increase(pitch, pitch_delta, true
|
2009-06-12 07:20:50 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2009-07-11 16:46:19 +00:00
|
|
|
, speed
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
semitone = get_semitone_from_pitch(pitch);
|
|
|
|
}
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if (global_settings.pitch_mode_timestretch)
|
2009-06-12 07:20:50 +00:00
|
|
|
{
|
2009-07-11 16:46:19 +00:00
|
|
|
/* do this to make sure we properly obey the stretch limits */
|
|
|
|
new_speed = speed;
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
2009-06-12 07:20:50 +00:00
|
|
|
else
|
2009-07-11 16:46:19 +00:00
|
|
|
{
|
|
|
|
speed = pitch;
|
|
|
|
}
|
|
|
|
#endif
|
2008-05-05 07:07:19 +00:00
|
|
|
}
|
2009-07-11 16:46:19 +00:00
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if(new_speed)
|
|
|
|
{
|
|
|
|
new_stretch = GET_STRETCH(pitch, new_speed);
|
|
|
|
|
|
|
|
/* limit the amount of stretch */
|
|
|
|
if(new_stretch > STRETCH_MAX)
|
|
|
|
{
|
|
|
|
new_stretch = STRETCH_MAX;
|
|
|
|
new_speed = GET_SPEED(pitch, new_stretch);
|
|
|
|
}
|
|
|
|
else if(new_stretch < STRETCH_MIN)
|
|
|
|
{
|
|
|
|
new_stretch = STRETCH_MIN;
|
|
|
|
new_speed = GET_SPEED(pitch, new_stretch);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_stretch = GET_STRETCH(pitch, new_speed);
|
|
|
|
if(new_stretch >= STRETCH_MAX ||
|
|
|
|
new_stretch <= STRETCH_MIN)
|
|
|
|
{
|
|
|
|
at_limit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the amount of stretch */
|
|
|
|
dsp_set_timestretch(new_stretch);
|
|
|
|
|
|
|
|
/* update the speed variable with the new speed */
|
|
|
|
speed = new_speed;
|
|
|
|
|
|
|
|
/* Reset new_speed so we only call dsp_set_timestretch */
|
|
|
|
/* when needed */
|
|
|
|
new_speed = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2009-10-15 21:35:10 +00:00
|
|
|
}
|
2008-05-05 07:07:19 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
pcmbuf_set_low_latency(false);
|
|
|
|
#endif
|
2011-06-13 07:33:20 +00:00
|
|
|
pop_current_activity();
|
2008-05-05 07:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|