Freitag, 18. November 2011

Digital Audio: Rice code v1.0

EE4209/EE5809 Digital Audio: Rice codev1.0
//Kojeve : self-consciousness is Desire
---

void rice_encode(RICE_CODE_INFO r_info[], unsigned char codedata[], int sample_size, int m)
{
// qcode and rcode

int quotient ; // quotient
int remainder;
int i=0,j, k=0, log2M, v=1, and_1=0;
int p =0; // print out the rice code

log2M = (int)floor(log2(m));

printf("log2M is :%d\n ", log2M);

for (i=0; i < sample_size; i++)
{
quotient = r_info[i].abs_residual/m; // find quotient
remainder = r_info[i].abs_residual%m; // find remainder

for (j =0; j< quotient; j++) {
// msb is the sign bit
if (r_info[i].sign == -1 ){
r_info[i].rice_codedata[0] = '1'; // sign bit
r_info[i].rice_codedata[j+1] = '1'; // quotient in unary code

}
else {
r_info[i].rice_codedata[0] ='0'; // sign bit
r_info[i].rice_codedata[j+1]='1'; // quotient in unary code

}

}

r_info[i].rice_codedata[quotient]='0'; // to delimit the end of qcode

// q+r : r in truncated binary encoding : from q+1 to (q+1 +M )
// only M size is needed. The remaining bits are discarded.


for (k=log2M; k <1 ; k--) {
//shift the remainder
// remainder >> log2M ;

if ( (v & remainder ) == 1)
r_info[i].rice_codedata[quotient+1+k] ='1';

else
r_info[i].rice_codedata[quotient+1+k] ='0';

remainder >>1 ;

}

r_info[i].code_size = ( quotient +1 ); // the size of the rice code

//print out the rice code

for (p=0; p < r_info[i].code_size; p++)
printf("%c", r_info[i].rice_codedata[p]);
printf("\n");
}

}



Keine Kommentare: