2002-09-27 09:44:51 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Philipp Pertermann
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-08-25 15:53:54 +00:00
|
|
|
#ifdef SIMULATOR
|
|
|
|
#include <stdlib.h> /* sim uses rand for peakmeter simulation */
|
|
|
|
#endif
|
2003-01-16 20:25:49 +00:00
|
|
|
#include "config.h"
|
2002-09-27 09:44:51 +00:00
|
|
|
#include "mas.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "settings.h"
|
2005-08-29 20:07:17 +00:00
|
|
|
#include "ata.h"
|
2002-09-27 09:44:51 +00:00
|
|
|
#include "lcd.h"
|
2006-11-09 12:27:56 +00:00
|
|
|
#include "scrollbar.h"
|
2005-11-17 20:14:59 +00:00
|
|
|
#include "gwps.h"
|
2002-09-27 09:44:51 +00:00
|
|
|
#include "sprintf.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "icons.h"
|
2002-10-03 09:19:11 +00:00
|
|
|
#include "lang.h"
|
2002-09-27 09:44:51 +00:00
|
|
|
#include "peakmeter.h"
|
2006-02-17 22:47:56 +00:00
|
|
|
#include "audio.h"
|
2006-03-25 13:35:31 +00:00
|
|
|
#include "screen_access.h"
|
2007-04-12 22:12:13 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2006-02-17 22:47:56 +00:00
|
|
|
#include "backlight.h"
|
|
|
|
#endif
|
2006-08-20 21:33:40 +00:00
|
|
|
#include "action.h"
|
2002-09-27 09:44:51 +00:00
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-10-06 22:27:27 +00:00
|
|
|
#include "pcm.h"
|
2005-12-02 01:04:03 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
#include "pcm_record.h"
|
|
|
|
#endif
|
2005-12-02 08:44:09 +00:00
|
|
|
|
2005-12-02 01:04:03 +00:00
|
|
|
static bool pm_playback = true; /* selects between playback and recording peaks */
|
2005-12-02 08:44:09 +00:00
|
|
|
#endif
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static struct meter_scales scales[NB_SCREENS];
|
2006-03-25 13:35:31 +00:00
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
#if !defined(SIMULATOR) && CONFIG_CODEC != SWCODEC
|
2005-08-29 20:07:17 +00:00
|
|
|
/* Data source */
|
|
|
|
static int pm_src_left = MAS_REG_DQPEAK_L;
|
|
|
|
static int pm_src_right = MAS_REG_DQPEAK_R;
|
2003-01-30 15:52:47 +00:00
|
|
|
#endif
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
/* Current values and cumulation */
|
|
|
|
static int pm_cur_left; /* current values (last peak_meter_peek) */
|
|
|
|
static int pm_cur_right;
|
|
|
|
static int pm_max_left; /* maximum values between peak meter draws */
|
|
|
|
static int pm_max_right;
|
2006-08-16 23:26:55 +00:00
|
|
|
#ifdef HAVE_AGC
|
|
|
|
static int pm_peakhold_left; /* max. peak values between peakhold calls */
|
|
|
|
static int pm_peakhold_right; /* used for AGC and histogram display */
|
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
|
|
|
|
/* Clip hold */
|
|
|
|
static bool pm_clip_left = false; /* when true a clip has occurred */
|
|
|
|
static bool pm_clip_right = false;
|
|
|
|
static long pm_clip_timeout_l; /* clip hold timeouts */
|
|
|
|
static long pm_clip_timeout_r;
|
|
|
|
|
|
|
|
/* Temporarily en- / disables peak meter. This is especially for external
|
|
|
|
applications to detect if the peak_meter is in use and needs drawing at all */
|
|
|
|
bool peak_meter_enabled = true;
|
2002-09-27 09:44:51 +00:00
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
/** Parameters **/
|
|
|
|
/* Range */
|
|
|
|
unsigned short peak_meter_range_min; /* minimum of range in samples */
|
|
|
|
unsigned short peak_meter_range_max; /* maximum of range in samples */
|
|
|
|
static unsigned short pm_range; /* range width in samples */
|
|
|
|
static bool pm_use_dbfs = true; /* true if peakmeter displays dBfs */
|
2006-12-25 14:01:47 +00:00
|
|
|
static bool level_check; /* true if peeked at peakmeter before drawing */
|
2005-08-29 20:07:17 +00:00
|
|
|
static unsigned short pm_db_min = 0; /* minimum of range in 1/100 dB */
|
|
|
|
static unsigned short pm_db_max = 9000; /* maximum of range in 1/100 dB */
|
|
|
|
static unsigned short pm_db_range = 9000; /* range width in 1/100 dB */
|
|
|
|
/* Timing behaviour */
|
|
|
|
static int pm_peak_hold = 1; /* peak hold timeout index */
|
|
|
|
static int pm_peak_release = 8; /* peak release in units per read */
|
|
|
|
static int pm_clip_hold = 16; /* clip hold timeout index */
|
|
|
|
static bool pm_clip_eternal = false; /* true if clip timeout is disabled */
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2005-04-04 20:16:01 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2005-04-04 09:12:12 +00:00
|
|
|
static unsigned short trig_strt_threshold;
|
|
|
|
static long trig_strt_duration;
|
|
|
|
static long trig_strt_dropout;
|
|
|
|
static unsigned short trig_stp_threshold;
|
|
|
|
static long trig_stp_hold;
|
|
|
|
static long trig_rstrt_gap;
|
|
|
|
|
|
|
|
/* point in time when the threshold was exceeded */
|
|
|
|
static long trig_hightime;
|
|
|
|
|
|
|
|
/* point in time when the volume fell below the threshold*/
|
|
|
|
static long trig_lowtime;
|
|
|
|
|
2005-04-04 20:16:01 +00:00
|
|
|
/* The output value of the trigger. See TRIG_XXX constants for valid values */
|
2005-04-04 09:12:12 +00:00
|
|
|
static int trig_status = TRIG_OFF;
|
|
|
|
|
|
|
|
static void (*trigger_listener)(int) = NULL;
|
2007-08-26 21:34:36 +00:00
|
|
|
|
|
|
|
/* clipping counter (only used for recording) */
|
|
|
|
static unsigned int pm_clipcount = 0; /* clipping count */
|
|
|
|
static bool pm_clipcount_active = false; /* counting or not */
|
2005-04-04 20:16:01 +00:00
|
|
|
#endif
|
2005-04-04 09:12:12 +00:00
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/* debug only */
|
|
|
|
#ifdef PM_DEBUG
|
|
|
|
static int peek_calls = 0;
|
|
|
|
|
|
|
|
#define PEEKS_PER_DRAW_SIZE 40
|
|
|
|
static unsigned int peeks_per_redraw[PEEKS_PER_DRAW_SIZE];
|
|
|
|
|
|
|
|
#define TICKS_PER_DRAW_SIZE 20
|
|
|
|
static unsigned int ticks_per_redraw[TICKS_PER_DRAW_SIZE];
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:44:28 +00:00
|
|
|
static void peak_meter_draw(struct screen *display, struct meter_scales *meter_scales,
|
|
|
|
int x, int y, int width, int height);
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/* time out values for max */
|
2005-08-29 20:07:17 +00:00
|
|
|
static const short peak_time_out[] = {
|
2002-09-27 09:44:51 +00:00
|
|
|
0 * HZ, HZ / 5, 30, HZ / 2, HZ, 2 * HZ,
|
|
|
|
3 * HZ, 4 * HZ, 5 * HZ, 6 * HZ, 7 * HZ, 8 * HZ,
|
|
|
|
9 * HZ, 10 * HZ, 15 * HZ, 20 * HZ, 30 * HZ, 60 * HZ
|
|
|
|
};
|
|
|
|
|
|
|
|
/* time out values for clip */
|
2004-08-01 23:34:44 +00:00
|
|
|
static const long clip_time_out[] = {
|
2002-09-27 09:44:51 +00:00
|
|
|
0 * HZ, 1 * HZ, 2 * HZ, 3 * HZ, 4 * HZ, 5 * HZ,
|
|
|
|
6 * HZ, 7 * HZ, 8 * HZ, 9 * HZ, 10 * HZ, 15 * HZ,
|
|
|
|
20 * HZ, 25 * HZ, 30 * HZ, 45 * HZ, 60 * HZ, 90 * HZ,
|
2005-02-16 11:04:35 +00:00
|
|
|
120 * HZ, 180 * HZ, 300 * HZ, 600L * HZ, 1200L * HZ,
|
|
|
|
2700L * HZ, 5400L * HZ
|
2002-09-27 09:44:51 +00:00
|
|
|
};
|
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/* precalculated peak values that represent magical
|
|
|
|
dBfs values. Used to draw the scale */
|
2007-09-20 16:44:28 +00:00
|
|
|
static const short db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = {
|
2006-07-02 22:36:46 +00:00
|
|
|
32736, /* 0 db */
|
|
|
|
22752, /* - 3 db */
|
|
|
|
16640, /* - 6 db */
|
|
|
|
11648, /* - 9 db */
|
|
|
|
8320, /* -12 db */
|
|
|
|
4364, /* -18 db */
|
|
|
|
2064, /* -24 db */
|
|
|
|
1194, /* -30 db */
|
|
|
|
363, /* -40 db */
|
|
|
|
101, /* -50 db */
|
|
|
|
34, /* -60 db */
|
2005-04-04 09:12:12 +00:00
|
|
|
0, /* -inf */
|
2002-10-29 12:09:15 +00:00
|
|
|
};
|
|
|
|
|
2002-10-30 23:01:27 +00:00
|
|
|
static int db_scale_count = DB_SCALE_SRC_VALUES_SIZE;
|
2002-10-29 12:09:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates dB Value for the peak meter, uses peak value as input
|
|
|
|
* @param int sample - The input value
|
|
|
|
* Make sure that 0 <= value < SAMPLE_RANGE
|
|
|
|
*
|
2006-07-02 22:36:46 +00:00
|
|
|
* @return int - The 2 digit fixed point result of the euation
|
2002-10-29 12:09:15 +00:00
|
|
|
* 20 * log (sample / SAMPLE_RANGE) + 90
|
2006-07-02 22:36:46 +00:00
|
|
|
* Output range is 0-9000 (that is 0.0 - 90.0 dB).
|
2002-10-29 12:09:15 +00:00
|
|
|
* Normally 0dB is full scale, here it is shifted +90dB.
|
|
|
|
* The calculation is based on the results of a linear
|
|
|
|
* approximation tool written specifically for this problem
|
2006-07-02 22:36:46 +00:00
|
|
|
* by Andreas Zwirtes (radhard@gmx.de). The result has an
|
2002-10-29 12:09:15 +00:00
|
|
|
* accurracy of better than 2%. It is highly runtime optimized,
|
|
|
|
* the cascading if-clauses do an successive approximation on
|
|
|
|
* the input value. This avoids big lookup-tables and
|
|
|
|
* for-loops.
|
2006-07-02 22:36:46 +00:00
|
|
|
* Improved by Jvo Studer for errors < 0.2dB for critical
|
|
|
|
* range of -12dB to 0dB (78.0 to 90.0dB).
|
2002-10-29 12:09:15 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
int calc_db (int isample)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
/* return n+m*(isample-istart)/100 */
|
|
|
|
int n;
|
|
|
|
long m;
|
|
|
|
int istart;
|
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 2308) { /* Range 1-5 */
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 115) { /* Range 1-3 */
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 24) {
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 5) {
|
|
|
|
istart = 1; /* Range 1 */
|
|
|
|
n = 98;
|
2002-10-29 12:09:15 +00:00
|
|
|
m = 34950;
|
|
|
|
}
|
|
|
|
else {
|
2006-07-02 22:36:46 +00:00
|
|
|
istart = 5; /* Range 2 */
|
|
|
|
n = 1496;
|
2002-10-29 12:09:15 +00:00
|
|
|
m = 7168;
|
|
|
|
}
|
2006-07-02 22:36:46 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
istart = 24; /* Range 3 */
|
|
|
|
n = 2858;
|
|
|
|
m = 1498;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* Range 4-5 */
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 534) {
|
|
|
|
istart = 114; /* Range 4 */
|
|
|
|
n = 4207;
|
|
|
|
m = 319;
|
|
|
|
}
|
2002-10-29 12:09:15 +00:00
|
|
|
else {
|
2006-07-02 22:36:46 +00:00
|
|
|
istart = 588; /* Range 5 */
|
|
|
|
n = 5583;
|
|
|
|
m = 69;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
else { /* Range 6-9 */
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 12932) {
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 6394) {
|
|
|
|
istart = 2608; /* Range 6 */
|
|
|
|
n = 6832;
|
|
|
|
m = 21;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-07-02 22:36:46 +00:00
|
|
|
istart = 7000; /* Range 7 */
|
|
|
|
n = 7682;
|
|
|
|
m = 9;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2006-07-02 22:36:46 +00:00
|
|
|
if (isample < 22450) {
|
|
|
|
istart = 13000; /* Range 8 */
|
|
|
|
n = 8219;
|
|
|
|
m = 5;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-07-02 22:36:46 +00:00
|
|
|
istart = 22636; /* Range 9 */
|
|
|
|
n = 8697;
|
2002-10-29 12:09:15 +00:00
|
|
|
m = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n + (m * (long)(isample - istart)) / 100L;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-04-04 09:12:12 +00:00
|
|
|
* A helper function for peak_meter_db2sample. Don't call it separately but
|
|
|
|
* use peak_meter_db2sample. If one or both of min and max are outside the
|
2002-10-29 12:09:15 +00:00
|
|
|
* range 0 <= min (or max) < 8961 the behaviour of this function is
|
|
|
|
* undefined. It may not return.
|
|
|
|
* @param int min - The minimum of the value range that is searched.
|
|
|
|
* @param int max - The maximum of the value range that is searched.
|
|
|
|
* @param int db - The value in dBfs * (-100) for which the according
|
|
|
|
* minimal peak sample is searched.
|
|
|
|
* @return int - A linear volume value with 0 <= value < MAX_PEAK
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
static int db_to_sample_bin_search(int min, int max, int db)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int test = min + (max - min) / 2;
|
|
|
|
|
|
|
|
if (min < max) {
|
|
|
|
if (calc_db(test) < db) {
|
|
|
|
test = db_to_sample_bin_search(test, max, db);
|
|
|
|
} else {
|
|
|
|
if (calc_db(test-1) > db) {
|
|
|
|
test = db_to_sample_bin_search(min, test, db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a value representing dBfs to a linear
|
|
|
|
* scaled volume info as it is used by the MAS.
|
|
|
|
* An incredibly inefficiant function which is
|
|
|
|
* the vague inverse of calc_db. This really
|
|
|
|
* should be replaced by something better soon.
|
|
|
|
*
|
|
|
|
* @param int db - A dBfs * 100 value with
|
|
|
|
* -9000 < value <= 0
|
|
|
|
* @return int - The return value is in the range of
|
|
|
|
* 0 <= return value < MAX_PEAK
|
|
|
|
*/
|
2006-12-25 14:01:47 +00:00
|
|
|
int peak_meter_db2sample(int db)
|
2005-08-29 20:07:17 +00:00
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
/* what is the maximum pseudo db value */
|
|
|
|
int max_peak_db = calc_db(MAX_PEAK - 1);
|
|
|
|
|
|
|
|
/* range check: db value to big */
|
|
|
|
if (max_peak_db + db < 0) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* range check: db value too small */
|
|
|
|
else if (max_peak_db + db >= max_peak_db) {
|
|
|
|
retval = MAX_PEAK -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* value in range: find the matching linear value */
|
|
|
|
else {
|
|
|
|
retval = db_to_sample_bin_search(0, MAX_PEAK, max_peak_db + db);
|
|
|
|
|
|
|
|
/* as this is a dirty function anyway, we want to adjust the
|
|
|
|
full scale hit manually to avoid users complaining that when
|
|
|
|
they adjust maximum for 0 dBfs and display it in percent it
|
|
|
|
shows 99%. That is due to precision loss and this is the
|
|
|
|
optical fix */
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the min value for restriction of the value range.
|
2005-08-29 20:07:17 +00:00
|
|
|
* @param int newmin - depending whether dBfs is used
|
2002-10-29 12:09:15 +00:00
|
|
|
* newmin is a value in dBfs * 100 or in linear percent values.
|
|
|
|
* for dBfs: -9000 < newmin <= 0
|
|
|
|
* for linear: 0 <= newmin <= 100
|
|
|
|
*/
|
2007-09-20 16:44:28 +00:00
|
|
|
static void peak_meter_set_min(int newmin)
|
2005-08-29 20:07:17 +00:00
|
|
|
{
|
|
|
|
if (pm_use_dbfs) {
|
2005-04-04 09:12:12 +00:00
|
|
|
peak_meter_range_min = peak_meter_db2sample(newmin);
|
2002-10-29 12:09:15 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (newmin < peak_meter_range_max) {
|
|
|
|
peak_meter_range_min = newmin * MAX_PEAK / 100;
|
|
|
|
}
|
|
|
|
}
|
2002-10-30 23:01:27 +00:00
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_range = peak_meter_range_max - peak_meter_range_min;
|
2006-08-17 09:35:27 +00:00
|
|
|
|
|
|
|
/* Avoid division by zero. */
|
|
|
|
if (pm_range == 0) {
|
|
|
|
pm_range = 1;
|
|
|
|
}
|
2002-10-30 23:01:27 +00:00
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_db_min = calc_db(peak_meter_range_min);
|
|
|
|
pm_db_range = pm_db_max - pm_db_min;
|
2006-03-25 13:35:31 +00:00
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
scales[i].db_scale_valid = false;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the minimum value of the range the meter
|
|
|
|
* displays. If the scale is set to dBfs it returns
|
|
|
|
* dBfs values * 100 or linear percent values.
|
|
|
|
* @return: using dBfs : -9000 < value <= 0
|
|
|
|
* using linear scale: 0 <= value <= 100
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
int peak_meter_get_min(void)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int retval = 0;
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_use_dbfs) {
|
2002-10-29 12:09:15 +00:00
|
|
|
retval = calc_db(peak_meter_range_min) - calc_db(MAX_PEAK - 1);
|
|
|
|
} else {
|
|
|
|
retval = peak_meter_range_min * 100 / MAX_PEAK;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the max value for restriction of the value range.
|
|
|
|
* @param int newmax - depending wether dBfs is used
|
|
|
|
* newmax is a value in dBfs * 100 or in linear percent values.
|
|
|
|
* for dBfs: -9000 < newmax <= 0
|
|
|
|
* for linear: 0 <= newmax <= 100
|
|
|
|
*/
|
2007-09-20 16:44:28 +00:00
|
|
|
static void peak_meter_set_max(int newmax)
|
2005-08-29 20:07:17 +00:00
|
|
|
{
|
|
|
|
if (pm_use_dbfs) {
|
2005-04-04 09:12:12 +00:00
|
|
|
peak_meter_range_max = peak_meter_db2sample(newmax);
|
2002-10-29 12:09:15 +00:00
|
|
|
} else {
|
|
|
|
if (newmax > peak_meter_range_min) {
|
|
|
|
peak_meter_range_max = newmax * MAX_PEAK / 100;
|
|
|
|
}
|
|
|
|
}
|
2002-10-30 23:01:27 +00:00
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_range = peak_meter_range_max - peak_meter_range_min;
|
2002-10-30 23:01:27 +00:00
|
|
|
|
2006-08-17 09:35:27 +00:00
|
|
|
/* Avoid division by zero. */
|
|
|
|
if (pm_range == 0) {
|
|
|
|
pm_range = 1;
|
|
|
|
}
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_db_max = calc_db(peak_meter_range_max);
|
|
|
|
pm_db_range = pm_db_max - pm_db_min;
|
2006-03-25 13:35:31 +00:00
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
scales[i].db_scale_valid = false;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the minimum value of the range the meter
|
|
|
|
* displays. If the scale is set to dBfs it returns
|
|
|
|
* dBfs values * 100 or linear percent values
|
|
|
|
* @return: using dBfs : -9000 < value <= 0
|
|
|
|
* using linear scale: 0 <= value <= 100
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
int peak_meter_get_max(void)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int retval = 0;
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_use_dbfs) {
|
2002-10-29 12:09:15 +00:00
|
|
|
retval = calc_db(peak_meter_range_max) - calc_db(MAX_PEAK - 1);
|
|
|
|
} else {
|
|
|
|
retval = peak_meter_range_max * 100 / MAX_PEAK;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-08-29 20:07:17 +00:00
|
|
|
* Returns whether the meter is currently displaying dBfs or percent values.
|
|
|
|
* @return bool - true if the meter is displaying dBfs
|
|
|
|
false if the meter is displaying percent values.
|
2002-10-29 12:09:15 +00:00
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
bool peak_meter_get_use_dbfs(void)
|
|
|
|
{
|
|
|
|
return pm_use_dbfs;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-08-29 20:07:17 +00:00
|
|
|
* Specifies whether the values displayed are scaled
|
2002-10-29 12:09:15 +00:00
|
|
|
* as dBfs or as linear percent values.
|
2005-08-29 20:07:17 +00:00
|
|
|
* @param use - set to true for dBfs,
|
|
|
|
* set to false for linear scaling in percent
|
2002-10-29 12:09:15 +00:00
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
void peak_meter_set_use_dbfs(bool use)
|
|
|
|
{
|
2006-03-25 13:35:31 +00:00
|
|
|
int i;
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_use_dbfs = use;
|
2006-03-25 13:35:31 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
scales[i].db_scale_valid = false;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the range of the meter. Only values
|
|
|
|
* that are in the range of [range_min ... range_max]
|
|
|
|
* are displayed.
|
|
|
|
* @param bool dbfs - set to true for dBfs,
|
|
|
|
* set to false for linear scaling in percent
|
|
|
|
* @param int range_min - Specifies the lower value of the range.
|
|
|
|
* Pass a value dBfs * 100 when dbfs is set to true.
|
|
|
|
* Pass a percent value when dbfs is set to false.
|
|
|
|
* @param int range_max - Specifies the upper value of the range.
|
|
|
|
* Pass a value dBfs * 100 when dbfs is set to true.
|
|
|
|
* Pass a percent value when dbfs is set to false.
|
|
|
|
*/
|
2005-02-02 21:49:19 +00:00
|
|
|
void peak_meter_init_range( bool dbfs, int range_min, int range_max)
|
|
|
|
{
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_use_dbfs = dbfs;
|
2002-10-29 12:09:15 +00:00
|
|
|
peak_meter_set_min(range_min);
|
|
|
|
peak_meter_set_max(range_max);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the peak meter with all relevant values concerning times.
|
|
|
|
* @param int release - Set the maximum amount of pixels the meter is allowed
|
|
|
|
* to decrease with each redraw
|
|
|
|
* @param int hold - Select the time preset for the time the peak indicator
|
|
|
|
* is reset after a peak occurred. The preset values are
|
2005-08-29 20:07:17 +00:00
|
|
|
* stored in peak_time_out.
|
2002-10-29 12:09:15 +00:00
|
|
|
* @param int clip_hold - Select the time preset for the time the peak
|
|
|
|
* indicator is reset after a peak occurred. The preset
|
|
|
|
* values are stored in clip_time_out.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
void peak_meter_init_times(int release, int hold, int clip_hold)
|
|
|
|
{
|
|
|
|
pm_peak_hold = hold;
|
|
|
|
pm_peak_release = release;
|
|
|
|
pm_clip_hold = clip_hold;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
2007-08-26 21:34:36 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2007-08-25 15:53:54 +00:00
|
|
|
/**
|
|
|
|
* Enable/disable clip counting
|
|
|
|
*/
|
|
|
|
void pm_activate_clipcount(bool active)
|
|
|
|
{
|
|
|
|
pm_clipcount_active = active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get clipping counter value
|
|
|
|
*/
|
|
|
|
int pm_get_clipcount(void)
|
|
|
|
{
|
|
|
|
return pm_clipcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set clipping counter to zero (typically at start of recording or playback)
|
|
|
|
*/
|
|
|
|
void pm_reset_clipcount(void)
|
|
|
|
{
|
|
|
|
pm_clipcount = 0;
|
|
|
|
}
|
2007-08-26 21:34:36 +00:00
|
|
|
#endif
|
2007-08-25 15:53:54 +00:00
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/**
|
|
|
|
* Set the source of the peak meter to playback or to
|
|
|
|
* record.
|
|
|
|
* @param: bool playback - If true playback peak meter is used.
|
|
|
|
* If false recording peak meter is used.
|
|
|
|
*/
|
2005-02-02 21:49:19 +00:00
|
|
|
void peak_meter_playback(bool playback)
|
|
|
|
{
|
2002-09-27 09:44:51 +00:00
|
|
|
#ifdef SIMULATOR
|
|
|
|
(void)playback;
|
2005-08-29 21:15:27 +00:00
|
|
|
#elif CONFIG_CODEC == SWCODEC
|
2005-12-02 01:04:03 +00:00
|
|
|
pm_playback = playback;
|
2002-09-27 09:44:51 +00:00
|
|
|
#else
|
|
|
|
if (playback) {
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_src_left = MAS_REG_DQPEAK_L;
|
|
|
|
pm_src_right = MAS_REG_DQPEAK_R;
|
2002-09-27 09:44:51 +00:00
|
|
|
} else {
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_src_left = MAS_REG_QPEAK_L;
|
|
|
|
pm_src_right = MAS_REG_QPEAK_R;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-04-04 20:16:01 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2005-08-29 20:07:17 +00:00
|
|
|
static void set_trig_status(int new_state)
|
|
|
|
{
|
2005-04-04 09:12:12 +00:00
|
|
|
if (trig_status != new_state) {
|
|
|
|
trig_status = new_state;
|
|
|
|
if (trigger_listener != NULL) {
|
|
|
|
trigger_listener(trig_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-25 15:53:54 +00:00
|
|
|
|
2005-04-04 20:16:01 +00:00
|
|
|
#endif
|
2005-04-04 09:12:12 +00:00
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/**
|
|
|
|
* Reads peak values from the MAS, and detects clips. The
|
2005-08-29 20:07:17 +00:00
|
|
|
* values are stored in pm_max_left pm_max_right for later
|
2002-09-27 09:44:51 +00:00
|
|
|
* evauluation. Consecutive calls to peak_meter_peek detect
|
|
|
|
* that ocurred. This function could be used by a thread for
|
|
|
|
* busy reading the MAS.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
void peak_meter_peek(void)
|
2005-02-02 21:49:19 +00:00
|
|
|
{
|
2005-08-29 20:07:17 +00:00
|
|
|
int left, right;
|
2007-08-26 21:34:36 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2007-08-25 15:53:54 +00:00
|
|
|
bool was_clipping = pm_clip_left || pm_clip_right;
|
2007-08-26 21:34:36 +00:00
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
/* read current values */
|
2006-02-23 21:13:03 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-12-02 01:04:03 +00:00
|
|
|
if (pm_playback)
|
|
|
|
pcm_calculate_peaks(&pm_cur_left, &pm_cur_right);
|
|
|
|
#ifdef HAVE_RECORDING
|
2006-11-06 18:07:30 +00:00
|
|
|
else
|
|
|
|
pcm_calculate_rec_peaks(&pm_cur_left, &pm_cur_right);
|
2005-12-02 01:04:03 +00:00
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
left = pm_cur_left;
|
|
|
|
right = pm_cur_right;
|
2002-09-27 09:44:51 +00:00
|
|
|
#else
|
2006-02-23 21:13:03 +00:00
|
|
|
#ifndef SIMULATOR
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_cur_left = left = mas_codec_readreg(pm_src_left);
|
|
|
|
pm_cur_right = right = mas_codec_readreg(pm_src_right);
|
2006-02-23 21:13:03 +00:00
|
|
|
#else
|
|
|
|
pm_cur_left = left = 8000;
|
|
|
|
pm_cur_right = right = 9000;
|
|
|
|
#endif
|
2002-09-27 09:44:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check for clips
|
|
|
|
An clip is assumed when two consecutive readouts
|
|
|
|
of the volume are at full scale. This is proven
|
|
|
|
to be inaccurate in both ways: it may detect clips
|
|
|
|
when no clip occurred and it may fail to detect
|
2006-03-08 20:38:16 +00:00
|
|
|
a real clip. For software codecs, the peak is already
|
|
|
|
the max of a bunch of samples, so use one max value
|
|
|
|
or you fail to detect clipping! */
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if (left == MAX_PEAK - 1) {
|
|
|
|
#else
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left == pm_max_left) &&
|
|
|
|
(left == MAX_PEAK - 1)) {
|
2006-03-08 20:38:16 +00:00
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_clip_left = true;
|
|
|
|
pm_clip_timeout_l =
|
|
|
|
current_tick + clip_time_out[pm_clip_hold];
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 20:38:16 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if (right == MAX_PEAK - 1) {
|
|
|
|
#else
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((right == pm_max_right) &&
|
2002-09-27 09:44:51 +00:00
|
|
|
(right == MAX_PEAK - 1)) {
|
2006-03-08 20:38:16 +00:00
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
pm_clip_right = true;
|
|
|
|
pm_clip_timeout_r =
|
|
|
|
current_tick + clip_time_out[pm_clip_hold];
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-26 21:34:36 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2007-08-25 15:53:54 +00:00
|
|
|
if(!was_clipping && (pm_clip_left || pm_clip_right))
|
|
|
|
{
|
|
|
|
if(pm_clipcount_active)
|
|
|
|
pm_clipcount++;
|
|
|
|
}
|
2007-08-26 21:34:36 +00:00
|
|
|
#endif
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
/* peaks are searched -> we have to find the maximum. When
|
|
|
|
many calls of peak_meter_peek the maximum value will be
|
|
|
|
stored in pm_max_xxx. This maximum is reset by the
|
|
|
|
functions peak_meter_read_x. */
|
|
|
|
pm_max_left = MAX(pm_max_left, left);
|
|
|
|
pm_max_right = MAX(pm_max_right, right);
|
|
|
|
|
2005-04-04 20:16:01 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2006-11-09 12:27:56 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* Ignore any unread peakmeter data */
|
|
|
|
#define MAX_DROP_TIME HZ/7 /* this value may need tweaking. Increase if you are
|
|
|
|
getting trig events when you shouldn't with
|
|
|
|
trig_stp_hold = 0 */
|
|
|
|
if (!trig_stp_hold)
|
|
|
|
trig_stp_hold = MAX_DROP_TIME;
|
|
|
|
#endif
|
|
|
|
|
2005-04-04 09:12:12 +00:00
|
|
|
switch (trig_status) {
|
|
|
|
case TRIG_READY:
|
|
|
|
/* no more changes, if trigger was activated as release trigger */
|
|
|
|
/* threshold exceeded? */
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left > trig_strt_threshold)
|
|
|
|
|| (right > trig_strt_threshold)) {
|
2005-04-04 09:12:12 +00:00
|
|
|
/* reset trigger duration */
|
|
|
|
trig_hightime = current_tick;
|
|
|
|
|
|
|
|
/* reset dropout duration */
|
|
|
|
trig_lowtime = current_tick;
|
|
|
|
|
2006-11-09 12:27:56 +00:00
|
|
|
if (trig_strt_duration)
|
|
|
|
set_trig_status(TRIG_STEADY);
|
|
|
|
else
|
2005-04-04 09:12:12 +00:00
|
|
|
/* if trig_duration is set to 0 the user wants to start
|
|
|
|
recording immediately */
|
|
|
|
set_trig_status(TRIG_GO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRIG_STEADY:
|
|
|
|
case TRIG_RETRIG:
|
|
|
|
/* trigger duration exceeded */
|
|
|
|
if (current_tick - trig_hightime > trig_strt_duration) {
|
|
|
|
set_trig_status(TRIG_GO);
|
|
|
|
} else {
|
|
|
|
/* threshold exceeded? */
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left > trig_strt_threshold)
|
|
|
|
|| (right > trig_strt_threshold)) {
|
2005-04-04 09:12:12 +00:00
|
|
|
/* reset lowtime */
|
|
|
|
trig_lowtime = current_tick;
|
|
|
|
}
|
|
|
|
/* volume is below threshold */
|
|
|
|
else {
|
|
|
|
/* dropout occurred? */
|
|
|
|
if (current_tick - trig_lowtime > trig_strt_dropout){
|
|
|
|
if (trig_status == TRIG_STEADY){
|
|
|
|
set_trig_status(TRIG_READY);
|
|
|
|
}
|
|
|
|
/* trig_status == TRIG_RETRIG */
|
|
|
|
else {
|
|
|
|
/* the gap has already expired */
|
|
|
|
trig_lowtime = current_tick - trig_rstrt_gap - 1;
|
|
|
|
set_trig_status(TRIG_POSTREC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRIG_GO:
|
|
|
|
case TRIG_CONTINUE:
|
|
|
|
/* threshold exceeded? */
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left > trig_stp_threshold)
|
|
|
|
|| (right > trig_stp_threshold)) {
|
2005-04-04 09:12:12 +00:00
|
|
|
/* restart hold time countdown */
|
|
|
|
trig_lowtime = current_tick;
|
2006-11-09 12:27:56 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
} else if (current_tick - trig_lowtime > MAX_DROP_TIME){
|
|
|
|
#else
|
2005-04-04 09:12:12 +00:00
|
|
|
} else {
|
2006-11-09 12:27:56 +00:00
|
|
|
#endif
|
2005-04-04 09:12:12 +00:00
|
|
|
set_trig_status(TRIG_POSTREC);
|
|
|
|
trig_hightime = current_tick;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRIG_POSTREC:
|
|
|
|
/* gap time expired? */
|
|
|
|
if (current_tick - trig_lowtime > trig_rstrt_gap){
|
|
|
|
/* start threshold exceeded? */
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left > trig_strt_threshold)
|
|
|
|
|| (right > trig_strt_threshold)) {
|
2005-04-04 09:12:12 +00:00
|
|
|
|
|
|
|
set_trig_status(TRIG_RETRIG);
|
|
|
|
trig_hightime = current_tick;
|
2006-11-09 12:27:56 +00:00
|
|
|
trig_lowtime = current_tick;
|
2005-04-04 09:12:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
/* stop threshold exceeded */
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left > trig_stp_threshold)
|
|
|
|
|| (right > trig_stp_threshold)) {
|
2005-04-04 09:12:12 +00:00
|
|
|
if (current_tick - trig_hightime > trig_stp_hold){
|
|
|
|
trig_lowtime = current_tick;
|
|
|
|
set_trig_status(TRIG_CONTINUE);
|
|
|
|
} else {
|
|
|
|
trig_lowtime = current_tick - trig_rstrt_gap - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* below any threshold */
|
|
|
|
else {
|
|
|
|
if (current_tick - trig_lowtime > trig_stp_hold){
|
|
|
|
set_trig_status(TRIG_READY);
|
|
|
|
} else {
|
|
|
|
trig_hightime = current_tick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* still within the gap time */
|
|
|
|
else {
|
|
|
|
/* stop threshold exceeded */
|
2005-08-29 20:07:17 +00:00
|
|
|
if ((left > trig_stp_threshold)
|
|
|
|
|| (right > trig_stp_threshold)) {
|
2005-04-04 09:12:12 +00:00
|
|
|
set_trig_status(TRIG_CONTINUE);
|
|
|
|
trig_lowtime = current_tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hold time expired */
|
|
|
|
else if (current_tick - trig_lowtime > trig_stp_hold){
|
|
|
|
trig_hightime = current_tick;
|
|
|
|
trig_lowtime = current_tick;
|
|
|
|
set_trig_status(TRIG_READY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-11-09 12:27:56 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* restore stop hold value */
|
|
|
|
if (trig_stp_hold == MAX_DROP_TIME)
|
|
|
|
trig_stp_hold = 0;
|
|
|
|
#endif
|
2005-04-04 20:16:01 +00:00
|
|
|
#endif
|
2006-03-25 13:35:31 +00:00
|
|
|
/* check levels next time peakmeter drawn */
|
|
|
|
level_check = true;
|
2002-10-29 12:09:15 +00:00
|
|
|
#ifdef PM_DEBUG
|
|
|
|
peek_calls++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/**
|
|
|
|
* Reads out the peak volume of the left channel.
|
|
|
|
* @return int - The maximum value that has been detected
|
|
|
|
* since the last call of peak_meter_read_l. The value
|
|
|
|
* is in the range 0 <= value < MAX_PEAK.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
static int peak_meter_read_l(void)
|
2005-02-02 21:49:19 +00:00
|
|
|
{
|
2005-08-29 20:07:17 +00:00
|
|
|
/* pm_max_left contains the maximum of all peak values that were read
|
|
|
|
by peak_meter_peek since the last call of peak_meter_read_l */
|
|
|
|
int retval = pm_max_left;
|
|
|
|
|
2006-08-16 23:26:55 +00:00
|
|
|
#ifdef HAVE_AGC
|
|
|
|
/* store max peak value for peak_meter_get_peakhold_x readout */
|
|
|
|
pm_peakhold_left = MAX(pm_max_left, pm_peakhold_left);
|
|
|
|
#endif
|
2002-10-29 12:09:15 +00:00
|
|
|
#ifdef PM_DEBUG
|
|
|
|
peek_calls = 0;
|
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
/* reset pm_max_left so that subsequent calls of peak_meter_peek don't
|
|
|
|
get fooled by an old maximum value */
|
|
|
|
pm_max_left = pm_cur_left;
|
2007-08-25 15:53:54 +00:00
|
|
|
|
2007-09-09 09:07:22 +00:00
|
|
|
#if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
|
2007-08-25 15:53:54 +00:00
|
|
|
srand(current_tick);
|
|
|
|
retval = rand()%MAX_PEAK;
|
|
|
|
#endif
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads out the peak volume of the right channel.
|
|
|
|
* @return int - The maximum value that has been detected
|
|
|
|
* since the last call of peak_meter_read_l. The value
|
|
|
|
* is in the range 0 <= value < MAX_PEAK.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
static int peak_meter_read_r(void)
|
|
|
|
{
|
|
|
|
/* peak_meter_r contains the maximum of all peak values that were read
|
|
|
|
by peak_meter_peek since the last call of peak_meter_read_r */
|
|
|
|
int retval = pm_max_right;
|
|
|
|
|
2006-08-16 23:26:55 +00:00
|
|
|
#ifdef HAVE_AGC
|
|
|
|
/* store max peak value for peak_meter_get_peakhold_x readout */
|
|
|
|
pm_peakhold_right = MAX(pm_max_right, pm_peakhold_right);
|
|
|
|
#endif
|
2002-10-29 12:09:15 +00:00
|
|
|
#ifdef PM_DEBUG
|
|
|
|
peek_calls = 0;
|
|
|
|
#endif
|
2005-08-29 20:07:17 +00:00
|
|
|
/* reset pm_max_right so that subsequent calls of peak_meter_peek don't
|
|
|
|
get fooled by an old maximum value */
|
|
|
|
pm_max_right = pm_cur_right;
|
2007-08-25 15:53:54 +00:00
|
|
|
|
2007-09-09 09:07:22 +00:00
|
|
|
#if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
|
2007-08-25 15:53:54 +00:00
|
|
|
srand(current_tick);
|
|
|
|
retval = rand()%MAX_PEAK;
|
|
|
|
#endif
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-08-16 23:26:55 +00:00
|
|
|
#ifdef HAVE_AGC
|
|
|
|
/**
|
|
|
|
* Reads out the current peak-hold values since the last call.
|
|
|
|
* This is used by the histogram feature in the recording screen.
|
|
|
|
* Values are in the range 0 <= peak_x < MAX_PEAK. MAX_PEAK is typ 32767.
|
|
|
|
*/
|
2006-12-25 14:01:47 +00:00
|
|
|
void peak_meter_get_peakhold(int *peak_left, int *peak_right)
|
2006-08-16 23:26:55 +00:00
|
|
|
{
|
|
|
|
if (peak_left)
|
|
|
|
*peak_left = pm_peakhold_left;
|
|
|
|
if (peak_right)
|
|
|
|
*peak_right = pm_peakhold_right;
|
|
|
|
pm_peakhold_left = 0;
|
|
|
|
pm_peakhold_right = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/**
|
|
|
|
* Reset the detected clips. This method is for
|
|
|
|
* use by the user interface.
|
|
|
|
* @param int unused - This parameter was added to
|
|
|
|
* make the function compatible with set_int
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
void peak_meter_set_clip_hold(int time)
|
|
|
|
{
|
2008-03-08 20:32:37 +00:00
|
|
|
pm_clip_left = false;
|
|
|
|
pm_clip_right = false;
|
|
|
|
pm_clip_eternal = (time > 0) ? false : true;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/**
|
|
|
|
* Scales a peak value as read from the MAS to the range of meterwidth.
|
|
|
|
* The scaling is performed according to the scaling method (dBfs / linear)
|
|
|
|
* and the range (peak_meter_range_min .. peak_meter_range_max).
|
|
|
|
* @param unsigned short val - The volume value. Range: 0 <= val < MAX_PEAK
|
|
|
|
* @param int meterwidht - The widht of the meter in pixel
|
|
|
|
* @return unsigned short - A value 0 <= return value <= meterwidth
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
unsigned short peak_meter_scale_value(unsigned short val, int meterwidth)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (val <= peak_meter_range_min) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val >= peak_meter_range_max) {
|
|
|
|
return meterwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = val;
|
|
|
|
|
|
|
|
/* different scaling is used for dBfs and linear percent */
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_use_dbfs) {
|
2002-10-29 12:09:15 +00:00
|
|
|
|
|
|
|
/* scale the samples dBfs */
|
2005-08-29 20:07:17 +00:00
|
|
|
retval = (calc_db(retval) - pm_db_min) * meterwidth / pm_db_range;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Scale for linear percent display */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* scale the samples */
|
2002-10-30 23:01:27 +00:00
|
|
|
retval = ((retval - peak_meter_range_min) * meterwidth)
|
2005-08-29 20:07:17 +00:00
|
|
|
/ pm_range;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2006-03-25 13:35:31 +00:00
|
|
|
void peak_meter_screen(struct screen *display, int x, int y, int height)
|
|
|
|
{
|
|
|
|
peak_meter_draw(display, &scales[display->screen_type], x, y,
|
2007-08-25 15:53:54 +00:00
|
|
|
display->width - x, height);
|
2006-03-25 13:35:31 +00:00
|
|
|
}
|
2002-09-27 09:44:51 +00:00
|
|
|
/**
|
|
|
|
* Draws a peak meter in the specified size at the specified position.
|
|
|
|
* @param int x - The x coordinate.
|
2006-03-25 13:35:31 +00:00
|
|
|
* Make sure that 0 <= x and x + width < display->width
|
2002-09-27 09:44:51 +00:00
|
|
|
* @param int y - The y coordinate.
|
2006-03-25 13:35:31 +00:00
|
|
|
* Make sure that 0 <= y and y + height < display->height
|
2002-09-27 09:44:51 +00:00
|
|
|
* @param int width - The width of the peak meter. Note that for display
|
|
|
|
* of clips a 3 pixel wide area is used ->
|
|
|
|
* width > 3
|
|
|
|
* @param int height - The height of the peak meter. height > 3
|
|
|
|
*/
|
2007-09-20 16:44:28 +00:00
|
|
|
static void peak_meter_draw(struct screen *display, struct meter_scales *scales,
|
2006-03-25 13:35:31 +00:00
|
|
|
int x, int y, int width, int height)
|
2005-06-24 22:33:21 +00:00
|
|
|
{
|
2006-03-25 13:35:31 +00:00
|
|
|
static int left_level = 0, right_level = 0;
|
2002-09-27 09:44:51 +00:00
|
|
|
int left = 0, right = 0;
|
|
|
|
int meterwidth = width - 3;
|
2007-08-20 06:36:24 +00:00
|
|
|
int i, delta;
|
2008-02-06 21:53:07 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && !defined (ROCKBOX_HAS_LOGF)
|
|
|
|
static long peak_release_tick[2] = {0,0};
|
|
|
|
int screen_nr = display->screen_type == SCREEN_MAIN ? 0 : 1;
|
|
|
|
#else
|
2007-08-18 23:03:03 +00:00
|
|
|
static long peak_release_tick = 0;
|
2008-02-06 21:53:07 +00:00
|
|
|
#endif
|
2002-09-27 09:44:51 +00:00
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
#ifdef PM_DEBUG
|
|
|
|
static long pm_tick = 0;
|
|
|
|
int tmp = peek_calls;
|
|
|
|
#endif
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/* if disabled only draw the peak meter */
|
|
|
|
if (peak_meter_enabled) {
|
2002-10-29 12:09:15 +00:00
|
|
|
|
|
|
|
|
2006-03-25 13:35:31 +00:00
|
|
|
if (level_check){
|
|
|
|
/* only read the volume info from MAS if peek since last read*/
|
|
|
|
left_level = peak_meter_read_l();
|
|
|
|
right_level = peak_meter_read_r();
|
|
|
|
level_check = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scale the samples dBfs */
|
|
|
|
left = peak_meter_scale_value(left_level, meterwidth);
|
|
|
|
right = peak_meter_scale_value(right_level, meterwidth);
|
|
|
|
|
|
|
|
/*if the scale has changed -> recalculate the scale
|
2002-10-29 12:09:15 +00:00
|
|
|
(The scale becomes invalid when the range changed.) */
|
2006-03-25 13:35:31 +00:00
|
|
|
if (!scales->db_scale_valid){
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_use_dbfs) {
|
2002-10-30 23:01:27 +00:00
|
|
|
db_scale_count = DB_SCALE_SRC_VALUES_SIZE;
|
2002-10-29 12:09:15 +00:00
|
|
|
for (i = 0; i < db_scale_count; i++){
|
|
|
|
/* find the real x-coords for predefined interesting
|
|
|
|
dBfs values. These only are recalculated when the
|
|
|
|
scaling of the meter changed. */
|
2006-03-25 13:35:31 +00:00
|
|
|
scales->db_scale_lcd_coord[i] =
|
2002-10-29 12:09:15 +00:00
|
|
|
peak_meter_scale_value(
|
|
|
|
db_scale_src_values[i],
|
|
|
|
meterwidth - 1);
|
|
|
|
}
|
|
|
|
}
|
2002-09-27 09:44:51 +00:00
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/* when scaling linear we simly make 10% steps */
|
|
|
|
else {
|
|
|
|
db_scale_count = 10;
|
|
|
|
for (i = 0; i < db_scale_count; i++) {
|
2006-03-25 13:35:31 +00:00
|
|
|
scales->db_scale_lcd_coord[i] =
|
2002-10-29 12:09:15 +00:00
|
|
|
(i * (MAX_PEAK / 10) - peak_meter_range_min) *
|
2005-08-29 20:07:17 +00:00
|
|
|
meterwidth / pm_range;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mark scale valid to avoid recalculating dBfs values
|
|
|
|
of the scale. */
|
2006-03-25 13:35:31 +00:00
|
|
|
scales->db_scale_valid = true;
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
2002-09-27 09:44:51 +00:00
|
|
|
|
|
|
|
/* apply release */
|
2008-02-06 21:53:07 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && !defined (ROCKBOX_HAS_LOGF)
|
|
|
|
delta = current_tick - peak_release_tick[screen_nr];
|
|
|
|
peak_release_tick[screen_nr] = current_tick;
|
|
|
|
#else
|
2007-08-20 06:36:24 +00:00
|
|
|
delta = current_tick - peak_release_tick;
|
|
|
|
peak_release_tick = current_tick;
|
2008-02-06 21:53:07 +00:00
|
|
|
#endif
|
2007-08-20 06:36:24 +00:00
|
|
|
left = MAX(left , scales->last_left - delta * pm_peak_release);
|
|
|
|
right = MAX(right, scales->last_right - delta * pm_peak_release);
|
|
|
|
|
2002-09-27 09:44:51 +00:00
|
|
|
/* reset max values after timeout */
|
2006-03-25 13:35:31 +00:00
|
|
|
if (TIME_AFTER(current_tick, scales->pm_peak_timeout_l)){
|
|
|
|
scales->pm_peak_left = 0;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 13:35:31 +00:00
|
|
|
if (TIME_AFTER(current_tick, scales->pm_peak_timeout_r)){
|
|
|
|
scales->pm_peak_right = 0;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
if (!pm_clip_eternal) {
|
|
|
|
if (pm_clip_left &&
|
|
|
|
TIME_AFTER(current_tick, pm_clip_timeout_l)){
|
|
|
|
pm_clip_left = false;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_clip_right &&
|
|
|
|
TIME_AFTER(current_tick, pm_clip_timeout_r)){
|
|
|
|
pm_clip_right = false;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for new max values */
|
2006-03-25 13:35:31 +00:00
|
|
|
if (left > scales->pm_peak_left) {
|
|
|
|
scales->pm_peak_left = left - 1;
|
|
|
|
scales->pm_peak_timeout_l =
|
2005-08-29 20:07:17 +00:00
|
|
|
current_tick + peak_time_out[pm_peak_hold];
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 13:35:31 +00:00
|
|
|
if (right > scales->pm_peak_right) {
|
|
|
|
scales->pm_peak_right = right - 1;
|
|
|
|
scales->pm_peak_timeout_r =
|
2005-08-29 20:07:17 +00:00
|
|
|
current_tick + peak_time_out[pm_peak_hold];
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the peak meter */
|
2006-03-25 13:35:31 +00:00
|
|
|
display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
|
|
|
display->fillrect(x, y, width, height);
|
|
|
|
display->set_drawmode(DRMODE_SOLID);
|
2002-09-27 09:44:51 +00:00
|
|
|
|
|
|
|
/* draw left */
|
2006-03-25 13:35:31 +00:00
|
|
|
display->fillrect (x, y, left, height / 2 - 2 );
|
|
|
|
if (scales->pm_peak_left > 0) {
|
|
|
|
display->vline(x + scales->pm_peak_left, y, y + height / 2 - 2 );
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_clip_left) {
|
2006-03-25 13:35:31 +00:00
|
|
|
display->fillrect(x + meterwidth, y, 3, height / 2 - 1);
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw right */
|
2006-03-25 13:35:31 +00:00
|
|
|
display->fillrect(x, y + height / 2 + 1, right, height / 2 - 2);
|
|
|
|
if (scales->pm_peak_right > 0) {
|
|
|
|
display->vline( x + scales->pm_peak_right, y + height / 2, y + height - 2);
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
if (pm_clip_right) {
|
2006-03-25 13:35:31 +00:00
|
|
|
display->fillrect(x + meterwidth, y + height / 2, 3, height / 2 - 1);
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/* draw scale end */
|
2006-03-25 13:35:31 +00:00
|
|
|
display->vline(x + meterwidth, y, y + height - 2);
|
2005-06-25 00:28:09 +00:00
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/* draw dots for scale marks */
|
|
|
|
for (i = 0; i < db_scale_count; i++) {
|
|
|
|
/* The x-coordinates of interesting scale mark points
|
|
|
|
have been calculated before */
|
2006-04-03 08:20:20 +00:00
|
|
|
display->drawpixel(x + scales->db_scale_lcd_coord[i],
|
|
|
|
y + height / 2 - 1);
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
2006-02-17 22:47:56 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDING
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2007-04-12 22:12:13 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2006-02-17 22:47:56 +00:00
|
|
|
/* cliplight */
|
|
|
|
if ((pm_clip_left || pm_clip_right) &&
|
|
|
|
global_settings.cliplight &&
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2006-02-24 19:17:47 +00:00
|
|
|
!pm_playback)
|
2006-02-17 22:47:56 +00:00
|
|
|
#else
|
2006-02-24 19:17:47 +00:00
|
|
|
!(audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_ERROR)))
|
2006-02-17 22:47:56 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* if clipping, cliplight setting on and in recording screen */
|
|
|
|
if (global_settings.cliplight <= 2)
|
|
|
|
{
|
|
|
|
/* turn on main unit light if setting set to main or both*/
|
|
|
|
backlight_on();
|
|
|
|
}
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
if (global_settings.cliplight >= 2)
|
|
|
|
{
|
|
|
|
/* turn remote light unit on if setting set to remote or both */
|
|
|
|
remote_backlight_on();
|
|
|
|
}
|
|
|
|
#endif /* HAVE_REMOTE_LCD */
|
|
|
|
}
|
2007-04-12 22:12:13 +00:00
|
|
|
#endif /* HAVE_BACKLIGHT */
|
2005-06-24 22:33:21 +00:00
|
|
|
|
2005-04-04 09:12:12 +00:00
|
|
|
if (trig_status != TRIG_OFF) {
|
|
|
|
int start_trigx, stop_trigx, ycenter;
|
|
|
|
|
2006-03-25 13:35:31 +00:00
|
|
|
display->set_drawmode(DRMODE_SOLID);
|
2005-04-04 09:12:12 +00:00
|
|
|
ycenter = y + height / 2;
|
|
|
|
/* display threshold value */
|
|
|
|
start_trigx = x+peak_meter_scale_value(trig_strt_threshold,meterwidth);
|
2006-03-25 13:35:31 +00:00
|
|
|
display->vline(start_trigx, ycenter - 2, ycenter);
|
2005-04-04 09:12:12 +00:00
|
|
|
start_trigx ++;
|
2006-03-25 13:35:31 +00:00
|
|
|
if (start_trigx < display->width ) display->drawpixel(start_trigx, ycenter - 1);
|
2005-04-04 09:12:12 +00:00
|
|
|
|
|
|
|
stop_trigx = x + peak_meter_scale_value(trig_stp_threshold,meterwidth);
|
2006-03-25 13:35:31 +00:00
|
|
|
display->vline(stop_trigx, ycenter - 2, ycenter);
|
|
|
|
if (stop_trigx > 0) display->drawpixel(stop_trigx - 1, ycenter - 1);
|
2005-04-04 09:12:12 +00:00
|
|
|
}
|
2006-02-17 22:47:56 +00:00
|
|
|
#endif /*HAVE_RECORDING*/
|
2005-04-04 09:12:12 +00:00
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
#ifdef PM_DEBUG
|
2007-03-19 16:49:55 +00:00
|
|
|
/* display a bar to show how many calls to peak_meter_peek
|
2002-10-29 12:09:15 +00:00
|
|
|
have ocurred since the last display */
|
2006-03-25 13:35:31 +00:00
|
|
|
display->set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
display->fillrect(x, y, tmp, 3);
|
2002-10-29 12:09:15 +00:00
|
|
|
|
|
|
|
if (tmp < PEEKS_PER_DRAW_SIZE) {
|
|
|
|
peeks_per_redraw[tmp]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = current_tick - pm_tick;
|
|
|
|
if (tmp < TICKS_PER_DRAW_SIZE ){
|
|
|
|
ticks_per_redraw[tmp] ++;
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
/* display a bar to show how many ticks have passed since
|
|
|
|
the last redraw */
|
2006-03-25 13:35:31 +00:00
|
|
|
display->fillrect(x, y + height / 2, current_tick - pm_tick, 2);
|
2002-10-29 12:09:15 +00:00
|
|
|
pm_tick = current_tick;
|
|
|
|
#endif
|
|
|
|
|
2006-03-25 13:35:31 +00:00
|
|
|
scales->last_left = left;
|
|
|
|
scales->last_right = right;
|
2005-06-24 22:33:21 +00:00
|
|
|
|
2006-03-25 13:35:31 +00:00
|
|
|
display->set_drawmode(DRMODE_SOLID);
|
2002-09-27 09:44:51 +00:00
|
|
|
}
|
2002-10-29 12:09:15 +00:00
|
|
|
|
2005-04-04 20:16:01 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2005-04-04 09:12:12 +00:00
|
|
|
/**
|
|
|
|
* Defines the parameters of the trigger. After these parameters are defined
|
|
|
|
* the trigger can be started either by peak_meter_attack_trigger or by
|
|
|
|
* peak_meter_release_trigger. Note that you can pass either linear (%) or
|
|
|
|
* logarithmic (db) values to the thresholds. Positive values are intepreted as
|
|
|
|
* percent (0 is 0% .. 100 is 100%). Negative values are interpreted as db.
|
|
|
|
* To avoid ambiguosity of the value 0 the negative values are shifted by -1.
|
|
|
|
* Thus -75 is -74db .. -1 is 0db.
|
|
|
|
* @param start_threshold - The threshold used for attack trigger. Negative
|
|
|
|
* values are interpreted as db -1, positive as %.
|
|
|
|
* @param start_duration - The minimum time span within which start_threshold
|
|
|
|
* must be exceeded to fire the attack trigger.
|
|
|
|
* @param start_dropout - The maximum time span the level may fall below
|
|
|
|
* start_threshold without releasing the attack trigger.
|
|
|
|
* @param stop_threshold - The threshold the volume must fall below to release
|
|
|
|
* the release trigger.Negative values are
|
|
|
|
* interpreted as db -1, positive as %.
|
|
|
|
* @param stop_hold - The minimum time the volume must fall below the
|
|
|
|
* stop_threshold to release the trigger.
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
void peak_meter_define_trigger(
|
|
|
|
int start_threshold,
|
|
|
|
long start_duration,
|
|
|
|
long start_dropout,
|
|
|
|
int stop_threshold,
|
|
|
|
long stop_hold_time,
|
|
|
|
long restart_gap
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (start_threshold < 0) {
|
|
|
|
/* db */
|
|
|
|
if (start_threshold < -89) {
|
|
|
|
trig_strt_threshold = 0;
|
|
|
|
} else {
|
|
|
|
trig_strt_threshold =peak_meter_db2sample((start_threshold+1)*100);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* linear percent */
|
|
|
|
trig_strt_threshold = start_threshold * MAX_PEAK / 100;
|
|
|
|
}
|
|
|
|
trig_strt_duration = start_duration;
|
|
|
|
trig_strt_dropout = start_dropout;
|
|
|
|
if (stop_threshold < 0) {
|
|
|
|
/* db */
|
|
|
|
trig_stp_threshold = peak_meter_db2sample((stop_threshold + 1) * 100);
|
|
|
|
} else {
|
|
|
|
/* linear percent */
|
|
|
|
trig_stp_threshold = stop_threshold * MAX_PEAK / 100;
|
|
|
|
}
|
|
|
|
trig_stp_hold = stop_hold_time;
|
|
|
|
trig_rstrt_gap = restart_gap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables or disables the trigger.
|
|
|
|
* @param on - If true the trigger is turned on.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
void peak_meter_trigger(bool on)
|
|
|
|
{
|
2005-04-04 09:12:12 +00:00
|
|
|
/* don't use set_trigger here as that would fire an undesired event */
|
|
|
|
trig_status = on ? TRIG_READY : TRIG_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the listener function that listenes on trig_status changes.
|
|
|
|
* @param listener - The function that is called with each change of
|
|
|
|
* trig_status. May be set to NULL if no callback is desired.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
void peak_meter_set_trigger_listener(void (*listener)(int status))
|
|
|
|
{
|
2005-04-04 09:12:12 +00:00
|
|
|
trigger_listener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the status of the trigger.
|
|
|
|
* TRIG_OFF: the trigger is inactive
|
|
|
|
* TRIG_RELEASED: The volume level is below the threshold
|
|
|
|
* TRIG_ACTIVATED: The volume level has exceeded the threshold, but the trigger
|
|
|
|
* hasn't been fired yet.
|
|
|
|
* TRIG_FIRED: The volume exceeds the threshold
|
|
|
|
*
|
|
|
|
* To activate the trigger call either peak_meter_attack_trigger or
|
|
|
|
* peak_meter_release_trigger. To turn the trigger off call
|
|
|
|
* peak_meter_trigger_off.
|
|
|
|
*/
|
2005-08-29 20:07:17 +00:00
|
|
|
int peak_meter_trigger_status(void)
|
|
|
|
{
|
2005-04-04 09:12:12 +00:00
|
|
|
return trig_status; /* & TRIG_PIT_MASK;*/
|
|
|
|
}
|
|
|
|
|
2006-11-09 12:27:56 +00:00
|
|
|
void peak_meter_draw_trig(int xpos[], int ypos[], int trig_width[], int nb_screens)
|
2005-08-29 20:07:17 +00:00
|
|
|
{
|
2006-11-09 12:27:56 +00:00
|
|
|
int barstart[NB_SCREENS];
|
|
|
|
int barend[NB_SCREENS];
|
|
|
|
int icon;
|
|
|
|
int ixpos[NB_SCREENS];
|
2006-07-19 15:30:40 +00:00
|
|
|
int i;
|
2006-11-09 12:27:56 +00:00
|
|
|
int trigbar_width[NB_SCREENS];
|
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
trigbar_width[i] = (trig_width[i] - (2 * (ICON_PLAY_STATE_WIDTH + 1)));
|
|
|
|
|
2005-04-04 09:12:12 +00:00
|
|
|
switch (trig_status) {
|
|
|
|
|
|
|
|
case TRIG_READY:
|
2006-11-09 12:27:56 +00:00
|
|
|
FOR_NB_SCREENS(i){
|
|
|
|
barstart[i] = 0;
|
|
|
|
barend[i] = 0;
|
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
icon = Icon_Stop;
|
2006-11-09 12:27:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
ixpos[i] = xpos[i];
|
2005-04-04 09:12:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TRIG_STEADY:
|
2006-11-09 12:27:56 +00:00
|
|
|
case TRIG_RETRIG:
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
barstart[i] = 0;
|
|
|
|
barend[i] = (trig_strt_duration == 0) ? trigbar_width[i] :
|
|
|
|
trigbar_width[i] *
|
|
|
|
(current_tick - trig_hightime) / trig_strt_duration;
|
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
icon = Icon_Stop;
|
2006-11-09 12:27:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
ixpos[i] = xpos[i];
|
2005-04-04 09:12:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TRIG_GO:
|
|
|
|
case TRIG_CONTINUE:
|
2006-11-09 12:27:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
barstart[i] = trigbar_width[i];
|
|
|
|
barend[i] = trigbar_width[i];
|
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
icon = Icon_Record;
|
2006-11-09 12:27:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
ixpos[i] = xpos[i]+ trig_width[i] - ICON_PLAY_STATE_WIDTH;
|
2005-04-04 09:12:12 +00:00
|
|
|
break;
|
|
|
|
|
2006-11-09 12:27:56 +00:00
|
|
|
case TRIG_POSTREC:
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
barstart[i] = (trig_stp_hold == 0) ? 0 :
|
|
|
|
trigbar_width[i] - trigbar_width[i] *
|
|
|
|
(current_tick - trig_lowtime) / trig_stp_hold;
|
|
|
|
barend[i] = trigbar_width[i];
|
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
icon = Icon_Record;
|
2006-11-09 12:27:56 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
ixpos[i] = xpos[i] + trig_width[i] - ICON_PLAY_STATE_WIDTH;
|
2005-04-04 09:12:12 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2006-11-09 12:27:56 +00:00
|
|
|
|
|
|
|
for(i = 0; i < nb_screens; i++)
|
2006-07-19 15:30:40 +00:00
|
|
|
{
|
2006-11-09 12:27:56 +00:00
|
|
|
gui_scrollbar_draw(&screens[i], xpos[i] + ICON_PLAY_STATE_WIDTH + 1,
|
|
|
|
ypos[i] + 1, trigbar_width[i], TRIG_HEIGHT - 2,
|
|
|
|
trigbar_width[i], barstart[i], barend[i],
|
|
|
|
HORIZONTAL);
|
|
|
|
|
|
|
|
screens[i].mono_bitmap(bitmap_icons_7x8[icon], ixpos[i], ypos[i],
|
2006-07-19 15:30:40 +00:00
|
|
|
ICON_PLAY_STATE_WIDTH, STATUSBAR_HEIGHT);
|
|
|
|
}
|
2005-04-04 09:12:12 +00:00
|
|
|
}
|
2005-04-04 20:16:01 +00:00
|
|
|
#endif
|
2005-04-04 09:12:12 +00:00
|
|
|
|
2006-07-31 12:55:27 +00:00
|
|
|
int peak_meter_draw_get_btn(int x, int y[], int height, int nb_screens)
|
2005-04-04 09:12:12 +00:00
|
|
|
{
|
2005-08-29 20:07:17 +00:00
|
|
|
int button = BUTTON_NONE;
|
2005-04-04 09:12:12 +00:00
|
|
|
long next_refresh = current_tick;
|
|
|
|
long next_big_refresh = current_tick + HZ / 10;
|
2006-03-25 13:35:31 +00:00
|
|
|
int i;
|
2007-10-16 08:34:51 +00:00
|
|
|
#if (CONFIG_CODEC == SWCODEC) || defined(SIMULATOR)
|
2005-08-29 20:07:17 +00:00
|
|
|
bool highperf = false;
|
2007-10-16 08:34:51 +00:00
|
|
|
#else
|
|
|
|
/* On MAS targets, we need to poll as often as possible in order to not
|
|
|
|
* miss a peak, as the MAS does only provide a quasi-peak. When the disk
|
|
|
|
* is active, it must not draw too much CPU power or a buffer overrun can
|
|
|
|
* happen when saving a recording. As a compromise, poll only once per tick
|
|
|
|
* when the disk is active, otherwise spin around as fast as possible. */
|
|
|
|
bool highperf = !ata_disk_is_active();
|
2005-08-29 20:07:17 +00:00
|
|
|
#endif
|
|
|
|
bool dopeek = true;
|
2005-06-04 09:48:03 +00:00
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
while (TIME_BEFORE(current_tick, next_big_refresh)) {
|
2006-08-20 21:33:40 +00:00
|
|
|
button = get_action(CONTEXT_RECSCREEN, TIMEOUT_NOBLOCK);
|
2005-04-04 09:12:12 +00:00
|
|
|
if (button != BUTTON_NONE) {
|
|
|
|
break;
|
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
if (dopeek) { /* Peek only once per refresh when disk is */
|
|
|
|
peak_meter_peek(); /* spinning, but as often as possible */
|
|
|
|
dopeek = highperf; /* otherwise. */
|
|
|
|
yield();
|
|
|
|
} else {
|
|
|
|
sleep(0); /* Sleep until end of current tick. */
|
|
|
|
}
|
|
|
|
if (TIME_AFTER(current_tick, next_refresh)) {
|
2006-07-31 12:55:27 +00:00
|
|
|
for(i = 0; i < nb_screens; i++)
|
2006-03-25 13:35:31 +00:00
|
|
|
{
|
2006-07-20 22:44:10 +00:00
|
|
|
peak_meter_screen(&screens[i], x, y[i], height);
|
2007-08-25 15:53:54 +00:00
|
|
|
screens[i].update_rect(x, y[i], screens[i].width - x, height);
|
2006-03-25 13:35:31 +00:00
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
next_refresh += HZ / PEAK_METER_FPS;
|
|
|
|
dopeek = true;
|
|
|
|
}
|
2005-04-04 09:12:12 +00:00
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
|
2005-04-04 09:12:12 +00:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
#ifdef PM_DEBUG
|
2005-08-29 20:07:17 +00:00
|
|
|
static void peak_meter_clear_histogram(void)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < TICKS_PER_DRAW_SIZE; i++) {
|
|
|
|
ticks_per_redraw[i] = (unsigned int)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < PEEKS_PER_DRAW_SIZE; i++) {
|
|
|
|
peeks_per_redraw[i] = (unsigned int)0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-29 20:07:17 +00:00
|
|
|
bool peak_meter_histogram(void)
|
|
|
|
{
|
2002-10-29 12:09:15 +00:00
|
|
|
int i;
|
|
|
|
int btn = BUTTON_NONE;
|
|
|
|
while ((btn & BUTTON_OFF) != BUTTON_OFF )
|
|
|
|
{
|
|
|
|
unsigned int max = 0;
|
|
|
|
int y = 0;
|
|
|
|
int x = 0;
|
2006-07-19 15:30:40 +00:00
|
|
|
screens[0].clear_display();
|
2002-10-29 12:09:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i < PEEKS_PER_DRAW_SIZE; i++) {
|
|
|
|
max = MAX(max, peeks_per_redraw[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < PEEKS_PER_DRAW_SIZE; i++) {
|
|
|
|
x = peeks_per_redraw[i] * (LCD_WIDTH - 1)/ max;
|
2006-07-19 15:30:40 +00:00
|
|
|
screens[0].hline(0, x, y + i);
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
y = PEEKS_PER_DRAW_SIZE + 1;
|
|
|
|
max = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < TICKS_PER_DRAW_SIZE; i++) {
|
|
|
|
max = MAX(max, ticks_per_redraw[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < TICKS_PER_DRAW_SIZE; i++) {
|
|
|
|
x = ticks_per_redraw[i] * (LCD_WIDTH - 1)/ max;
|
2006-07-19 15:30:40 +00:00
|
|
|
screens[0].hline(0, x, y + i);
|
2002-10-29 12:09:15 +00:00
|
|
|
}
|
2006-07-19 15:30:40 +00:00
|
|
|
screens[0].update();
|
2005-08-29 20:07:17 +00:00
|
|
|
|
2002-10-29 12:09:15 +00:00
|
|
|
btn = button_get(true);
|
|
|
|
if (btn == BUTTON_PLAY) {
|
|
|
|
peak_meter_clear_histogram();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-02-02 21:49:19 +00:00
|
|
|
#endif
|
|
|
|
|