2009-09-08 16:45:05 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-08-28 17:52:31 +00:00
|
|
|
* $Id$
|
2009-09-08 16:45:05 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Lechner Michael / smoking gnu
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* INTRODUCTION:
|
|
|
|
* OK, this is an attempt to write an instrument tuner for rockbox.
|
2010-08-28 17:52:31 +00:00
|
|
|
* It uses a Schmitt trigger algorithm, which I copied from
|
|
|
|
* tuneit [ (c) 2004 Mario Lang <mlang@delysid.org> ], for detecting the
|
|
|
|
* fundamental freqency of a sound. A FFT algorithm would be more accurate
|
2009-09-08 16:45:05 +00:00
|
|
|
* but also much slower.
|
2010-08-28 17:52:31 +00:00
|
|
|
*
|
2009-09-08 16:45:05 +00:00
|
|
|
* TODO:
|
|
|
|
* - Adapt the Yin FFT algorithm, which would reduce complexity from O(n^2)
|
|
|
|
* to O(nlogn), theoretically reducing latency by a factor of ~10. -David
|
2010-08-28 17:52:31 +00:00
|
|
|
*
|
2009-09-08 16:45:05 +00:00
|
|
|
* MAJOR CHANGES:
|
|
|
|
* 08.03.2008 Started coding
|
|
|
|
* 21.03.2008 Pitch detection works more or less
|
|
|
|
* Button definitions for most targets added
|
|
|
|
* 02.04.2008 Proper GUI added
|
|
|
|
* Todo, Major Changes and Current Limitations added
|
|
|
|
* 08.19.2009 Brought the code up to date with current plugin standards
|
|
|
|
* Made it work more nicely with color, BW and grayscale
|
|
|
|
* Changed pitch detection to use the Yin algorithm (better
|
|
|
|
* detection, but slower -- would be ~4x faster with
|
|
|
|
* fixed point math, I think). Code was poached from the
|
|
|
|
* Aubio sound processing library (aubio.org). -David
|
|
|
|
* 08.31.2009 Lots of changes:
|
|
|
|
* Added a menu to tweak settings
|
2010-08-28 17:52:31 +00:00
|
|
|
* Converted everything to fixed point (greatly improving
|
2009-09-08 16:45:05 +00:00
|
|
|
* latency)
|
|
|
|
* Improved the display
|
|
|
|
* Improved efficiency with judicious use of cpu_boost, the
|
|
|
|
* backlight, and volume detection to limit unneeded
|
|
|
|
* calculation
|
|
|
|
* Fixed a problem that caused an octave-off error
|
|
|
|
* -David
|
2010-05-14 06:25:40 +00:00
|
|
|
* 05.14.2010 Multibuffer continuous recording with two buffers
|
2010-08-28 17:52:31 +00:00
|
|
|
*
|
|
|
|
*
|
2009-09-08 16:45:05 +00:00
|
|
|
* CURRENT LIMITATIONS:
|
|
|
|
* - No gapless recording. Strictly speaking true gappless isn't possible,
|
|
|
|
* since the algorithm takes longer to calculate than the length of the
|
|
|
|
* sample, but latency could be improved a bit with proper use of the DMA
|
|
|
|
* recording functions.
|
2010-08-28 17:52:31 +00:00
|
|
|
* - Due to how the Yin algorithm works, latency is higher for lower
|
2009-09-08 16:45:05 +00:00
|
|
|
* frequencies.
|
|
|
|
*/
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
#include "plugin.h"
|
|
|
|
#include "lib/pluginlib_actions.h"
|
2009-09-12 21:19:17 +00:00
|
|
|
#include "lib/picture.h"
|
2010-05-14 06:25:40 +00:00
|
|
|
#include "lib/helper.h"
|
2009-09-12 21:19:17 +00:00
|
|
|
#include "pluginbitmaps/pitch_notes.h"
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Some fixed point calculation stuff */
|
2010-09-14 06:34:01 +00:00
|
|
|
typedef int32_t fixed;
|
2009-09-08 16:45:05 +00:00
|
|
|
#define FIXED_PRECISION 18
|
|
|
|
#define FP_MAX ((fixed) {0x7fffffff})
|
|
|
|
#define FP_MIN ((fixed) {-0x80000000})
|
2010-09-14 06:34:01 +00:00
|
|
|
#define int2fixed(x) ((fixed)((x) << FIXED_PRECISION))
|
|
|
|
#define int2mantissa(x) ((fixed)(x))
|
|
|
|
#define fixed2int(x) ((int)((x) >> FIXED_PRECISION))
|
|
|
|
#define fixed2float(x) (((float)(x)) / ((float)(1 << FIXED_PRECISION)))
|
|
|
|
#define float2fixed(x) ((fixed)(x * (float)(1 << FIXED_PRECISION)))
|
2010-09-07 14:09:16 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* I adapted these ones from the Rockbox fixed point library */
|
|
|
|
#define fp_mul(x, y) \
|
2010-09-14 06:34:01 +00:00
|
|
|
((fixed)((((int64_t)((x))) * ((int64_t)((y)))) >> (FIXED_PRECISION)))
|
2009-09-08 16:45:05 +00:00
|
|
|
#define fp_div(x, y) \
|
2010-09-14 06:34:01 +00:00
|
|
|
((fixed)((((int64_t)((x))) << (FIXED_PRECISION)) / ((int64_t)((y)))))
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Operators for fixed point */
|
2010-09-14 06:34:01 +00:00
|
|
|
#define fp_add(x, y) ((fixed)((x) + (y)))
|
|
|
|
#define fp_sub(x, y) ((fixed)((x) - (y)))
|
|
|
|
#define fp_shl(x, y) ((fixed)((x) << (y)))
|
|
|
|
#define fp_shr(x, y) ((fixed)((x) >> (y)))
|
|
|
|
#define fp_neg(x) ((fixed)(-(x)))
|
|
|
|
#define fp_gt(x, y) ((x) > (y))
|
|
|
|
#define fp_gte(x, y) ((x) >= (y))
|
|
|
|
#define fp_lt(x, y) ((x) < (y))
|
|
|
|
#define fp_lte(x, y) ((x) <= (y))
|
2009-09-08 16:45:05 +00:00
|
|
|
#define fp_sqr(x) fp_mul((x), (x))
|
2010-09-14 06:34:01 +00:00
|
|
|
#define fp_equal(x, y) ((x) == (y))
|
2009-09-08 16:45:05 +00:00
|
|
|
#define fp_round(x) (fixed2int(fp_add((x), float2fixed(0.5))))
|
2010-09-14 06:34:01 +00:00
|
|
|
#define fp_data(x) (x)
|
2009-09-08 16:45:05 +00:00
|
|
|
#define fp_frac(x) (fp_sub((x), int2fixed(fixed2int(x))))
|
2010-09-14 06:34:01 +00:00
|
|
|
#define FP_ZERO ((fixed)0)
|
|
|
|
#define FP_LOW ((fixed)2)
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
/* Some defines for converting between period and frequency */
|
2009-09-12 21:19:17 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* I introduce some divisors in this because the fixed point */
|
|
|
|
/* variables aren't big enough to hold higher than a certain */
|
2009-09-12 21:19:17 +00:00
|
|
|
/* value. This loses a bit of precision but it means we */
|
2009-09-08 16:45:05 +00:00
|
|
|
/* don't have to use 32.32 variables (yikes). */
|
|
|
|
/* With an 18-bit decimal precision, the max value in the */
|
|
|
|
/* integer part is 8192. Divide 44100 by 7 and it'll fit in */
|
|
|
|
/* that variable. */
|
2010-05-14 06:25:40 +00:00
|
|
|
#define fp_period2freq(x) fp_div(int2fixed(sample_rate / 7), \
|
2009-09-08 16:45:05 +00:00
|
|
|
fp_div((x),int2fixed(7)))
|
|
|
|
#define fp_freq2period(x) fp_period2freq(x)
|
2010-05-14 06:25:40 +00:00
|
|
|
#define period2freq(x) (sample_rate / (x))
|
2009-09-08 16:45:05 +00:00
|
|
|
#define freq2period(x) period2freq(x)
|
|
|
|
|
|
|
|
#define sqr(x) ((x)*(x))
|
|
|
|
|
|
|
|
/* Some constants for tuning */
|
|
|
|
#define A_FREQ float2fixed(440.0f)
|
|
|
|
#define D_NOTE float2fixed(1.059463094359f)
|
|
|
|
#define LOG_D_NOTE float2fixed(1.0f/12.0f)
|
|
|
|
#define D_NOTE_SQRT float2fixed(1.029302236643f)
|
|
|
|
#define LOG_2 float2fixed(1.0f)
|
|
|
|
|
|
|
|
/* The recording buffer size */
|
|
|
|
/* This is how much is sampled at a time. */
|
2010-05-14 06:25:40 +00:00
|
|
|
/* It also determines latency -- if BUFFER_SIZE == sample_rate then */
|
2009-09-08 16:45:05 +00:00
|
|
|
/* there'll be one sample per second, or a latency of one second. */
|
|
|
|
/* Furthermore, the lowest detectable frequency will be about twice */
|
|
|
|
/* the number of reads per second */
|
2010-08-28 17:52:31 +00:00
|
|
|
/* If we ever switch to Yin FFT algorithm then this needs to be
|
2009-09-08 16:45:05 +00:00
|
|
|
a power of 2 */
|
|
|
|
#define BUFFER_SIZE 4096
|
|
|
|
#define SAMPLE_SIZE 4096
|
|
|
|
#define SAMPLE_SIZE_MIN 1024
|
|
|
|
#define YIN_BUFFER_SIZE (BUFFER_SIZE / 4)
|
|
|
|
|
|
|
|
#define LCD_FACTOR (fp_div(int2fixed(LCD_WIDTH), int2fixed(100)))
|
|
|
|
/* The threshold for the YIN algorithm */
|
2009-09-12 21:19:17 +00:00
|
|
|
#define DEFAULT_YIN_THRESHOLD 5 /* 0.10 */
|
2010-08-28 17:52:31 +00:00
|
|
|
static const fixed yin_threshold_table[] IDATA_ATTR =
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2010-09-14 06:34:01 +00:00
|
|
|
float2fixed(0.01),
|
|
|
|
float2fixed(0.02),
|
|
|
|
float2fixed(0.03),
|
|
|
|
float2fixed(0.04),
|
|
|
|
float2fixed(0.05),
|
|
|
|
float2fixed(0.10),
|
|
|
|
float2fixed(0.15),
|
|
|
|
float2fixed(0.20),
|
|
|
|
float2fixed(0.25),
|
|
|
|
float2fixed(0.30),
|
|
|
|
float2fixed(0.35),
|
|
|
|
float2fixed(0.40),
|
|
|
|
float2fixed(0.45),
|
|
|
|
float2fixed(0.50),
|
2009-09-12 21:19:17 +00:00
|
|
|
};
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2009-09-20 16:16:32 +00:00
|
|
|
/* Structure for the reference frequency (frequency of A)
|
|
|
|
* It's used for scaling the frequency before finding out
|
|
|
|
* the note. The frequency is scaled in a way that the main
|
|
|
|
* algorithm can assume the frequency of A to be 440 Hz.
|
|
|
|
*/
|
2010-08-28 17:52:31 +00:00
|
|
|
static const struct
|
2009-09-20 16:16:32 +00:00
|
|
|
{
|
|
|
|
const int frequency; /* Frequency in Hz */
|
|
|
|
const fixed ratio; /* 440/frequency */
|
|
|
|
const fixed logratio; /* log2(factor) */
|
2010-08-28 17:52:31 +00:00
|
|
|
} freq_A[] =
|
2009-09-20 16:16:32 +00:00
|
|
|
{
|
2010-09-14 06:34:01 +00:00
|
|
|
{435, float2fixed(1.011363636), float2fixed( 0.016301812)},
|
|
|
|
{436, float2fixed(1.009090909), float2fixed( 0.013056153)},
|
|
|
|
{437, float2fixed(1.006818182), float2fixed( 0.009803175)},
|
|
|
|
{438, float2fixed(1.004545455), float2fixed( 0.006542846)},
|
|
|
|
{439, float2fixed(1.002272727), float2fixed( 0.003275132)},
|
|
|
|
{440, float2fixed(1.000000000), float2fixed( 0.000000000)},
|
|
|
|
{441, float2fixed(0.997727273), float2fixed(-0.003282584)},
|
|
|
|
{442, float2fixed(0.995454545), float2fixed(-0.006572654)},
|
|
|
|
{443, float2fixed(0.993181818), float2fixed(-0.009870244)},
|
|
|
|
{444, float2fixed(0.990909091), float2fixed(-0.013175389)},
|
|
|
|
{445, float2fixed(0.988636364), float2fixed(-0.016488123)},
|
2009-09-20 16:16:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Index of the entry for 440 Hz in the table (default frequency for A) */
|
|
|
|
#define DEFAULT_FREQ_A 5
|
|
|
|
#define NUM_FREQ_A (sizeof(freq_A)/sizeof(freq_A[0]))
|
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* How loud the audio has to be to start displaying pitch */
|
|
|
|
/* Must be between 0 and 100 */
|
|
|
|
#define VOLUME_THRESHOLD (50)
|
2009-10-04 02:31:27 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Change to AUDIO_SRC_LINEIN if you want to record from line-in */
|
2009-10-04 02:31:27 +00:00
|
|
|
#ifdef HAVE_MIC_IN
|
2009-09-08 16:45:05 +00:00
|
|
|
#define INPUT_TYPE AUDIO_SRC_MIC
|
2009-10-04 02:31:27 +00:00
|
|
|
#else
|
|
|
|
#define INPUT_TYPE AUDIO_SRC_LINEIN
|
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
/* How many decimal places to display for the Hz value */
|
|
|
|
#define DISPLAY_HZ_PRECISION 100
|
|
|
|
|
2009-09-12 21:19:17 +00:00
|
|
|
/* Where to put the various GUI elements */
|
2010-08-28 17:52:31 +00:00
|
|
|
static int note_y;
|
|
|
|
static int bar_grad_y;
|
2009-09-12 21:19:17 +00:00
|
|
|
#define LCD_RES_MIN (LCD_HEIGHT < LCD_WIDTH ? LCD_HEIGHT : LCD_WIDTH)
|
|
|
|
#define BAR_PADDING (LCD_RES_MIN / 32)
|
|
|
|
#define BAR_Y (LCD_HEIGHT * 3 / 4)
|
|
|
|
#define BAR_HEIGHT (LCD_RES_MIN / 4 - BAR_PADDING)
|
|
|
|
#define BAR_HLINE_Y (BAR_Y - BAR_PADDING)
|
|
|
|
#define BAR_HLINE_Y2 (BAR_Y + BAR_HEIGHT + BAR_PADDING - 1)
|
|
|
|
#define HZ_Y 0
|
|
|
|
#define GRADUATION 10 /* Subdivisions of the whole 100-cent scale */
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
/* Bitmaps for drawing the note names. These need to have height
|
2009-09-12 21:19:17 +00:00
|
|
|
<= (bar_grad_y - note_y), or 15/32 * LCD_HEIGHT
|
|
|
|
*/
|
|
|
|
#define NUM_NOTE_IMAGES 9
|
|
|
|
#define NOTE_INDEX_A 0
|
|
|
|
#define NOTE_INDEX_B 1
|
|
|
|
#define NOTE_INDEX_C 2
|
|
|
|
#define NOTE_INDEX_D 3
|
|
|
|
#define NOTE_INDEX_E 4
|
|
|
|
#define NOTE_INDEX_F 5
|
|
|
|
#define NOTE_INDEX_G 6
|
|
|
|
#define NOTE_INDEX_SHARP 7
|
|
|
|
#define NOTE_INDEX_FLAT 8
|
2010-08-28 17:52:31 +00:00
|
|
|
|
|
|
|
static const struct picture note_bitmaps =
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
|
|
|
pitch_notes,
|
|
|
|
BMPWIDTH_pitch_notes,
|
|
|
|
BMPHEIGHT_pitch_notes,
|
|
|
|
BMPHEIGHT_pitch_notes/NUM_NOTE_IMAGES
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-14 06:25:40 +00:00
|
|
|
static unsigned int sample_rate;
|
|
|
|
static int audio_head = 0; /* which of the two buffers to use? */
|
|
|
|
static volatile int audio_tail = 0; /* which of the two buffers to record? */
|
2009-09-08 16:45:05 +00:00
|
|
|
/* It's stereo, so make the buffer twice as big */
|
2010-05-14 06:41:40 +00:00
|
|
|
#ifndef SIMULATOR
|
2010-05-14 08:44:07 +00:00
|
|
|
static int16_t audio_data[2][BUFFER_SIZE] __attribute__((aligned(CACHEALIGN_SIZE)));
|
2010-05-14 12:35:05 +00:00
|
|
|
static fixed yin_buffer[YIN_BUFFER_SIZE] IBSS_ATTR;
|
|
|
|
#ifdef PLUGIN_USE_IRAM
|
|
|
|
static int16_t iram_audio_data[BUFFER_SIZE] IBSS_ATTR;
|
|
|
|
#else
|
|
|
|
#define iram_audio_data audio_data[audio_head]
|
|
|
|
#endif
|
2010-05-14 06:41:40 +00:00
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
/* Notes within one (reference) scale */
|
|
|
|
static const struct
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2009-09-20 17:03:30 +00:00
|
|
|
const char *name; /* Name of the note, e.g. "A#" */
|
2009-09-20 17:10:16 +00:00
|
|
|
const fixed freq; /* Note frequency, Hz */
|
2009-09-20 17:03:30 +00:00
|
|
|
const fixed logfreq; /* log2(frequency) */
|
2010-08-28 17:52:31 +00:00
|
|
|
} notes[] =
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2010-09-14 06:34:01 +00:00
|
|
|
{"A" , float2fixed(440.0000000f), float2fixed(8.781359714f)},
|
|
|
|
{"A#", float2fixed(466.1637615f), float2fixed(8.864693047f)},
|
|
|
|
{"B" , float2fixed(493.8833013f), float2fixed(8.948026380f)},
|
|
|
|
{"C" , float2fixed(523.2511306f), float2fixed(9.031359714f)},
|
|
|
|
{"C#", float2fixed(554.3652620f), float2fixed(9.114693047f)},
|
|
|
|
{"D" , float2fixed(587.3295358f), float2fixed(9.198026380f)},
|
|
|
|
{"D#", float2fixed(622.2539674f), float2fixed(9.281359714f)},
|
|
|
|
{"E" , float2fixed(659.2551138f), float2fixed(9.364693047f)},
|
|
|
|
{"F" , float2fixed(698.4564629f), float2fixed(9.448026380f)},
|
|
|
|
{"F#", float2fixed(739.9888454f), float2fixed(9.531359714f)},
|
|
|
|
{"G" , float2fixed(783.9908720f), float2fixed(9.614693047f)},
|
|
|
|
{"G#", float2fixed(830.6093952f), float2fixed(9.698026380f)},
|
2009-09-08 16:45:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* GUI */
|
2010-03-29 23:50:07 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
static unsigned front_color;
|
|
|
|
#endif
|
2009-09-12 21:19:17 +00:00
|
|
|
static int font_w,font_h;
|
|
|
|
static int bar_x_0;
|
|
|
|
static int lbl_x_minus_50, lbl_x_minus_20, lbl_x_0, lbl_x_20, lbl_x_50;
|
|
|
|
|
2009-09-20 17:03:30 +00:00
|
|
|
/* Settings for the plugin */
|
2010-08-28 17:52:31 +00:00
|
|
|
static struct tuner_settings
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
unsigned volume_threshold;
|
|
|
|
unsigned record_gain;
|
|
|
|
unsigned sample_size;
|
|
|
|
unsigned lowest_freq;
|
|
|
|
unsigned yin_threshold;
|
2009-09-20 16:16:32 +00:00
|
|
|
int freq_A; /* Index of the frequency of A */
|
|
|
|
bool use_sharps;
|
|
|
|
bool display_hz;
|
2010-08-28 17:52:31 +00:00
|
|
|
} settings;
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2009-09-12 21:19:17 +00:00
|
|
|
/*=================================================================*/
|
|
|
|
/* Settings loading and saving(adapted from the clock plugin) */
|
|
|
|
/*=================================================================*/
|
|
|
|
|
|
|
|
#define SETTINGS_FILENAME PLUGIN_APPS_DIR "/.pitch_settings"
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
/* The settings as they exist on the hard disk, so that
|
2009-09-12 21:19:17 +00:00
|
|
|
* we can know at saving time if changes have been made */
|
2010-08-28 17:52:31 +00:00
|
|
|
static struct tuner_settings hdd_settings;
|
2009-09-12 21:19:17 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static bool settings_needs_saving(void)
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
return(rb->memcmp(&settings, &hdd_settings, sizeof(settings)));
|
2009-09-12 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static void tuner_settings_reset(void)
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
settings = (struct tuner_settings) {
|
|
|
|
.volume_threshold = VOLUME_THRESHOLD,
|
|
|
|
.record_gain = rb->global_settings->rec_mic_gain,
|
|
|
|
.sample_size = BUFFER_SIZE,
|
|
|
|
.lowest_freq = period2freq(BUFFER_SIZE / 4),
|
|
|
|
.yin_threshold = DEFAULT_YIN_THRESHOLD,
|
|
|
|
.freq_A = DEFAULT_FREQ_A,
|
|
|
|
.use_sharps = true,
|
|
|
|
.display_hz = false,
|
|
|
|
};
|
2009-09-12 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static void load_settings(void)
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
int fd = rb->open(SETTINGS_FILENAME, O_RDONLY);
|
|
|
|
if(fd < 0){ /* file doesn't exist */
|
|
|
|
/* Initializes the settings with default values at least */
|
|
|
|
tuner_settings_reset();
|
|
|
|
return;
|
2009-09-12 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
/* basic consistency check */
|
|
|
|
if(rb->filesize(fd) == sizeof(settings)){
|
|
|
|
rb->read(fd, &settings, sizeof(settings));
|
|
|
|
rb->memcpy(&hdd_settings, &settings, sizeof(settings));
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
tuner_settings_reset();
|
2009-09-12 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
rb->close(fd);
|
2009-09-12 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static void save_settings(void)
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
if(!settings_needs_saving())
|
2009-09-12 21:19:17 +00:00
|
|
|
return;
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
int fd = rb->creat(SETTINGS_FILENAME, 0666);
|
|
|
|
if(fd >= 0){ /* does file exist? */
|
|
|
|
rb->write (fd, &settings, sizeof(settings));
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
2009-09-12 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/*=================================================================*/
|
|
|
|
/* MENU */
|
|
|
|
/*=================================================================*/
|
|
|
|
|
|
|
|
/* Keymaps */
|
|
|
|
const struct button_mapping* plugin_contexts[]={
|
2010-05-20 17:41:28 +00:00
|
|
|
pla_main_ctx,
|
2009-09-08 16:45:05 +00:00
|
|
|
#if NB_SCREENS == 2
|
2010-05-20 17:41:28 +00:00
|
|
|
pla_remote_ctx,
|
2009-09-08 16:45:05 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
|
|
|
|
|
|
|
|
/* Option strings */
|
2009-09-12 21:19:17 +00:00
|
|
|
|
|
|
|
/* This has to match yin_threshold_table */
|
2010-08-28 17:52:31 +00:00
|
|
|
static const struct opt_items yin_threshold_text[] =
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
{ "0.01", -1 },
|
|
|
|
{ "0.02", -1 },
|
|
|
|
{ "0.03", -1 },
|
|
|
|
{ "0.04", -1 },
|
|
|
|
{ "0.05", -1 },
|
|
|
|
{ "0.10", -1 },
|
|
|
|
{ "0.15", -1 },
|
|
|
|
{ "0.20", -1 },
|
|
|
|
{ "0.25", -1 },
|
|
|
|
{ "0.30", -1 },
|
|
|
|
{ "0.35", -1 },
|
|
|
|
{ "0.40", -1 },
|
|
|
|
{ "0.45", -1 },
|
|
|
|
{ "0.50", -1 },
|
|
|
|
};
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static const struct opt_items accidental_text[] =
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
|
|
|
{ "Flat", -1 },
|
|
|
|
{ "Sharp", -1 },
|
|
|
|
};
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static void set_min_freq(int new_freq)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
settings.sample_size = freq2period(new_freq) * 4;
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
/* clamp the sample size between min and max */
|
2010-08-28 17:52:31 +00:00
|
|
|
if(settings.sample_size <= SAMPLE_SIZE_MIN)
|
|
|
|
settings.sample_size = SAMPLE_SIZE_MIN;
|
|
|
|
else if(settings.sample_size >= BUFFER_SIZE)
|
|
|
|
settings.sample_size = BUFFER_SIZE;
|
2010-05-14 06:25:40 +00:00
|
|
|
|
|
|
|
/* sample size must be divisible by 4 - round up */
|
2010-08-28 17:52:31 +00:00
|
|
|
settings.sample_size = (settings.sample_size + 3) & ~3;
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static bool main_menu(void)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2009-09-20 16:16:32 +00:00
|
|
|
int selection = 0;
|
2009-09-08 16:45:05 +00:00
|
|
|
bool done = false;
|
2009-09-20 16:16:32 +00:00
|
|
|
bool exit_tuner = false;
|
2009-09-08 16:45:05 +00:00
|
|
|
int choice;
|
2009-09-20 16:16:32 +00:00
|
|
|
int freq_val;
|
|
|
|
bool reset;
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2010-05-14 06:25:40 +00:00
|
|
|
backlight_use_settings();
|
|
|
|
#ifdef HAVE_SCHEDULER_BOOSTCTRL
|
|
|
|
rb->cancel_cpu_boost();
|
|
|
|
#endif
|
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
MENUITEM_STRINGLIST(menu,"Tuner Settings",NULL,
|
|
|
|
"Return to Tuner",
|
|
|
|
"Volume Threshold",
|
|
|
|
"Listening Volume",
|
|
|
|
"Lowest Frequency",
|
|
|
|
"Algorithm Pickiness",
|
2009-09-12 21:19:17 +00:00
|
|
|
"Accidentals",
|
|
|
|
"Display Frequency (Hz)",
|
2009-09-20 16:16:32 +00:00
|
|
|
"Frequency of A (Hz)",
|
2009-09-12 21:19:17 +00:00
|
|
|
"Reset Settings",
|
2009-09-08 16:45:05 +00:00
|
|
|
"Quit");
|
|
|
|
|
|
|
|
while(!done)
|
|
|
|
{
|
|
|
|
choice = rb->do_menu(&menu, &selection, NULL, false);
|
|
|
|
switch(choice)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
rb->set_int("Volume Threshold", "%", UNIT_INT,
|
2010-08-28 17:52:31 +00:00
|
|
|
&settings.volume_threshold,
|
2009-09-08 16:45:05 +00:00
|
|
|
NULL, 5, 5, 95, NULL);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rb->set_int("Listening Volume", "%", UNIT_INT,
|
2010-08-28 17:52:31 +00:00
|
|
|
&settings.record_gain,
|
|
|
|
NULL, 1, rb->sound_min(SOUND_MIC_GAIN),
|
2009-09-08 16:45:05 +00:00
|
|
|
rb->sound_max(SOUND_MIC_GAIN), NULL);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rb->set_int("Lowest Frequency", "Hz", UNIT_INT,
|
2010-08-28 17:52:31 +00:00
|
|
|
&settings.lowest_freq, set_min_freq, 1,
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Range depends on the size of the buffer */
|
2010-08-28 17:52:31 +00:00
|
|
|
sample_rate / (BUFFER_SIZE / 4),
|
2010-05-14 06:25:40 +00:00
|
|
|
sample_rate / (SAMPLE_SIZE_MIN / 4), NULL);
|
2009-09-08 16:45:05 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
rb->set_option(
|
|
|
|
"Algorithm Pickiness (Lower -> more discriminating)",
|
2010-08-28 17:52:31 +00:00
|
|
|
&settings.yin_threshold,
|
2009-09-20 16:33:24 +00:00
|
|
|
INT, yin_threshold_text,
|
|
|
|
sizeof(yin_threshold_text) / sizeof(yin_threshold_text[0]),
|
2009-09-08 16:45:05 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case 5:
|
2009-09-12 21:19:17 +00:00
|
|
|
rb->set_option("Display Accidentals As",
|
2010-08-28 17:52:31 +00:00
|
|
|
&settings.use_sharps,
|
2009-09-12 21:19:17 +00:00
|
|
|
BOOL, accidental_text, 2, NULL);
|
2009-09-08 16:45:05 +00:00
|
|
|
break;
|
2009-09-12 21:19:17 +00:00
|
|
|
case 6:
|
2009-09-20 16:33:24 +00:00
|
|
|
rb->set_bool("Display Frequency (Hz)",
|
2010-08-28 17:52:31 +00:00
|
|
|
&settings.display_hz);
|
2009-09-12 21:19:17 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2010-08-28 17:52:31 +00:00
|
|
|
freq_val = freq_A[settings.freq_A].frequency;
|
2009-09-20 16:16:32 +00:00
|
|
|
rb->set_int("Frequency of A (Hz)",
|
|
|
|
"Hz", UNIT_INT, &freq_val, NULL,
|
|
|
|
1, freq_A[0].frequency, freq_A[NUM_FREQ_A-1].frequency,
|
|
|
|
NULL);
|
2010-08-28 17:52:31 +00:00
|
|
|
settings.freq_A = freq_val - freq_A[0].frequency;
|
2009-09-20 16:16:32 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
reset = false;
|
2009-09-20 16:33:24 +00:00
|
|
|
rb->set_bool("Reset Tuner Settings?", &reset);
|
|
|
|
if (reset)
|
2010-08-28 17:52:31 +00:00
|
|
|
tuner_settings_reset();
|
2009-09-12 21:19:17 +00:00
|
|
|
break;
|
2009-09-20 16:16:32 +00:00
|
|
|
case 9:
|
2009-09-12 21:19:17 +00:00
|
|
|
exit_tuner = true;
|
2009-09-20 16:16:32 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
2010-08-28 17:52:31 +00:00
|
|
|
case 0:
|
2009-09-12 21:19:17 +00:00
|
|
|
default:
|
|
|
|
/* Return to the tuner */
|
2009-09-08 16:45:05 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-14 06:25:40 +00:00
|
|
|
|
|
|
|
backlight_force_on();
|
2009-09-20 16:16:32 +00:00
|
|
|
return exit_tuner;
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*=================================================================*/
|
|
|
|
/* Binary Log */
|
|
|
|
/*=================================================================*/
|
|
|
|
|
|
|
|
/* Fixed-point log base 2*/
|
2010-08-28 17:52:31 +00:00
|
|
|
/* Adapted from python code at
|
2009-09-08 16:45:05 +00:00
|
|
|
http://en.wikipedia.org/wiki/Binary_logarithm#Algorithm
|
|
|
|
*/
|
2010-08-28 17:52:31 +00:00
|
|
|
static fixed log(fixed inp)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
fixed x = inp;
|
|
|
|
fixed fp = int2fixed(1);
|
|
|
|
fixed res = int2fixed(0);
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
if(fp_lte(x, FP_ZERO))
|
|
|
|
{
|
|
|
|
return FP_MIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Integer part*/
|
|
|
|
/* while x<1 */
|
|
|
|
while(fp_lt(x, int2fixed(1)))
|
|
|
|
{
|
|
|
|
res = fp_sub(res, int2fixed(1));
|
|
|
|
x = fp_shl(x, 1);
|
|
|
|
}
|
|
|
|
/* while x>=2 */
|
|
|
|
while(fp_gte(x, int2fixed(2)))
|
|
|
|
{
|
|
|
|
res = fp_add(res, int2fixed(1));
|
|
|
|
x = fp_shr(x, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fractional part */
|
|
|
|
/* while fp > 0 */
|
|
|
|
while(fp_gt(fp, FP_ZERO))
|
|
|
|
{
|
|
|
|
fp = fp_shr(fp, 1);
|
|
|
|
x = fp_mul(x, x);
|
|
|
|
/* if x >= 2 */
|
|
|
|
if(fp_gte(x, int2fixed(2)))
|
|
|
|
{
|
|
|
|
x = fp_shr(x, 1);
|
|
|
|
res = fp_add(res, fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=================================================================*/
|
|
|
|
/* GUI Stuff */
|
|
|
|
/*=================================================================*/
|
|
|
|
|
2009-09-12 21:19:17 +00:00
|
|
|
/* Draw the note bitmap */
|
2010-08-28 17:52:31 +00:00
|
|
|
static void draw_note(const char *note)
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int note_x = (LCD_WIDTH - BMPWIDTH_pitch_notes) / 2;
|
|
|
|
int accidental_index = NOTE_INDEX_SHARP;
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-12 21:19:17 +00:00
|
|
|
i = note[0]-'A';
|
|
|
|
|
|
|
|
if(note[1] == '#')
|
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
if(!(settings.use_sharps))
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
|
|
|
i = (i + 1) % 7;
|
|
|
|
accidental_index = NOTE_INDEX_FLAT;
|
|
|
|
}
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
vertical_picture_draw_sprite(rb->screens[0],
|
|
|
|
¬e_bitmaps,
|
2009-09-12 21:19:17 +00:00
|
|
|
accidental_index,
|
|
|
|
LCD_WIDTH / 2,
|
|
|
|
note_y);
|
|
|
|
note_x = LCD_WIDTH / 2 - BMPWIDTH_pitch_notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
vertical_picture_draw_sprite(rb->screens[0], ¬e_bitmaps, i,
|
|
|
|
note_x,
|
|
|
|
note_y);
|
|
|
|
}
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Draw the red bar and the white lines */
|
2010-08-28 17:52:31 +00:00
|
|
|
static void draw_bar(fixed wrong_by_cents)
|
|
|
|
{
|
2009-09-12 21:19:17 +00:00
|
|
|
unsigned n;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-09-20 16:16:32 +00:00
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(255,255,255)); /* Color screens */
|
2009-09-12 21:19:17 +00:00
|
|
|
#elif LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK); /* Greyscale screens */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rb->lcd_hline(0,LCD_WIDTH-1, BAR_HLINE_Y);
|
|
|
|
rb->lcd_hline(0,LCD_WIDTH-1, BAR_HLINE_Y2);
|
|
|
|
|
|
|
|
/* Draw graduation lines on the off-by readout */
|
|
|
|
for(n = 0; n <= GRADUATION; n++)
|
|
|
|
{
|
|
|
|
x = (LCD_WIDTH * n + GRADUATION / 2) / GRADUATION;
|
|
|
|
if (x >= LCD_WIDTH)
|
|
|
|
x = LCD_WIDTH - 1;
|
|
|
|
rb->lcd_vline(x, BAR_HLINE_Y, BAR_HLINE_Y2);
|
|
|
|
}
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(front_color);
|
|
|
|
#endif
|
2010-08-28 21:46:22 +00:00
|
|
|
rb->lcd_putsxyf(lbl_x_minus_50 ,bar_grad_y, "%d", -50);
|
|
|
|
rb->lcd_putsxyf(lbl_x_minus_20 ,bar_grad_y, "%d", -20);
|
|
|
|
rb->lcd_putsxyf(lbl_x_0 ,bar_grad_y, "%d", 0);
|
|
|
|
rb->lcd_putsxyf(lbl_x_20 ,bar_grad_y, "%d", 20);
|
|
|
|
rb->lcd_putsxyf(lbl_x_50 ,bar_grad_y, "%d", 50);
|
2009-09-12 21:19:17 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(255,0,0)); /* Color screens */
|
|
|
|
#elif LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(LCD_DARKGRAY); /* Greyscale screens */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fp_gt(wrong_by_cents, FP_ZERO))
|
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
rb->lcd_fillrect(bar_x_0, BAR_Y,
|
2009-09-12 21:19:17 +00:00
|
|
|
fixed2int(fp_mul(wrong_by_cents, LCD_FACTOR)), BAR_HEIGHT);
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_fillrect(bar_x_0 + fixed2int(fp_mul(wrong_by_cents,LCD_FACTOR)),
|
2009-09-12 21:19:17 +00:00
|
|
|
BAR_Y,
|
2010-08-28 17:52:31 +00:00
|
|
|
fixed2int(fp_mul(wrong_by_cents, LCD_FACTOR)) * -1,
|
2009-09-12 21:19:17 +00:00
|
|
|
BAR_HEIGHT);
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate how wrong the note is and draw the GUI */
|
2010-08-28 17:52:31 +00:00
|
|
|
static void display_frequency (fixed freq)
|
2009-12-05 01:00:47 +00:00
|
|
|
{
|
2009-09-08 16:45:05 +00:00
|
|
|
fixed ldf, mldf;
|
|
|
|
fixed lfreq, nfreq;
|
2009-09-20 16:16:32 +00:00
|
|
|
fixed orig_freq;
|
2009-09-08 16:45:05 +00:00
|
|
|
int i, note = 0;
|
|
|
|
|
|
|
|
if (fp_lt(freq, FP_LOW))
|
|
|
|
freq = FP_LOW;
|
2009-12-05 01:00:47 +00:00
|
|
|
|
2009-09-20 16:16:32 +00:00
|
|
|
/* We calculate the frequency and its log as if */
|
|
|
|
/* the reference frequency of A were 440 Hz. */
|
|
|
|
orig_freq = freq;
|
2010-08-28 17:52:31 +00:00
|
|
|
lfreq = fp_add(log(freq), freq_A[settings.freq_A].logratio);
|
|
|
|
freq = fp_mul(freq, freq_A[settings.freq_A].ratio);
|
2009-09-20 16:16:32 +00:00
|
|
|
|
|
|
|
/* This calculates a log freq offset for note A */
|
|
|
|
/* Get the frequency to within the range of our reference table, */
|
|
|
|
/* i.e. into the right octave. */
|
2009-09-20 17:03:30 +00:00
|
|
|
while (fp_lt(lfreq, fp_sub(notes[0].logfreq, fp_shr(LOG_D_NOTE, 1))))
|
2009-09-08 16:45:05 +00:00
|
|
|
lfreq = fp_add(lfreq, LOG_2);
|
2009-12-05 01:00:47 +00:00
|
|
|
while (fp_gte(lfreq, fp_sub(fp_add(notes[0].logfreq, LOG_2),
|
2009-09-08 16:45:05 +00:00
|
|
|
fp_shr(LOG_D_NOTE, 1))))
|
|
|
|
lfreq = fp_sub(lfreq, LOG_2);
|
|
|
|
mldf = LOG_D_NOTE;
|
2009-12-05 01:00:47 +00:00
|
|
|
for (i=0; i<12; i++)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2009-12-05 01:00:47 +00:00
|
|
|
ldf = fp_gt(fp_sub(lfreq,notes[i].logfreq), FP_ZERO) ?
|
2009-09-20 17:03:30 +00:00
|
|
|
fp_sub(lfreq,notes[i].logfreq) : fp_neg(fp_sub(lfreq,notes[i].logfreq));
|
2009-12-05 01:00:47 +00:00
|
|
|
if (fp_lt(ldf, mldf))
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2009-09-20 16:16:32 +00:00
|
|
|
mldf = ldf;
|
|
|
|
note = i;
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-20 17:03:30 +00:00
|
|
|
nfreq = notes[note].freq;
|
2009-09-20 16:16:32 +00:00
|
|
|
while (fp_gt(fp_div(nfreq, freq), D_NOTE_SQRT))
|
2009-09-08 16:45:05 +00:00
|
|
|
nfreq = fp_shr(nfreq, 1);
|
2009-12-05 01:00:47 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
while (fp_gt(fp_div(freq, nfreq), D_NOTE_SQRT))
|
|
|
|
nfreq = fp_shl(nfreq, 1);
|
2009-12-05 01:00:47 +00:00
|
|
|
|
2009-09-20 16:16:32 +00:00
|
|
|
ldf = fp_mul(int2fixed(1200), log(fp_div(freq,nfreq)));
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
draw_bar(ldf); /* The red bar */
|
2009-09-12 21:19:17 +00:00
|
|
|
if(fp_round(freq) != 0)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2009-09-20 17:03:30 +00:00
|
|
|
draw_note(notes[note].name);
|
2010-08-28 17:52:31 +00:00
|
|
|
if(settings.display_hz)
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(front_color);
|
|
|
|
#endif
|
2010-08-28 21:46:22 +00:00
|
|
|
rb->lcd_putsxyf(0, HZ_Y, "%s : %d cents (%d.%02dHz)",
|
2009-09-20 17:03:30 +00:00
|
|
|
notes[note].name, fp_round(ldf) ,fixed2int(orig_freq),
|
2009-09-20 16:16:32 +00:00
|
|
|
fp_round(fp_mul(fp_frac(orig_freq),
|
2009-09-12 21:19:17 +00:00
|
|
|
int2fixed(DISPLAY_HZ_PRECISION))));
|
|
|
|
}
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
rb->lcd_update();
|
|
|
|
}
|
|
|
|
|
2010-08-28 19:15:07 +00:00
|
|
|
#ifndef SIMULATOR
|
2009-09-08 16:45:05 +00:00
|
|
|
/*-----------------------------------------------------------------------
|
2010-08-28 17:52:31 +00:00
|
|
|
* Functions for the Yin algorithm
|
|
|
|
*
|
|
|
|
* These were all adapted from the versions in Aubio v0.3.2
|
2009-09-08 16:45:05 +00:00
|
|
|
* Here's what the Aubio documentation has to say:
|
|
|
|
*
|
|
|
|
* This algorithm was developped by A. de Cheveigne and H. Kawahara and
|
|
|
|
* published in:
|
2010-08-28 17:52:31 +00:00
|
|
|
*
|
2009-09-08 16:45:05 +00:00
|
|
|
* de Cheveign?, A., Kawahara, H. (2002) "YIN, a fundamental frequency
|
2010-08-28 17:52:31 +00:00
|
|
|
* estimator for speech and music", J. Acoust. Soc. Am. 111, 1917-1930.
|
2009-09-08 16:45:05 +00:00
|
|
|
*
|
|
|
|
* see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html
|
|
|
|
-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* Find the index of the minimum element of an array of floats */
|
2010-08-28 17:52:31 +00:00
|
|
|
static unsigned vec_min_elem(fixed *s, unsigned buflen)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
unsigned j, pos=0.0f;
|
|
|
|
fixed tmp = s[0];
|
2010-08-28 17:52:31 +00:00
|
|
|
for (j=0; j < buflen; j++)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
if(fp_gt(tmp, s[j]))
|
|
|
|
{
|
|
|
|
pos = j;
|
|
|
|
tmp = s[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static inline fixed aubio_quadfrac(fixed s0, fixed s1, fixed s2, fixed pf)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
/* Original floating point version: */
|
2010-08-28 17:52:31 +00:00
|
|
|
/* tmp = s0 + (pf/2.0f) * (pf * ( s0 - 2.0f*s1 + s2 ) -
|
2009-09-08 16:45:05 +00:00
|
|
|
3.0f*s0 + 4.0f*s1 - s2);*/
|
|
|
|
/* Converted to explicit operator precedence: */
|
2010-08-28 17:52:31 +00:00
|
|
|
/* tmp = s0 + ((pf/2.0f) * ((((pf * ((s0 - (2*s1)) + s2)) -
|
2009-09-08 16:45:05 +00:00
|
|
|
(3*s0)) + (4*s1)) - s2)); */
|
|
|
|
|
|
|
|
/* I made it look like this so I could easily track the precedence and */
|
|
|
|
/* make sure it matched the original expression */
|
|
|
|
/* Oy, this is when I really wish I could do C++ operator overloading */
|
|
|
|
fixed tmp = fp_add
|
|
|
|
(
|
|
|
|
s0,
|
|
|
|
fp_mul
|
|
|
|
(
|
|
|
|
fp_shr(pf, 1),
|
|
|
|
fp_sub
|
|
|
|
(
|
|
|
|
fp_add
|
|
|
|
(
|
|
|
|
fp_sub
|
|
|
|
(
|
|
|
|
fp_mul
|
|
|
|
(
|
|
|
|
pf,
|
|
|
|
fp_add
|
|
|
|
(
|
|
|
|
fp_sub
|
|
|
|
(
|
|
|
|
s0,
|
|
|
|
fp_shl(s1, 1)
|
|
|
|
),
|
2010-08-28 17:52:31 +00:00
|
|
|
s2
|
2009-09-08 16:45:05 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
fp_mul
|
|
|
|
(
|
|
|
|
float2fixed(3.0f),
|
|
|
|
s0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
fp_shl(s1, 2)
|
|
|
|
),
|
|
|
|
s2
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define QUADINT_STEP float2fixed(1.0f/200.0f)
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static fixed ICODE_ATTR vec_quadint_min(fixed *x, unsigned bufsize, unsigned pos, unsigned span)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
fixed res, frac, s0, s1, s2;
|
|
|
|
fixed exactpos = int2fixed(pos);
|
|
|
|
/* init resold to something big (in case x[pos+-span]<0)) */
|
|
|
|
fixed resold = FP_MAX;
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
if ((pos > span) && (pos < bufsize-span))
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
s0 = x[pos-span];
|
|
|
|
s1 = x[pos] ;
|
|
|
|
s2 = x[pos+span];
|
|
|
|
/* increase frac */
|
2010-08-28 17:52:31 +00:00
|
|
|
for (frac = float2fixed(0.0f);
|
|
|
|
fp_lt(frac, float2fixed(2.0f));
|
|
|
|
frac = fp_add(frac, QUADINT_STEP))
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
res = aubio_quadfrac(s0, s1, s2, frac);
|
2010-08-28 17:52:31 +00:00
|
|
|
if (fp_lt(res, resold))
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
resold = res;
|
2010-08-28 17:52:31 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-12 21:19:17 +00:00
|
|
|
{
|
2009-09-08 16:45:05 +00:00
|
|
|
/* exactpos += (frac-QUADINT_STEP)*span - span/2.0f; */
|
2010-08-28 17:52:31 +00:00
|
|
|
exactpos = fp_add(exactpos,
|
2009-09-08 16:45:05 +00:00
|
|
|
fp_sub(
|
|
|
|
fp_mul(
|
|
|
|
fp_sub(frac, QUADINT_STEP),
|
|
|
|
int2fixed(span)
|
|
|
|
),
|
|
|
|
int2fixed(span)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exactpos;
|
|
|
|
}
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
/* Calculate the period of the note in the
|
2009-09-08 16:45:05 +00:00
|
|
|
buffer using the YIN algorithm */
|
|
|
|
/* The yin pointer is just a buffer that the algorithm uses as a work
|
|
|
|
space. It needs to be half the length of the input buffer. */
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static fixed ICODE_ATTR pitchyin(int16_t *input, fixed *yin)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
fixed retval;
|
|
|
|
unsigned j,tau = 0;
|
|
|
|
int period;
|
2010-08-28 17:52:31 +00:00
|
|
|
unsigned yin_size = settings.sample_size / 4;
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
fixed tmp = FP_ZERO, tmp2 = FP_ZERO;
|
|
|
|
yin[0] = int2fixed(1);
|
|
|
|
for (tau = 1; tau < yin_size; tau++)
|
|
|
|
{
|
|
|
|
yin[tau] = FP_ZERO;
|
|
|
|
for (j = 0; j < yin_size; j++)
|
|
|
|
{
|
2010-08-28 17:52:31 +00:00
|
|
|
tmp = fp_sub(int2mantissa(input[2 * j]),
|
2009-09-08 16:45:05 +00:00
|
|
|
int2mantissa(input[2 * (j + tau)]));
|
|
|
|
yin[tau] = fp_add(yin[tau], fp_mul(tmp, tmp));
|
|
|
|
}
|
|
|
|
tmp2 = fp_add(tmp2, yin[tau]);
|
|
|
|
if(!fp_equal(tmp2, FP_ZERO))
|
|
|
|
{
|
|
|
|
yin[tau] = fp_mul(yin[tau], fp_div(int2fixed(tau), tmp2));
|
|
|
|
}
|
|
|
|
period = tau - 3;
|
2010-08-28 17:52:31 +00:00
|
|
|
if(tau > 4 && fp_lt(yin[period],
|
|
|
|
yin_threshold_table[settings.yin_threshold])
|
2009-09-08 16:45:05 +00:00
|
|
|
&& fp_lt(yin[period], yin[period+1]))
|
|
|
|
{
|
|
|
|
retval = vec_quadint_min(yin, yin_size, period, 1);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 17:52:31 +00:00
|
|
|
retval = vec_quadint_min(yin, yin_size,
|
2009-09-08 16:45:05 +00:00
|
|
|
vec_min_elem(yin, yin_size), 1);
|
|
|
|
return retval;
|
|
|
|
/*return FP_ZERO;*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------*/
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
static uint32_t ICODE_ATTR buffer_magnitude(int16_t *input)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
unsigned n;
|
|
|
|
uint64_t tally = 0;
|
2010-08-28 17:52:31 +00:00
|
|
|
const unsigned size = settings.sample_size;
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
/* Operate on only one channel of the stereo signal */
|
2010-05-14 12:35:05 +00:00
|
|
|
for(n = 0; n < size; n+=2)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2010-05-14 06:25:40 +00:00
|
|
|
int s = input[n];
|
|
|
|
tally += s * s;
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:35:05 +00:00
|
|
|
tally /= size / 2;
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
/* now tally holds the average of the squares of all the samples */
|
|
|
|
/* It must be between 0 and 0x7fff^2, so it fits in 32 bits */
|
|
|
|
return (uint32_t)tally;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop the recording when the buffer is full */
|
2010-08-28 17:52:31 +00:00
|
|
|
static void recording_callback(int status, void **start, size_t *size)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2010-05-14 06:25:40 +00:00
|
|
|
int tail = audio_tail ^ 1;
|
|
|
|
|
|
|
|
/* Do not overrun the reader. Reuse current buffer if full. */
|
|
|
|
if (tail != audio_head)
|
|
|
|
audio_tail = tail;
|
|
|
|
|
|
|
|
/* Always record full buffer, even if not required */
|
2010-05-24 16:42:32 +00:00
|
|
|
*start = audio_data[tail];
|
|
|
|
*size = BUFFER_SIZE * sizeof (int16_t);
|
2010-05-14 06:25:40 +00:00
|
|
|
|
|
|
|
(void)status;
|
|
|
|
}
|
2010-08-28 19:07:38 +00:00
|
|
|
#endif /* SIMULATOR */
|
2010-05-14 06:25:40 +00:00
|
|
|
|
|
|
|
/* Start recording */
|
|
|
|
static void record_data(void)
|
|
|
|
{
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
/* Always record full buffer, even if not required */
|
2010-08-28 17:52:31 +00:00
|
|
|
rb->pcm_record_data(recording_callback, audio_data[audio_tail],
|
2010-05-14 06:25:40 +00:00
|
|
|
BUFFER_SIZE * sizeof (int16_t));
|
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The main program loop */
|
2010-08-28 17:52:31 +00:00
|
|
|
static void record_and_get_pitch(void)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
int quit=0, button;
|
|
|
|
bool redraw = true;
|
|
|
|
/* For tracking the latency */
|
|
|
|
/*
|
|
|
|
long timer;
|
|
|
|
char debug_string[20];
|
|
|
|
*/
|
2009-09-12 21:19:17 +00:00
|
|
|
#ifndef SIMULATOR
|
2009-09-08 16:45:05 +00:00
|
|
|
fixed period;
|
|
|
|
bool waiting = false;
|
2010-05-14 06:41:40 +00:00
|
|
|
#else
|
|
|
|
audio_tail = 1;
|
2009-09-12 21:19:17 +00:00
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2010-05-14 06:25:40 +00:00
|
|
|
backlight_force_on();
|
|
|
|
|
|
|
|
record_data();
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
while(!quit)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2010-05-14 06:25:40 +00:00
|
|
|
while (audio_head == audio_tail && !quit) /* wait for the buffer to be filled */
|
2010-08-28 17:52:31 +00:00
|
|
|
{
|
2010-05-14 06:25:40 +00:00
|
|
|
button=pluginlib_getaction(HZ/100, plugin_contexts, PLA_ARRAY_COUNT);
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
switch(button)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
2010-05-20 17:41:28 +00:00
|
|
|
case PLA_EXIT:
|
2009-09-08 16:45:05 +00:00
|
|
|
quit=true;
|
|
|
|
break;
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2010-05-20 17:41:28 +00:00
|
|
|
case PLA_CANCEL:
|
2010-05-14 06:25:40 +00:00
|
|
|
rb->pcm_stop_recording();
|
|
|
|
quit = main_menu() != 0;
|
|
|
|
if(!quit)
|
|
|
|
{
|
|
|
|
redraw = true;
|
|
|
|
record_data();
|
|
|
|
}
|
2009-09-08 16:45:05 +00:00
|
|
|
break;
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-08-28 17:52:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
if(!quit)
|
|
|
|
{
|
2009-09-12 21:19:17 +00:00
|
|
|
#ifndef SIMULATOR
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Only do the heavy lifting if the volume is high enough */
|
2010-08-28 17:52:31 +00:00
|
|
|
if(buffer_magnitude(audio_data[audio_head]) >
|
|
|
|
sqr(settings.volume_threshold *
|
2009-09-08 16:45:05 +00:00
|
|
|
rb->sound_max(SOUND_MIC_GAIN)))
|
|
|
|
{
|
2010-05-14 06:25:40 +00:00
|
|
|
waiting = false;
|
2009-09-08 16:45:05 +00:00
|
|
|
redraw = false;
|
|
|
|
|
2010-05-14 06:25:40 +00:00
|
|
|
#ifdef HAVE_SCHEDULER_BOOSTCTRL
|
|
|
|
rb->trigger_cpu_boost();
|
|
|
|
#endif
|
2010-05-14 12:35:05 +00:00
|
|
|
#ifdef PLUGIN_USE_IRAM
|
|
|
|
rb->memcpy(iram_audio_data, audio_data[audio_head],
|
2010-08-28 17:52:31 +00:00
|
|
|
settings.sample_size * sizeof (int16_t));
|
2010-05-14 12:35:05 +00:00
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
/* This returns the period of the detected pitch in samples */
|
2010-05-14 12:35:05 +00:00
|
|
|
period = pitchyin(iram_audio_data, yin_buffer);
|
2009-09-08 16:45:05 +00:00
|
|
|
/* Hz = sample rate / period */
|
|
|
|
if(fp_gt(period, FP_ZERO))
|
|
|
|
{
|
|
|
|
display_frequency(fp_period2freq(period));
|
|
|
|
}
|
2010-08-28 17:52:31 +00:00
|
|
|
else
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
display_frequency(FP_ZERO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(redraw || !waiting)
|
|
|
|
{
|
|
|
|
waiting = true;
|
|
|
|
redraw = false;
|
|
|
|
display_frequency(FP_ZERO);
|
2010-05-14 06:25:40 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cancel_cpu_boost();
|
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
2010-05-14 06:41:40 +00:00
|
|
|
|
2010-05-14 06:25:40 +00:00
|
|
|
/* Move to next buffer if not empty (but empty *shouldn't* happen
|
|
|
|
* here). */
|
|
|
|
if (audio_head != audio_tail)
|
|
|
|
audio_head ^= 1;
|
2010-05-14 06:41:40 +00:00
|
|
|
#else /* SIMULATOR */
|
|
|
|
/* Display a preselected frequency */
|
|
|
|
display_frequency(int2fixed(445));
|
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->pcm_close_recording();
|
2010-06-26 10:07:17 +00:00
|
|
|
rb->pcm_set_frequency(REC_SAMPR_DEFAULT | SAMPR_TYPE_REC);
|
2010-05-14 06:25:40 +00:00
|
|
|
#ifdef HAVE_SCHEDULER_BOOSTCTRL
|
|
|
|
rb->cancel_cpu_boost();
|
2009-09-08 16:45:05 +00:00
|
|
|
#endif
|
2010-05-14 06:25:40 +00:00
|
|
|
|
|
|
|
backlight_use_settings();
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init recording, tuning, and GUI */
|
2010-08-28 17:52:31 +00:00
|
|
|
static void init_everything(void)
|
2010-05-14 12:35:05 +00:00
|
|
|
{
|
|
|
|
/* Disable all talking before initializing IRAM */
|
|
|
|
rb->talk_disable(true);
|
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
load_settings();
|
2010-08-28 17:52:31 +00:00
|
|
|
rb->storage_sleep();
|
2009-09-08 16:45:05 +00:00
|
|
|
|
2010-08-30 20:47:53 +00:00
|
|
|
/* Stop all playback */
|
2010-05-14 06:25:40 +00:00
|
|
|
rb->plugin_get_audio_buffer(NULL);
|
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* --------- Init the audio recording ----------------- */
|
2010-08-28 17:52:31 +00:00
|
|
|
rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
|
|
|
|
rb->audio_set_input_source(INPUT_TYPE, SRCF_RECORDING);
|
2009-09-08 16:45:05 +00:00
|
|
|
|
|
|
|
/* set to maximum gain */
|
2010-08-28 17:52:31 +00:00
|
|
|
rb->audio_set_recording_gain(settings.record_gain,
|
|
|
|
settings.record_gain,
|
2009-09-08 16:45:05 +00:00
|
|
|
AUDIO_GAIN_MIC);
|
|
|
|
|
2010-05-14 06:25:40 +00:00
|
|
|
/* Highest C on piano is approx 4.186 kHz, so we need just over
|
|
|
|
* 8.372 kHz to pass it. */
|
|
|
|
sample_rate = rb->round_value_to_list32(9000, rb->rec_freq_sampr,
|
|
|
|
REC_NUM_FREQ, false);
|
|
|
|
sample_rate = rb->rec_freq_sampr[sample_rate];
|
2010-06-26 10:07:17 +00:00
|
|
|
rb->pcm_set_frequency(sample_rate | SAMPR_TYPE_REC);
|
2009-09-08 16:45:05 +00:00
|
|
|
rb->pcm_init_recording();
|
2010-08-28 17:52:27 +00:00
|
|
|
|
|
|
|
/* avoid divsion by zero */
|
2010-08-28 17:52:31 +00:00
|
|
|
if(settings.lowest_freq == 0)
|
|
|
|
settings.lowest_freq = period2freq(BUFFER_SIZE / 4);
|
2010-08-28 17:52:27 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
/* GUI */
|
2010-03-29 23:50:07 +00:00
|
|
|
#if LCD_DEPTH > 1
|
2009-09-08 16:45:05 +00:00
|
|
|
front_color = rb->lcd_get_foreground();
|
2010-03-29 23:50:07 +00:00
|
|
|
#endif
|
2009-09-08 16:45:05 +00:00
|
|
|
rb->lcd_getstringsize("X", &font_w, &font_h);
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-12 21:19:17 +00:00
|
|
|
bar_x_0 = LCD_WIDTH / 2;
|
|
|
|
lbl_x_minus_50 = 0;
|
|
|
|
lbl_x_minus_20 = (LCD_WIDTH / 2) -
|
2009-09-08 16:45:05 +00:00
|
|
|
fixed2int(fp_mul(LCD_FACTOR, int2fixed(20))) - font_w;
|
2009-09-12 21:19:17 +00:00
|
|
|
lbl_x_0 = (LCD_WIDTH - font_w) / 2;
|
|
|
|
lbl_x_20 = (LCD_WIDTH / 2) +
|
|
|
|
fixed2int(fp_mul(LCD_FACTOR, int2fixed(20))) - font_w;
|
|
|
|
lbl_x_50 = LCD_WIDTH - 2 * font_w;
|
|
|
|
|
|
|
|
bar_grad_y = BAR_Y - BAR_PADDING - font_h;
|
|
|
|
/* Put the note right between the top and bottom text elements */
|
|
|
|
note_y = ((font_h + bar_grad_y - note_bitmaps.slide_height) / 2);
|
2010-05-14 12:35:05 +00:00
|
|
|
|
|
|
|
rb->talk_disable(false);
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 15:01:59 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2009-09-08 16:45:05 +00:00
|
|
|
{
|
|
|
|
(void)parameter;
|
2010-08-28 17:52:31 +00:00
|
|
|
|
2009-09-08 16:45:05 +00:00
|
|
|
init_everything();
|
|
|
|
record_and_get_pitch();
|
|
|
|
save_settings();
|
|
|
|
|
2010-08-28 17:52:31 +00:00
|
|
|
return PLUGIN_OK;
|
2009-09-08 16:45:05 +00:00
|
|
|
}
|