First step towards a better sound setting API

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1243 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-06-28 11:48:53 +00:00
parent b983d1b4a1
commit 667fb7c6e9
5 changed files with 187 additions and 48 deletions

View file

@ -84,10 +84,10 @@ extern struct user_settings global_settings;
/* system defines */
#define DEFAULT_VOLUME_SETTING 70
#define DEFAULT_VOLUME_SETTING 70/2
#define DEFAULT_BALANCE_SETTING 50
#define DEFAULT_BASS_SETTING 50
#define DEFAULT_TREBLE_SETTING 50
#define DEFAULT_BASS_SETTING 50/2
#define DEFAULT_TREBLE_SETTING 50/2
#define DEFAULT_LOUDNESS_SETTING 0
#define DEFAULT_BASS_BOOST_SETTING 0
#define DEFAULT_CONTRAST_SETTING 0

View file

@ -19,23 +19,83 @@
#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include "lcd.h"
#include "menu.h"
#include "button.h"
#include "mpeg.h"
#include "settings.h"
void set_sound(char* string,
int* variable,
int setting)
{
bool done = false;
int min, max;
int val;
char* unit;
char str[32];
unit = mpeg_sound_unit(setting);
min = mpeg_sound_min(setting);
max = mpeg_sound_max(setting);
lcd_clear_display();
lcd_puts_scroll(0,0,string);
while (!done) {
val = mpeg_val2phys(setting, *variable);
snprintf(str,sizeof str,"%d %s ", val, unit);
lcd_puts(0,1,str);
lcd_update();
switch( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
(*variable)++;
if(*variable > max )
*variable = max;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
(*variable)--;
if(*variable < min )
*variable = min;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
break;
}
mpeg_sound_set(setting, *variable);
}
lcd_stop_scroll();
}
static void volume(void)
{
set_int("Volume","%", &global_settings.volume, mpeg_volume, 2, 0, 100);
set_sound("Volume", &global_settings.volume, SOUND_VOLUME);
}
static void bass(void)
{
set_int("Bass","%", &global_settings.bass, mpeg_bass, 2, 0, 100);
set_sound("Bass", &global_settings.bass, SOUND_BASS);
};
static void treble(void)
{
set_int("Treble","%", &global_settings.treble, mpeg_treble, 2, 0, 100);
set_sound("Treble", &global_settings.treble, SOUND_TREBLE);
}
void sound_menu(void)

View file

@ -176,17 +176,17 @@ void wps_show(void)
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
global_settings.volume += 2;
if(global_settings.volume > 100)
global_settings.volume = 100;
mpeg_volume(global_settings.volume);
global_settings.volume++;
if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME))
global_settings.volume = mpeg_sound_max(SOUND_VOLUME);
mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
break;
case BUTTON_DOWN:
global_settings.volume -= 2;
if(global_settings.volume < 0)
global_settings.volume = 0;
mpeg_volume(global_settings.volume);
global_settings.volume--;
if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME))
global_settings.volume = mpeg_sound_min(SOUND_VOLUME);
mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
break;
#endif

View file

