📄 sac_e.c
字号:
#include <stdio.h>#include "sim.h"#define q1_e 16384#define q2_e 32768#define q3_e 49152#define top_e 65535static long low_e=0, high_e=top_e, opposite_bits_e=0, length_e=0, zerorun_e=0;int AR_Encode(int index, int cumul_freq[ ]){ int bitcount=0; if (index<0) return -1; /* Escape Code */ length_e = high_e - low_e + 1; high_e = low_e - 1 + (length_e * cumul_freq[index]) / cumul_freq[0]; low_e += (length_e * cumul_freq[index+1]) / cumul_freq[0]; for ( ; ; ) { if (high_e < q2_e) { bitcount+=bit_opp_bits(0); } else if (low_e >= q2_e) { bitcount+=bit_opp_bits(1); low_e -= q2_e; high_e -= q2_e; } else if (low_e >= q1_e && high_e < q3_e) { opposite_bits_e += 1; low_e -= q1_e; high_e -= q1_e; } else break; low_e *= 2; high_e = 2*high_e+1; } return bitcount;}int bit_opp_bits(int bit) /* Output a bit and the following opposite bits */ { int bitcount=0; bitcount = bit_in_psc_layer(bit); while(opposite_bits_e > 0){ bitcount += bit_in_psc_layer(!bit); opposite_bits_e--; } return bitcount;}int encoder_flush(){ int bitcount = 0; if (trace) fprintf(tf, "encoder_flush:\n"); opposite_bits_e++; if (low_e < q1_e) { bitcount+=bit_opp_bits(0); } else { bitcount+=bit_opp_bits(1); } low_e = 0; high_e = top_e; zerorun_e=0; return bitcount;}int bit_in_psc_layer(int bit){ void putbits (int, int); int bitcount = 0; if (zerorun_e > 13) { if (trace) fprintf(tf, "PSC emulation ... Bit stuffed.\n"); putbits (1, 1); bitcount++; zerorun_e = 0; } putbits (1, bit); bitcount++; if (bit) zerorun_e = 0; else zerorun_e++; return bitcount;}
int indexfn(int value, int table[], int max){ int n=0; while(1) { if (table[n++]==value) return n-1; if (n>max) return -1; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -