-
- int GetT55x7Clock( const int * data, const size_t len, int peak ){
-
- int i,lastpeak,clock;
- clock = 0xFFFF;
- lastpeak = 0;
-
- /* Detect peak if we don't have one */
- if (!peak) {
- for (i = 0; i < len; ++i) {
- if (data[i] > peak) {
- peak = data[i];
- }
- }
- }
-
- for (i = 1; i < len; ++i) {
- /* if this is the beginning of a peak */
- if ( data[i-1] != data[i] && data[i] == peak) {
- /* find lowest difference between peaks */
- if (lastpeak && i - lastpeak < clock)
- clock = i - lastpeak;
- lastpeak = i;
- }
- }
-
- // When detected clock is 31 or 33 then then return
- int clockmod = clock%8;
- if ( clockmod == 0) return clock;
-
- if ( clockmod == 7 ) clock += 1;
- else if ( clockmod == 1 ) clock -= 1;
-
- return clock;
- }