⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tty_bit.c

📁 完整的EVRC压缩解压缩算法源码,通过C-C++编译后可以运行!
💻 C
📖 第 1 页 / 共 2 页
字号:
        /*
        *  If there is a transition in the dits
        *  count mark, space, and unknown dits in
        *  a window and form TTY bits.
        */
                                                    
        if( sub(ditbuf[i],ditbuf[i+1]) != 0 )
        {
            mark_counter = 0;                       
            space_counter = 0;                      
            good_dits = 0;                          
            bad_dits = 0;                           
            tty_unknown_counter = 0;                
            for( j=i+1 ; j < MIN(DITBUF_LEN,MAX_BIT_LEN+i+2) ; j++ )
            {
                /* Count LOGIC_1, LOGIC_0, and UNKNOWN dits */
                                                    
                if( sub(ditbuf[j],LOGIC_0) == 0 )
                {
                    space_counter = add(space_counter,1);
                }
                else if( sub(ditbuf[j],LOGIC_1) == 0 )
                {
                    mark_counter = add(mark_counter,1);                 
                }
                else
                {
                    tty_unknown_counter = add(tty_unknown_counter,1);          
                }

                /* Check if there are more 1's or 0's in the dit window */
                                                    
                if( sub(space_counter,mark_counter) > 0 )
                {
                    bit = LOGIC_0;                  
                    good_dits = space_counter;      
                    bad_dits = mark_counter;        
                }
                else
                {
                    bit = LOGIC_1;                  
                    good_dits = mark_counter;       
                    bad_dits = space_counter;       
                }


                /* If the number of UNKNOWN's is too high, abort */
                                                    
                if( ( sub(tty_unknown_counter,TTY_BIT_UNKNOWN_THRESH) > 0
                     || sub(bad_dits,BAD_DIT_THRESH) > 0 )
                    && sub(good_dits,GOOD_DIT_THRESH) < 0
                  )
                {
                    break;
                }

                /*
                *  If the new bit is different from the previous bit
                *  and the new bit starts with dits from the previous
                *  bit, break so that the bit boundaries will resync.
                *  in the logic below.
                */

                if( sub(bit,tty_bit_hist[STOP_BIT_IDX]) != 0
                    && ( sub(ditbuf[i+1],tty_bit_hist[STOP_BIT_IDX]) == 0
                        || ( sub(bit,ditbuf[i+1]) != 0
                             && ( sub(ditbuf[i+1],LOGIC_0) == 0
                                  || sub(ditbuf[i+1],LOGIC_1) == 0 ))
                       )
                  )
                {
                    break;
                }

                /*
                *  If the number of mark or space detections is above
                *  a minimum threshold...
                */

                len = sub(j,i);
                                                                    
                if( sub(good_dits,GOOD_DIT_THRESH) >= 0
                    && sub(bad_dits,BAD_DIT_THRESH) <= 0
                    && sub(len,MIN_BIT_LEN) >= 0
                  )
                {
                    /* If there is a break in the run of dits... */
                                                                    
                    if( sub(bit,ditbuf[j]) != 0 )
                    {
                        /*
                        *  If the run is broken by a mark or space,
                        *  declare the current bit.
                        */
                                                                    
                        if( sub(ditbuf[j],LOGIC_0) == 0
                            || sub(ditbuf[j],LOGIC_1) == 0
                            || sub(tty_unknown_counter,TTY_BIT_UNKNOWN_THRESH) > 0
                          )
                        {
                            /* Subtract the last dit from the counters */
                            len = sub(len,1);
                            if( sub(len,MIN_BIT_LEN) < 0 )
                            {
                                break;
                            }


                            bit_len = len;
                            bad_dits = sub(bad_dits,1);
                            *bit_index = sub(j,1);                       
                            update_flag = 1;                        
                            break;
                        }
                    }
                                                                    
                    if( sub(len,MAX_BIT_LEN) > 0 )
                    {
                                                                    
                        if( sub(baud_rate,TTY_45_BAUD) == 0 )
                        {
                            bit_len = BIT_LEN_45_BAUD;              
                        }
                        else
                        {
                            bit_len = BIT_LEN_50_BAUD;              
                        }

                        /*
                        *  Subtract the unknown/bad dits from the counter if
                        *  they are beyond bit_len.
                        */
                        for( k=0 ; k <= (MAX_BIT_LEN-bit_len) ; k++ )
                        {
                                                                    
                            if( sub(ditbuf[i+k+bit_len+1],bit) != 0 )
                            {
                                tty_unknown_counter = sub(tty_unknown_counter,1);
                            }
                            else
                            {
                                good_dits = sub(good_dits,1);
                            }
                        }

                        if( sub(good_dits,GOOD_DIT_THRESH) < 0 )
                        {
                            bit_len = 0;
                            break;
                        }

                        *bit_index = add(bit_len,i);                     
                        update_flag = 1;                            

                        break;
                    }
                }

                /*
                *  If the end of the ditbuf came before the end of a
                *  run was found, but the partial bit result in the
                *  last element of tty_bit_hist[]
                */

                if( sub(j,DITBUF_LEN-1) == 0 )
                {
                    bit_len = len;
                    tty_bit_hist[TTY_BIT_HIST_LEN-1] = bit;         
                    tty_bit_len_hist[TTY_BIT_HIST_LEN-1] = bit_len; 
                    *bit_index = i;                                 
                    break;
                }

            } /* end for(j) */

            /* If a TTY bit was detected */
                                                                    
            if( bit_len > 0 )
            {
                break;
            }
            else if( ( sub(ditbuf[i+1],LOGIC_0) == 0
                       || sub(ditbuf[i+1],LOGIC_1) == 0)
                     && ( sub(ditbuf[i+1],tty_bit_hist[STOP_BIT_IDX]) == 0 )
                   )
            {
                /*
                *  Resync the bit boundaries if a bit wasn't found but
                *  mark or space detections from the previous bit
                *  were found.
                */
                                                                        

                if( sub(baud_rate,TTY_50_BAUD) == 0
                    || sub(tty_bit_len_hist[STOP_BIT_IDX],BIT_LEN_45_BAUD) < 0 )
                {
                    /*
                    *  If the baud rate is 50 or the bit_len is less than a nominal
                    *  45 baud bit, add the extra dits to last bit.  This helps switch
                    *  from 50 baud to 45 baud.
                    */
                    tty_bit_len_hist[STOP_BIT_IDX] = add(tty_bit_len_hist[STOP_BIT_IDX],1);
                    ditbuf[i+1] = ERASE;                                
                    fail_counter = 0;                                   
                    *bit_index = add(i,1);                                   
                }
                else
                {
                    /*
                    *  If the baud rate is 45 baud, use the extra dits to start a new
                    *  bit, making it easier to switch into 50 baud.
                    */
                    bit = ditbuf[i+1];
                    bit_len = 1;
                    bad_dits = 0;
                    *bit_index = add(i,1);                       
                    fail_counter = 0;                       
                    update_flag = 1;                        
                    break;
                }
            }


        } /* end if( ditbuf[i] != ditbuf[i+1] ) */


    } /* end for(i) */



                                                                        
    /* Erase dits that were counted as part of a bit */

    for( i=0 ; i <= *bit_index ; i++ )
    {
        ditbuf[i] = ERASE;
    }


    /* Update history buffers */

    if( update_flag == 0 )
    {
        *bit_index = add(*bit_index,bit_len);
        tty_unknown_counter = 0;                    
        bad_dits = 0;                               
    }
    else
    {
        /* Update tty_bit_hist[] */

        for( i=1 ; i < TTY_BIT_HIST_LEN-1 ; i++ )
        {
            tty_bit_hist[i-1] = tty_bit_hist[i];                
        }

        /* Update tty_bit_len_hist[] */

        for( i=2 ; i < TTY_BIT_HIST_LEN-1 ; i++ )
        {
            tty_bit_len_hist[i-1] = tty_bit_len_hist[i];        
        }
        
        /* Update history with newest bit */
        
        tty_bit_hist[STOP_BIT_IDX] = bit;                       
        tty_bit_len_hist[STOP_BIT_IDX] = bit_len;               

        tty_bit_hist[TTY_BIT_HIST_LEN-1] = ERASE;               
        tty_bit_len_hist[TTY_BIT_HIST_LEN-1] = 0;               
    }



    /*
    *  Zero the unknown counter for the character
    *  if a LOGIC_0 is in the memory bit.
    */

    if( sub(tty_bit_hist[MEM_BIT_IDX],LOGIC_0) == 0 )
    {
        tty_bit_len_hist[MEM_BIT_IDX] = 0;
    }


    /* Update the total # of bad and unknown dits  */

    tty_bit_len_hist[MEM_BIT_IDX] = add(tty_bit_len_hist[MEM_BIT_IDX],tty_unknown_counter);
    tty_bit_len_hist[MEM_BIT_IDX] = add(tty_bit_len_hist[MEM_BIT_IDX],bad_dits);



    return(update_flag);

} /* end get_tty_bit() */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -