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

📄 dit2a.c

📁 完整的EVRC压缩解压缩算法源码,通过C-C++编译后可以运行!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Permission is granted to 3GPP2 participants to copy any portion of*/
/* this contribution for the legitimate purpose of the 3GPP2.        */
/* Copying this contribution for monetary gain or other non-3GPP2    */
/* purpose is prohibited.                                            */
/*                                                                   */
/*-------------------------------------------------------------------*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <math.h>
#include "typedef.h"
#include "tty.h"
#include "basic_op.h"

#include "tty_dbg.h"

#define DEBUG_LEVEL     1   /* 0=OFF, -1=ALL ON, or [1-5] */
#define DEBUG(n,x)      if( (n <= DEBUG_LEVEL || DEBUG_LEVEL < 0) && tty_debug_print_flag) {x}

#define MIN_TTY_ONSET_FRAMES    4   /* Minimum times to transmit TTY_ONSET */

#define FRAMING_HANGOVER    12      /* # of frames from the start
                                    *  of framing a character 
                                    *  to still output that  
                                    *  character's info
                                    */


void FlushBuffer(Word16 *inbuf,Word16 bufLen,Word16 fillValue);

Word16    framingCount;
Word16    ttyState;
Word16    last_char_counter;
Word16    first_tty_char_flag;

Word16    last_tty_char;

Word16  tty_bit_hist[TTY_BIT_HIST_LEN];
Word16  tty_bit_len_hist[TTY_BIT_HIST_LEN];

unsigned long   dit2a_char_count = 0;   /* for debugging only */

/*********************************************************************
*   init_dit_to_ascii()
**********************************************************************/

void init_dit_to_ascii()
{
	/* initialize stuff */

    ttyState = NON_TTY_MODE;
    framingCount = -MIN_TTY_ONSET_FRAMES;
    last_tty_char = -1;

    last_char_counter = TTY_COUNTER_STOP;
    first_tty_char_flag = 0;

    FlushBuffer(tty_bit_hist,TTY_BIT_HIST_LEN,UNKNOWN);
    FlushBuffer(tty_bit_len_hist,TTY_BIT_HIST_LEN,0);

} 
	
/*********************************************************************
*   dit_to_ascii()
**********************************************************************/

void dit_to_ascii(
    Word16  *tty_char,      /* (i/o): prev/new character decision   */
    Word16  *char_counter,  /* (i/o): prev/new character counter    */
    Word16  *tty_baud_rate, /* (i/o): prev/new character counter    */
    Word16  ditbuf[])     /* (i): dits for current frame          */
{
    
    Word16  temp;
    Word16  bit_index;


    DEBUG(2,fprintf(stdout,"--------------------------------------\n");)

    if( sub(framingCount,FRAMING_HANGOVER) >= 0 )
    {
        last_tty_char = -1;
        framingCount = 0;
    }

    bit_index = 0;
    while( sub(bit_index,DITBUF_LEN-MIN_BIT_LEN+1) < 0 )
    {
        temp = get_tty_bit( tty_bit_hist,
                            tty_bit_len_hist,
                            &bit_index,
                            ditbuf,
                            *tty_baud_rate );

        DEBUG(2,
        {
          int   i;
            fprintf(stdout,"\ntty_bit_hist[]: ");
            for( i=0 ; i < TTY_BIT_HIST_LEN ; i++ )
            {
                fprintf(stdout," %3d",tty_bit_hist[i]);
            }
            fprintf(stdout,"\n                ");
            for( i=0 ; i < TTY_BIT_HIST_LEN ; i++ )
            {
                fprintf(stdout," %3d",tty_bit_len_hist[i]);
            }
            fprintf(stdout,"\n\n");
        }
        )


        temp = get_tty_char( tty_char, tty_bit_hist, tty_bit_len_hist );

        get_tty_state( &ttyState,
                       first_tty_char_flag,
                       tty_bit_hist,
                       tty_bit_len_hist );

                                                        
        if( temp != 0 )
        {
            if( framingCount > 0 )
            {
                framingCount = 0;                       
            }
            first_tty_char_flag = 1;                    

            /* Increment to next counter value (by shifting) */
            *char_counter = shl(last_char_counter,1);     
                                                        
            if( sub((*char_counter),TTY_COUNTER_STOP) > 0 )
            {
                *char_counter = TTY_COUNTER_START;      
            }
            last_char_counter = *char_counter;          
            last_tty_char = *tty_char;

            tty_rate( tty_baud_rate, tty_bit_len_hist );

            ++dit2a_char_count;

            DEBUG(1,fprintf(stdout,"dit2a: %lu: Regained char = %2d  counter = %d  rate = %d\n",
                dit2a_char_count, *tty_char, *char_counter, *tty_baud_rate );)
        }

    } /* end while() */

    if( last_tty_char < 0 ) /* if a character is not ready */
    {
        if( sub(ttyState,NON_TTY_MODE) == 0 )
        {
                                                        
            *char_counter = NON_TTY;                    
            *tty_char = 0;                              
            framingCount = -MIN_TTY_ONSET_FRAMES;
        }
        else /* ttyState == TTY_ONSET */
        {
            /***
            **** FIX: changed from SILENCE to ONSET so that encoder
            **** forces the rate to full rate - sab
            ***/
            
            *char_counter = TTY_ONSET;                  
            *tty_char = TTY_ONSET_CHAR;                 
            if( framingCount < 0 )
            {
                framingCount = add(framingCount,1);
            }
        }
    }
    else if( framingCount < 0 ) /* if a character is ready but not enough TTY_ONSET messages */
    {
        *char_counter = TTY_ONSET;                  
        *tty_char = TTY_ONSET_CHAR;                 
        framingCount = add(framingCount,1);
    }
    else
    {
        *char_counter = last_char_counter;
        *tty_char = last_tty_char;
        framingCount = add(framingCount,1);
    }


    DEBUG(3,fprintf(stdout,"ttyState = %2d  framingCount = %2d  counter = %2d  char = %2d\n",
        ttyState,framingCount,*char_counter,*tty_char);)

    
} /* end dit_to_ascii() */



/*********************************************************************
*   FlushBuffer()
**********************************************************************/

void FlushBuffer(Word16 *inbuf,Word16 bufLen,Word16 fillValue)
{
    Word16  i;

	for(i=0; i<bufLen; ++i)
    {
        inbuf[i] = fillValue;                               
    }
}


⌨️ 快捷键说明

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