## Question regarding notefreq code

Hi

I have a few questions regading the code of analzye_notefreq. Since it was written by duff most probably can answer it, but some questions are rather general, so maybe sombody else can also provide some insight. I have a background in programming in different languages, but I am by no means a c/c++ expert. Also I normally programm on "high level", means not close to hardware and rarely have to really optimize code. Therefore some questions might be basic.
I had read the YIN paper a while ago and also wrote matlab code that works. I was glad that there already exists a optimized version for teensy which worked well for my project. I had a look at the code to see whether I could adapt it a little for my specific needs to improve detection. Then some questions surfaced

first question is around line 106 in the calculation of the difference function:
Code:
```            lag = *( ( int16_t * )p + ( x+tau ) );
current = *( ( int16_t * )p+x );
delta = ( current-lag );
sum += delta * delta;
x += 4;```
x is incremented by 4 and therefore also the pointer to the audiobuffer. it looks like the audio buffer is subsampled by a factor of 4? is that correct?

the the block above is copied 4 times in the while loop. is this to reduce the "while checks" on the end? does this really make much difference? also, the number of "iterations" to generate the sum is depends on AUDIO_GUITARTUNER_BLOCKS, so one could also use a for loop. I assume there is a reason to use a while?

next question is line 191, in the parabolic interpolation routine. the indices to the yin "ringbuffer" are calculated. if the head index is 4. idx1 is reset to 0 (which is correct, as the rinbuffer has 5 elements), however idx2 is also set to 0, but I think it should be 1.

Code:
```        idx0 = _head;
idx1 = ( idx1 >= 5 ) ? 0 : idx1;
idx2 = ( idx2 >= 5 ) ? 0 : idx2;```
general question (e.g. line 260) regarding passing values. what is the reason for disabling and later enabling interrupts?

Code:
```float AudioAnalyzeNoteFrequency::probability( void ) {
__disable_irq( );
float p = periodicity;
__enable_irq( );
return p;```

thanks

Polar