|
|
|
|
|
|
|
|
#ifndef AudioTuner_h_ |
|
|
#ifndef AudioTuner_h_ |
|
|
#define AudioTuner_h_ |
|
|
#define AudioTuner_h_ |
|
|
|
|
|
|
|
|
|
|
|
#include <core_pins.h> |
|
|
#include "AudioStream.h" |
|
|
#include "AudioStream.h" |
|
|
#include "arm_math.h" |
|
|
#include "arm_math.h" |
|
|
/*********************************************************************** |
|
|
/*********************************************************************** |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return none |
|
|
* @return none |
|
|
*/ |
|
|
*/ |
|
|
AudioTuner( void ) : AudioStream( 1, inputQueueArray ), |
|
|
|
|
|
data( 0.0 ), |
|
|
|
|
|
coeff_p( NULL ), |
|
|
|
|
|
enabled( false ), |
|
|
|
|
|
new_output( false ), |
|
|
|
|
|
coeff_size( 0 ) |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* initialize variables and start |
|
|
|
|
|
* |
|
|
|
|
|
* @param threshold Allowed uncertainty |
|
|
|
|
|
* @param coeff coefficients for fir filter |
|
|
|
|
|
* @param taps number of coefficients, even |
|
|
|
|
|
* @param factor must be power of 2 |
|
|
|
|
|
*/ |
|
|
|
|
|
void begin( float threshold, int16_t *coeff, uint8_t taps, uint8_t factor ); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* sets threshold value |
|
|
|
|
|
* |
|
|
|
|
|
* @param thresh |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
void threshold( float p ); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* triggers true when valid frequency is found |
|
|
|
|
|
* |
|
|
|
|
|
* @return flag to indicate valid frequency is found |
|
|
|
|
|
*/ |
|
|
|
|
|
bool available( void ); |
|
|
|
|
|
/** |
|
|
|
|
|
* get frequency |
|
|
|
|
|
* |
|
|
|
|
|
* @return frequency in hertz |
|
|
|
|
|
*/ |
|
|
|
|
|
float read( void ); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* get predicitity |
|
|
|
|
|
* |
|
|
|
|
|
* @return probability of frequency found |
|
|
|
|
|
*/ |
|
|
|
|
|
float probability( void ); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* fir decimation coefficents |
|
|
|
|
|
* |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
void coeff( int16_t *p, int n ); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* disable yin |
|
|
|
|
|
* |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
void disable( void ); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Audio Library calls this update function ~2.9ms |
|
|
|
|
|
* |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
virtual void update( void ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AudioTuner(void) |
|
|
|
|
|
: AudioStream(1, inputQueueArray) |
|
|
|
|
|
, data(0.0) |
|
|
|
|
|
, coeff_p(NULL) |
|
|
|
|
|
, coeff_size(0) |
|
|
|
|
|
, new_output(false) |
|
|
|
|
|
, enabled(false) |
|
|
|
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* initialize variables and start |
|
|
|
|
|
* |
|
|
|
|
|
* @param threshold Allowed uncertainty |
|
|
|
|
|
* @param coeff coefficients for fir filter |
|
|
|
|
|
* @param taps number of coefficients, even |
|
|
|
|
|
* @param factor must be power of 2 |
|
|
|
|
|
*/ |
|
|
|
|
|
void begin(float threshold, int16_t *coeff, uint8_t taps, uint8_t factor); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* sets threshold value |
|
|
|
|
|
* |
|
|
|
|
|
* @param thresh |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
void threshold(float p); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* triggers true when valid frequency is found |
|
|
|
|
|
* |
|
|
|
|
|
* @return flag to indicate valid frequency is found |
|
|
|
|
|
*/ |
|
|
|
|
|
bool available(void); |
|
|
|
|
|
/** |
|
|
|
|
|
* get frequency |
|
|
|
|
|
* |
|
|
|
|
|
* @return frequency in hertz |
|
|
|
|
|
*/ |
|
|
|
|
|
float read(void); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* get predicitity |
|
|
|
|
|
* |
|
|
|
|
|
* @return probability of frequency found |
|
|
|
|
|
*/ |
|
|
|
|
|
float probability(void); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* fir decimation coefficents |
|
|
|
|
|
* |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
void coeff(int16_t *p, int n); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* disable yin |
|
|
|
|
|
* |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
void disable(void); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Audio Library calls this update function ~2.9ms |
|
|
|
|
|
* |
|
|
|
|
|
* @return none |
|
|
|
|
|
*/ |
|
|
|
|
|
virtual void update(void); |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
/** |
|
|
/** |
|
|
* check the sampled data for fundamental frequency |
|
|
* check the sampled data for fundamental frequency |
|
|
|
|
|
|
|
|
* @return tau |
|
|
* @return tau |
|
|
*/ |
|
|
*/ |
|
|
uint16_t estimate( uint64_t *yin, uint64_t *rs, uint16_t head, uint16_t tau ); |
|
|
uint16_t estimate( uint64_t *yin, uint64_t *rs, uint16_t head, uint16_t tau ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* process audio data |
|
|
* process audio data |
|
|
* |
|
|
* |
|
|
* @return none |
|
|
* @return none |
|
|
*/ |
|
|
*/ |
|
|
void process( int16_t *p ); |
|
|
void process( int16_t *p ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Variables |
|
|
* Variables |
|
|
*/ |
|
|
*/ |