Reading data at 10 Khz rate

The code on post 32.
Some time that code also looses its Sync but once it looses it comes back after 2-3 wrong value
No in that code you have checked only 32 byte and after you skip a pules but data stream is continuous so pulse skip might not possible

const int CLOCK_PIN     =     2;
const int DATA_PIN      =     4;
const int PACKET_BITS   =     128;
const int PREAMBLE_LEN  =    6;
const int DATA_LEN      =    ((PACKET_BITS / 4) - PREAMBLE_LEN);

enum {
    PRE_0,    PRE_1,    PRE_2,    PRE_3,    PRE_4,    PRE_5,    DATA
} states;    

byte     preamble [] = {0x0C,0x0A,0x0A,0x0C,0x01,0x0F};
char     hexAsciiVals[] = "0123456789ABCDEF";
byte     state = PRE_0;
byte     nibble;
int        nibble_count = 0;

void setup() {
  pinMode(CLOCK_PIN, INPUT);
  pinMode(DATA_PIN, INPUT);
  Serial.begin(9600);
}

void loop() {

    nibble = getNibble();
    nibble_count++;
    
    switch (state) {    
        case PRE_0:
            if (nibble_count > 32) { // I made this change for my own understanding
                // we've read 32 bytes and still not found a match 
                // for the preamble so skip a clock pulse
                while (digitalRead(CLOCK_PIN) == HIGH);
                while (digitalRead(CLOCK_PIN) == LOW);
                nibble_count = 0;
            } else {
                state = (nibble == preamble[0]) ? PRE_0 : PRE_1;
            }
            break;
        
        case PRE_1:
            state = (nibble == preamble[1]) ? PRE_0 : PRE_2;    
            break;
            
        case PRE_2:
            state = (nibble == preamble[2]) ? PRE_0 : PRE_3;
            break;

        case PRE_3:
            state = (nibble == preamble[3]) ? PRE_0 : PRE_4;
            break;

        case PRE_4:
            state = (nibble == preamble[4]) ? PRE_0 : PRE_5;
            break;
        
        case PRE_5:
            state = (nibble == preamble[5]) ? PRE_0 : DATA;
            break;
            
        case DATA:
            Serial.write (hexAsciiVals[nibble]);
            if (nibble_count == DATA_LEN) {
                // all done, start again
                state = PRE_0;
                nibble_count = 0;
            }
            break;
    }
}

byte getNibble() {

    byte val = 0;
    
    for (byte bit_count = 0; bit_count < 4; bit_count++) {
        while (digitalRead(CLOCK_PIN) == HIGH);
        
          while (digitalRead(CLOCK_PIN) == LOW);
        
          val <<= 1;
          val |= digitalRead(DATA_PIN);
        
          
    }
    return (val &= 0x0F);
}