@ -27,6 +27,7 @@
#include "thread.h"
#include "panic.h"
#include "file.h"
#include "mpeg.h"
#include "id3.h"
#define MPEG_STACK_SIZE 0x2000
@ -44,6 +45,42 @@
extern char* peek_next_track(int type);
extern char* peek_prev_track(int type);
static char *units[] =
{
"%", /* Volume */
"%", /* Bass */
"%" /* Treble */
};
static int minval[] =
{
0, /* Volume */
0, /* Bass */
0 /* Treble */
};
static int maxval[] =
{
50, /* Volume */
50, /* Bass */
50 /* Treble */
};
char *mpeg_sound_unit(int setting)
{
return units[setting];
}
int mpeg_sound_min(int setting)
{
return minval[setting];
}
int mpeg_sound_max(int setting)
{
return maxval[setting];
}
#ifndef ARCHOS_RECORDER
static unsigned int bass_table[] =
{
@ -638,43 +675,69 @@ void mpeg_prev(void)
queue_post(&mpeg_queue, MPEG_PREV, NULL);
}
void mpeg_volume(int percent)
void mpeg_sound_set(int setting, int value)
{
int volume;
int tmp;
switch(setting)
{
case SOUND_VOLUME:
value *= 2; /* Convert to percent */
#ifdef ARCHOS_RECORDER
volume = 0x7f00 * percent / 100;
mas_codec_writereg(0x10, volume & 0xff00);
tmp = 0x7f00 * value / 100;
mas_codec_writereg(0x10, tmp & 0xff00);
#else
volume = 0x38 * percent / 100;
dac_volume(volume, volume, false);
tmp = 0x38 * value / 100;
dac_volume(tmp, tmp, false);
#endif
break;
case SOUND_BASS:
value *= 2; /* Convert to percent */
#ifdef ARCHOS_RECORDER
tmp = 0x6000 * value / 100;
mas_codec_writereg(0x14, tmp & 0xff00);
#else
tmp = 15 * value / 100;
mas_writereg(MAS_REG_KBASS, bass_table[tmp]);
#endif
break;
case SOUND_TREBLE:
value *= 2; /* Convert to percent */
#ifdef ARCHOS_RECORDER
tmp = 0x6000 * value / 100;
mas_codec_writereg(0x15, tmp & 0xff00);
#else
tmp = 15 * value / 100;
mas_writereg(MAS_REG_KTREBLE, treble_table[tmp]);
#endif
break;
}
}
void mpeg_bass(int percent)
int mpeg_val2phys(int setting, int value)
{
int bass;
int result = 0;
#ifdef ARCHOS_RECORDER
bass = 0x6000 * percent / 100;
mas_codec_writereg(0x14, bass & 0xff00);
#else
bass = 15 * percent / 100;
mas_writereg(MAS_REG_KBASS, bass_table[bass]);
#endif
}
void mpeg_treble(int percent)
{
int treble;
#ifdef ARCHOS_RECORDER
treble = 0x6000 * percent / 100;
mas_codec_writereg(0x15, treble & 0xff00);
#else
treble = 15 * percent / 100;
mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
#endif
switch(setting)
{
case SOUND_VOLUME:
result = value * 2;
break;
case SOUND_BASS:
result = value * 2;
break;
case SOUND_TREBLE:
result = value * 2;
break;
}
return result;
}
void mpeg_init(int volume, int bass, int treble)
@ -742,7 +805,7 @@ void mpeg_init(int volume, int bass, int treble)
dac_config(0x04); /* DAC on, all else off */
#endif
mpeg_bass(bass);
mpeg_treble(treble);
mpeg_volume(volume);
mpeg_sound_set(SOUND_BASS, bass);
mpeg_sound_set(SOUND_TREBLE, treble);
mpeg_sound_set(SOUND_VOLUME, volume);
}

View file

@ -26,9 +26,25 @@ void mpeg_pause(void);
void mpeg_resume(void);
void mpeg_next(void);
void mpeg_prev(void);
void mpeg_volume(int percent);
void mpeg_bass(int percent);
void mpeg_treble(int percent);
void mpeg_sound_set(int setting, int value);
int mpeg_sound_min(int setting);
int mpeg_sound_max(int setting);
int mpeg_val2phys(int setting, int value);
char *mpeg_sound_unit(int setting);
struct mp3entry* mpeg_current_track(void);
#define SOUND_VOLUME 0
#define SOUND_BASS 1
#define SOUND_TREBLE 2
#define SOUND_BALANCE 3
#ifdef ARCHOS_RECORDER
#define SOUND_LOUDNESS 4
#define SOUND_SUPERBASS 5
#define SOUND_NUMSETTINGS 6
#else
#define SOUND_DEEMPH 4
#define SOUND_NUMSETTINGS 5
#endif
#endif