|
|
|
|
|
|
|
|
#include "utility/dspinst.h" |
|
|
#include "utility/dspinst.h" |
|
|
#include "arm_math.h" |
|
|
#include "arm_math.h" |
|
|
|
|
|
|
|
|
#define HALF_BLOCKS AUDIO_BLOCKS * 64 |
|
|
|
|
|
|
|
|
#define HALF_BLOCKS AUDIO_GUITARTUNER_BLOCKS * 64 |
|
|
|
|
|
|
|
|
#define LOOP1(a) a |
|
|
#define LOOP1(a) a |
|
|
#define LOOP2(a) a LOOP1(a) |
|
|
#define LOOP2(a) a LOOP1(a) |
|
|
|
|
|
|
|
|
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) *dst++ = *src++; |
|
|
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) *dst++ = *src++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioTuner::update( void ) { |
|
|
|
|
|
|
|
|
void AudioAnalyzeGuitarTuner::update( void ) { |
|
|
|
|
|
|
|
|
audio_block_t *block; |
|
|
audio_block_t *block; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !first_run && process_buffer ) process( ); |
|
|
if ( !first_run && process_buffer ) process( ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( state >= AUDIO_BLOCKS ) { |
|
|
|
|
|
|
|
|
if ( state >= AUDIO_GUITARTUNER_BLOCKS ) { |
|
|
if ( next_buffer ) { |
|
|
if ( next_buffer ) { |
|
|
if ( !first_run && process_buffer ) process( ); |
|
|
if ( !first_run && process_buffer ) process( ); |
|
|
for ( int i = 0; i < AUDIO_BLOCKS; i++ ) copy_buffer( AudioBuffer+( i * 0x80 ), blocklist1[i]->data ); |
|
|
|
|
|
for ( int i = 0; i < AUDIO_BLOCKS; i++ ) release(blocklist1[i] ); |
|
|
|
|
|
|
|
|
for ( int i = 0; i < AUDIO_GUITARTUNER_BLOCKS; i++ ) copy_buffer( AudioBuffer+( i * 0x80 ), blocklist1[i]->data ); |
|
|
|
|
|
for ( int i = 0; i < AUDIO_GUITARTUNER_BLOCKS; i++ ) release(blocklist1[i] ); |
|
|
} else { |
|
|
} else { |
|
|
if ( !first_run && process_buffer ) process( ); |
|
|
if ( !first_run && process_buffer ) process( ); |
|
|
for ( int i = 0; i < AUDIO_BLOCKS; i++ ) copy_buffer( AudioBuffer+( i * 0x80 ), blocklist2[i]->data ); |
|
|
|
|
|
for ( int i = 0; i < AUDIO_BLOCKS; i++ ) release( blocklist2[i] ); |
|
|
|
|
|
|
|
|
for ( int i = 0; i < AUDIO_GUITARTUNER_BLOCKS; i++ ) copy_buffer( AudioBuffer+( i * 0x80 ), blocklist2[i]->data ); |
|
|
|
|
|
for ( int i = 0; i < AUDIO_GUITARTUNER_BLOCKS; i++ ) release( blocklist2[i] ); |
|
|
} |
|
|
} |
|
|
process_buffer = true; |
|
|
process_buffer = true; |
|
|
first_run = false; |
|
|
first_run = false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
FASTRUN void AudioTuner::process( void ) { |
|
|
|
|
|
|
|
|
FASTRUN void AudioAnalyzeGuitarTuner::process( void ) { |
|
|
//digitalWriteFast(0, HIGH); |
|
|
//digitalWriteFast(0, HIGH); |
|
|
|
|
|
|
|
|
const int16_t *p; |
|
|
const int16_t *p; |
|
|
p = AudioBuffer; |
|
|
p = AudioBuffer; |
|
|
|
|
|
|
|
|
uint16_t cycles = 64;; |
|
|
|
|
|
|
|
|
uint16_t cycles = 64; |
|
|
uint16_t tau = tau_global; |
|
|
uint16_t tau = tau_global; |
|
|
do { |
|
|
do { |
|
|
uint16_t x = 0; |
|
|
uint16_t x = 0; |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return tau |
|
|
* @return tau |
|
|
*/ |
|
|
*/ |
|
|
uint16_t AudioTuner::estimate( int64_t *yin, int64_t *rs, uint16_t head, uint16_t tau ) { |
|
|
|
|
|
|
|
|
uint16_t AudioAnalyzeGuitarTuner::estimate( int64_t *yin, int64_t *rs, uint16_t head, uint16_t tau ) { |
|
|
const int64_t *y = ( int64_t * )yin; |
|
|
const int64_t *y = ( int64_t * )yin; |
|
|
const int64_t *r = ( int64_t * )rs; |
|
|
const int64_t *r = ( int64_t * )rs; |
|
|
uint16_t _tau, _head; |
|
|
uint16_t _tau, _head; |
|
|
|
|
|
|
|
|
* @param threshold Allowed uncertainty |
|
|
* @param threshold Allowed uncertainty |
|
|
* @param cpu_max How much cpu usage before throttling |
|
|
* @param cpu_max How much cpu usage before throttling |
|
|
*/ |
|
|
*/ |
|
|
void AudioTuner::initialize( float threshold ) { |
|
|
|
|
|
|
|
|
void AudioAnalyzeGuitarTuner::initialize( float threshold ) { |
|
|
__disable_irq( ); |
|
|
__disable_irq( ); |
|
|
process_buffer = false; |
|
|
process_buffer = false; |
|
|
yin_threshold = threshold; |
|
|
yin_threshold = threshold; |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return true if data is ready else false |
|
|
* @return true if data is ready else false |
|
|
*/ |
|
|
*/ |
|
|
bool AudioTuner::available( void ) { |
|
|
|
|
|
|
|
|
bool AudioAnalyzeGuitarTuner::available( void ) { |
|
|
__disable_irq( ); |
|
|
__disable_irq( ); |
|
|
bool flag = new_output; |
|
|
bool flag = new_output; |
|
|
if ( flag ) new_output = false; |
|
|
if ( flag ) new_output = false; |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return frequency in hertz |
|
|
* @return frequency in hertz |
|
|
*/ |
|
|
*/ |
|
|
float AudioTuner::read( void ) { |
|
|
|
|
|
|
|
|
float AudioAnalyzeGuitarTuner::read( void ) { |
|
|
__disable_irq( ); |
|
|
__disable_irq( ); |
|
|
float d = data; |
|
|
float d = data; |
|
|
__enable_irq( ); |
|
|
__enable_irq( ); |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return periodicity |
|
|
* @return periodicity |
|
|
*/ |
|
|
*/ |
|
|
float AudioTuner::probability( void ) { |
|
|
|
|
|
|
|
|
float AudioAnalyzeGuitarTuner::probability( void ) { |
|
|
__disable_irq( ); |
|
|
__disable_irq( ); |
|
|
float p = periodicity; |
|
|
float p = periodicity; |
|
|
__enable_irq( ); |
|
|
__enable_irq( ); |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @param thresh Allowed uncertainty |
|
|
* @param thresh Allowed uncertainty |
|
|
*/ |
|
|
*/ |
|
|
void AudioTuner::threshold( float p ) { |
|
|
|
|
|
|
|
|
void AudioAnalyzeGuitarTuner::threshold( float p ) { |
|
|
__disable_irq( ); |
|
|
__disable_irq( ); |
|
|
yin_threshold = p; |
|
|
yin_threshold = p; |
|
|
__enable_irq( ); |
|
|
__enable_irq( ); |