summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-05-22 12:45:35 +0000
committerJens Arnold <amiconn@rockbox.org>2005-05-22 12:45:35 +0000
commitb9ebe6af0aad5f3defa797f87b0c5297f317171e (patch)
treede0ad32c3d203eeb921c39c37b827949872f0fab
parent8f1ace7525057b6dfe8b6be96c987d6449057524 (diff)
Better pitch handling.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6503 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/screens.c28
-rw-r--r--firmware/export/sound.h3
-rw-r--r--firmware/sound.c32
3 files changed, 32 insertions, 31 deletions
diff --git a/apps/screens.c b/apps/screens.c
index 7c00e9481d..3c53b4e120 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -389,7 +389,7 @@ int charging_screen(void)
int pitch_screen(void)
{
int button;
- static int pitch = 1000;
+ int pitch = sound_get_pitch();
bool exit = false;
bool used = false;
@@ -436,9 +436,8 @@ int pitch_screen(void)
case BUTTON_ON | BUTTON_UP:
case BUTTON_ON | BUTTON_UP | BUTTON_REPEAT:
used = true;
- pitch++;
- if ( pitch > 2000 )
- pitch = 2000;
+ if ( pitch < 2000 )
+ pitch++;
sound_set_pitch(pitch);
break;
@@ -446,9 +445,8 @@ int pitch_screen(void)
case BUTTON_ON | BUTTON_DOWN:
case BUTTON_ON | BUTTON_DOWN | BUTTON_REPEAT:
used = true;
- pitch--;
- if ( pitch < 500 )
- pitch = 500;
+ if ( pitch > 500 )
+ pitch--;
sound_set_pitch(pitch);
break;
@@ -468,33 +466,21 @@ int pitch_screen(void)
break;
case BUTTON_ON | BUTTON_RIGHT:
+ case BUTTON_LEFT | BUTTON_REL:
if ( pitch < 2000 ) {
pitch += 20;
sound_set_pitch(pitch);
}
break;
- case BUTTON_RIGHT | BUTTON_REL:
- if ( pitch > 500 ) {
- pitch -= 20;
- sound_set_pitch(pitch);
- }
- break;
-
case BUTTON_ON | BUTTON_LEFT:
+ case BUTTON_RIGHT | BUTTON_REL:
if ( pitch > 500 ) {
pitch -= 20;
sound_set_pitch(pitch);
}
break;
- case BUTTON_LEFT | BUTTON_REL:
- if ( pitch < 2000 ) {
- pitch += 20;
- sound_set_pitch(pitch);
- }
- break;
-
#ifdef SIMULATOR
case BUTTON_ON:
#else
diff --git a/firmware/export/sound.h b/firmware/export/sound.h
index 2fa00d88a9..9f4cd60ae8 100644
--- a/firmware/export/sound.h
+++ b/firmware/export/sound.h
@@ -55,7 +55,8 @@ const char *sound_unit(int setting);
int sound_numdecimals(int setting);
int sound_steps(int setting);
#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) || defined(SIMULATOR)
-void sound_set_pitch(int percent);
+void sound_set_pitch(int permille);
+int sound_get_pitch(void);
#endif
#endif
diff --git a/firmware/sound.c b/firmware/sound.c
index ab0ab1ed46..0fb54861c9 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -602,27 +602,41 @@ int sound_val2phys(int setting, int value)
The pitch value is in tenths of percent.
*/
+static int last_pitch = 1000;
+
void sound_set_pitch(int pitch)
{
unsigned long val;
- /* invert pitch value */
- pitch = 1000000/pitch;
-
- /* Calculate the new (bogus) frequency */
- val = 18432*pitch/1000;
+ if (pitch != last_pitch)
+ {
+ /* Calculate the new (bogus) frequency */
+ val = 18432 * 1000 / pitch;
- mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1);
+ mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1);
- /* We must tell the MAS that the frequency has changed.
- This will unfortunately cause a short silence. */
- mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1);
+ /* We must tell the MAS that the frequency has changed.
+ * This will unfortunately cause a short silence. */
+ mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1);
+
+ last_pitch = pitch;
+ }
+}
+
+int sound_get_pitch(void)
+{
+ return last_pitch;
}
#elif defined SIMULATOR
void sound_set_pitch(int pitch)
{
(void)pitch;
}
+
+int sound_get_pitch(void)
+{
+ return 1000;
+}
#endif
#if CONFIG_HWCODEC == MASNONE