# HG changeset patch # User chust # Date 2014-05-02 15:06:17 # Node ID ccd69f4e7a6050ffa67bd25415e45fa7d564ce16 # Parent be100cfb14bdf6e110059075a2e1194adfb6a4d4 version 1.3 qui finalise la version 1.2 (pb d'alignement mémoire réglé pour BP1 et BP2) (NB_BINS_COMPRESSED_MATRIX_f0 = 11 + quelques mises en forme des commentaires) diff --git a/basic_parameters.c b/basic_parameters.c --- a/basic_parameters.c +++ b/basic_parameters.c @@ -2,6 +2,7 @@ // version 1.0: 31/07/2013 // version 1.1: 02/04/2014 // version 1.2: 30/04/2014 +// version 1.3: 02/05/2014 #include "basic_parameters.h" #include @@ -92,8 +93,7 @@ void init_k_f0( void ) float alpha_M = 45 * (3.1415927/180); void BP1_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp1 ){ - int exponent; // 32 bits signed - float PSDB; // 32 bits floating point + float PSDB; // 32-bit floating point float PSDE; float tmp; float NVEC_V0; @@ -110,13 +110,14 @@ void BP1_set( float * compressed_spec_ma float bx_bx_star; float vphi; float significand; - uint8_t nbitexp; // 8 bits unsigned + int exponent; // 32-bit signed integer + uint8_t nbitexp; // 8-bit unsigned integer uint8_t nbitsig; uint8_t tmp_uint8; - uint8_t *pt_uint8; // pointer on unsigned 8-bit bytes - int8_t expmin; // 8 bits signed + uint8_t *pt_uint8; // pointer on unsigned 8-bit integer + int8_t expmin; // 8-bit signed integer int8_t expmax; - int16_t rangesig; // 16 bits unsigned + uint16_t rangesig; // 16-bit unsigned integer uint16_t psd; uint16_t exp; uint16_t tmp_uint16; @@ -161,9 +162,9 @@ void BP1_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding @@ -259,16 +260,16 @@ void BP1_set( float * compressed_spec_ma NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3 - lfr_bp1[i*NB_BYTES_BP1+4] = (uint8_t) (NVEC_V0*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp1[i*NB_BYTES_BP1+5] = (uint8_t) (NVEC_V1*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - pt_uint8 = (uint8_t*) &NVEC_V2; // affect an uint8_t pointer with the adress of NVEC_V2 + lfr_bp1[i*NB_BYTES_BP1+4] = (uint8_t) (NVEC_V0*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp1[i*NB_BYTES_BP1+5] = (uint8_t) (NVEC_V1*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2 #ifdef LSB_FIRST_TCH - lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[3] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention) - // record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6] + lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[3] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention) + // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6] #endif #ifdef MSB_FIRST_TCH - lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[0] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 0th octet:SPARC convention) - // record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6] + lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[0] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 0th octet:SPARC convention) + // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6] #endif #ifdef DEBUG_TCH printf("NVEC_V0 : %16.8e\n",NVEC_V0); @@ -280,13 +281,13 @@ void BP1_set( float * compressed_spec_ma #endif //======================================================= // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits - aux = 2*tmp / PSDB; // compute the ellipticity + aux = 2*tmp / PSDB; // Compute the ellipticity - tmp_uint8 = (uint8_t) (aux*15 + 0.5); // shift and cast into a 8-bit uint8_t with rounding - // where just the first 4 bits are used (0, ..., 15) - lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | (tmp_uint8 << 3); // put these 4 bits next to the right place - // of the sign bit of NVEC_V2 (recorded - // previously in lfr_bp1[i*NB_BYTES_BP1+6]) + tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding + // where just the first 4 bits are used (0, ..., 15) + lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | (tmp_uint8 << 3); // Put these 4 bits next to the right place + // of the sign bit of NVEC_V2 (recorded + // previously in lfr_bp1[i*NB_BYTES_BP1+6]) #ifdef DEBUG_TCH printf("ellipticity : %16.8e\n",aux); printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8); @@ -304,12 +305,12 @@ void BP1_set( float * compressed_spec_ma + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]; aux = PSDB*PSDB; - tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // compute the degree of polarisation + tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation - tmp_uint8 = (uint8_t) (tmp*7 + 0.5);// shift and cast into a 8-bit uint8_t with rounding + tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding // where just the first 3 bits are used (0, ..., 7) - lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | tmp_uint8; // record these 3 bits at the 3 first bit positions - // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6] + lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | tmp_uint8; // Record these 3 bits at the 3 first bit positions + // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6] #ifdef DEBUG_TCH printf("DOP : %16.8e\n",tmp); printf("tmp_uint8 for DOP : %u\n",tmp_uint8); @@ -348,21 +349,21 @@ void BP1_set( float * compressed_spec_ma #ifdef DEBUG_TCH printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2); #endif - pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re + pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re #ifdef LSB_FIRST_TCH lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention) - // Record it at the 8th bit position (from the right to the left) - // of lfr_bp1[i*NB_BYTES_BP1+1] + // Record it at the 8th bit position (from the right to the left) + // of lfr_bp1[i*NB_BYTES_BP1+1] pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX| #endif #ifdef MSB_FIRST_TCH lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 0th octet:SPARC convention) - // Record it at the 8th bit position (from the right to the left) - // of lfr_bp1[i*NB_BYTES_BP1+1] + // Record it at the 8th bit position (from the right to the left) + // of lfr_bp1[i*NB_BYTES_BP1+1] pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX| #endif - significand = frexpf(e_cross_b_re/2, &exponent);// 0.5 <= significand < 1 - // ReaSX/2 = significand * 2^exponent + significand = frexpf(e_cross_b_re/2, &exponent); // 0.5 <= significand < 1 + // ReaSX/2 = significand * 2^exponent // The division by 2 is to ensure that max value <= 2^30 (rough estimate) // Should be reconsidered by taking into account the k-coefficients ... @@ -374,15 +375,15 @@ void BP1_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } lfr_bp1[i*NB_BYTES_BP1+7] = (uint8_t) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding - // where just the first 3 bits are used (0, ..., 7) + // where just the first 3 bits are used (0, ..., 7) tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where - // just the first 5 bits are used (0, ..., 2^5-1) + // just the first 5 bits are used (0, ..., 2^5-1) #ifdef DEBUG_TCH printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2); printf("significand : %16.8e\n",significand); @@ -390,8 +391,8 @@ void BP1_set( float * compressed_spec_ma printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]); printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8); #endif - lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (tmp_uint8 << 3); // shift these 5 bits to the left before logical addition - // with lfr_bp1[i*NB_BYTES_BP1+7] + lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (tmp_uint8 << 3); // Shift these 5 bits to the left before logical addition + // with lfr_bp1[i*NB_BYTES_BP1+7] #ifdef DEBUG_TCH printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]); printf("lfr_bp1[i*NB_BYTES_BP1+1] for ReaSX sign + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+1]); @@ -399,15 +400,15 @@ void BP1_set( float * compressed_spec_ma #endif pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im #ifdef LSB_FIRST_TCH - pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| + pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| #endif #ifdef MSB_FIRST_TCH - pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| + pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| #endif tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect - // an unsigned 8-bit char with 01000000; otherwise with null. - lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right - // to the left) of lfr_bp1[i*NB_BYTES_BP1+1], by simple logical addition. + // an unsigned 8-bit char with 01000000; otherwise with null. + lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right + // to the left) of lfr_bp1[i*NB_BYTES_BP1+1], by simple logical addition. #ifdef DEBUG_TCH printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2); printf("ArgSX sign : %u\n",tmp_uint8); @@ -462,7 +463,7 @@ void BP1_set( float * compressed_spec_ma printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im); #endif // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re) - pt_uint8 = (uint8_t*) &n_cross_e_scal_b_re; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_re + pt_uint8 = (uint8_t*) &n_cross_e_scal_b_re; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_re #ifdef LSB_FIRST_TCH lfr_bp1[i*NB_BYTES_BP1+3] = lfr_bp1[i*NB_BYTES_BP1+3] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention) // Record it at the 8th bit position (from the right to the left) @@ -477,8 +478,8 @@ void BP1_set( float * compressed_spec_ma #endif vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI| - significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1 - // vphi/2 = significand * 2^exponent + significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1 + // vphi/2 = significand * 2^exponent // The division by 2 is to ensure that max value <= 2^30 (rough estimate) // Should be reconsidered by taking into account the k-coefficients ... @@ -500,9 +501,9 @@ void BP1_set( float * compressed_spec_ma printf("exponent : %d\n" ,exponent); #endif lfr_bp1[i*NB_BYTES_BP1+8] = (uint8_t) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding - // where just the first 3 bits are used (0, ..., 7) + // where just the first 3 bits are used (0, ..., 7) tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where - // just the first 5 bits are used (0, ..., 2^5-1) + // just the first 5 bits are used (0, ..., 2^5-1) #ifdef DEBUG_TCH printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]); printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8); @@ -515,15 +516,15 @@ void BP1_set( float * compressed_spec_ma #endif pt_uint8 = (uint8_t*) &n_cross_e_scal_b_im; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_im #ifdef LSB_FIRST_TCH - pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| + pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| #endif #ifdef MSB_FIRST_TCH - pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| + pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| #endif tmp_uint8 = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect - // an unsigned 8-bit char with 01000000; otherwise with null. - lfr_bp1[i*NB_BYTES_BP1+3] = lfr_bp1[i*NB_BYTES_BP1+3] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right - // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition. + // an unsigned 8-bit char with 01000000; otherwise with null. + lfr_bp1[i*NB_BYTES_BP1+3] = lfr_bp1[i*NB_BYTES_BP1+3] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right + // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition. #ifdef DEBUG_TCH printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im); printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2); @@ -535,12 +536,21 @@ void BP1_set( float * compressed_spec_ma void BP2_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp2 ) { - int i, exponent; - float aux, significand, cross_re, cross_im; - int8_t nbitexp, nbitsig, expmin, expmax; // 8 bits - int16_t rangesig; // 16 bits - uint16_t autocor, tmp_uint16; // 16 bits - uint16_t *pt_u_short_int; // pointer on unsigned 16-bit words + float cross_re; // 32-bit floating point + float cross_im; + float aux; + float significand; + int exponent; // 32-bit signed integer + uint8_t nbitexp; // 8-bit unsigned integer + uint8_t nbitsig; + uint8_t *pt_uint8; // pointer on unsigned 8-bit integer + int8_t expmin; // 8-bit signed integer + int8_t expmax; + uint16_t rangesig; // 16-bit unsigned integer + uint16_t autocor; + uint16_t exp; + uint16_t tmp_uint16; + uint16_t i; #ifdef DEBUG_TCH printf("BP2 : \n"); @@ -548,8 +558,8 @@ void BP2_set( float * compressed_spec_ma #endif // For floating point data to be recorded on 16-bit words : - nbitexp = 6; // number of bits for the exponent - nbitsig = 16 - nbitexp; // number of bits for the significand + nbitexp = 6; // number of bits for the exponent + nbitsig = 16 - nbitexp; // number of bits for the significand rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1 expmax = 32; expmin = expmax - (1 << nbitexp) + 1; @@ -586,8 +596,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux; - lfr_bp2[i*NB_BYTES_BP2+10] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+20] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+10] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+20] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("\nBin number: %d\n", i); printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]); @@ -597,8 +607,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux; - lfr_bp2[i*NB_BYTES_BP2+11] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+21] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+11] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+21] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]); printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]); @@ -607,8 +617,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux; - lfr_bp2[i*NB_BYTES_BP2+12] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+22] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+12] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+22] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]); printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]); @@ -617,8 +627,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux; - lfr_bp2[i*NB_BYTES_BP2+13] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+23] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+13] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+23] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]); printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]); @@ -627,8 +637,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux; - lfr_bp2[i*NB_BYTES_BP2+14] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+24] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+14] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+24] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]); printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]); @@ -637,8 +647,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux; - lfr_bp2[i*NB_BYTES_BP2+15] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+25] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+15] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+25] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]); printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]); @@ -647,8 +657,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux; - lfr_bp2[i*NB_BYTES_BP2+16] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+26] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+16] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+26] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]); printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]); @@ -657,8 +667,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux; - lfr_bp2[i*NB_BYTES_BP2+17] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+27] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+17] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+27] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]); printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]); @@ -667,8 +677,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux; - lfr_bp2[i*NB_BYTES_BP2+18] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+28] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+18] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+28] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]); printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]); @@ -677,8 +687,8 @@ void BP2_set( float * compressed_spec_ma aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux; cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux; - lfr_bp2[i*NB_BYTES_BP2+19] = (uint8_t) (cross_re*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding - lfr_bp2[i*NB_BYTES_BP2+29] = (uint8_t) (cross_im*127.5 + 128); // shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+19] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding + lfr_bp2[i*NB_BYTES_BP2+29] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding #ifdef DEBUG_TCH printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]); printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]); @@ -692,7 +702,7 @@ void BP2_set( float * compressed_spec_ma // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits // S11 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1 - // S11 = significand * 2^exponent + // S11 = significand * 2^exponent #ifdef DEBUG_TCH printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]); printf("significand : %16.8e\n",significand); @@ -706,30 +716,38 @@ void BP2_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding - // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) - tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int - // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1) - pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+0]; // Affect an uint16_t pointer with the - // adress where the 16-bit word result will be stored - *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the - // left place of the significand bits (nbitsig), making - // the 16-bit word to be recorded, and record it using the pointer + // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) + exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just + // the first nbitexp bits are used (0, ..., 2^nbitexp-1) + tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the + // left place of the significand bits (nbitsig), + // making the 16-bit word to be recorded + pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16 +#ifdef LSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[0]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[1]; // Record MSB of tmp_uint16 +#endif +#ifdef MSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[1]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[0]; // Record MSB of tmp_uint16 +#endif #ifdef DEBUG_TCH - printf("autocor for S11 significand : %u\n",autocor ); - printf("tmp_uint8 for S11 exponent : %u\n",tmp_uint16 ); - printf("*pt_u_short_int for S11 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int); - printf("lfr_bp2[i*NB_BYTES_BP2+1] : %u or %x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]); - printf("lfr_bp2[i*NB_BYTES_BP2+0] : %u or %x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+0]); + printf("autocor for S11 significand : %u\n",autocor); + printf("exp for S11 exponent : %u\n",exp); + printf("pt_uint8[1] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]); + printf("pt_uint8[0] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]); + printf("lfr_bp2[i*NB_BYTES_BP2+1] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]); + printf("lfr_bp2[i*NB_BYTES_BP2+0] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+0]); #endif // S22 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1 - // S22 = significand * 2^exponent + // S22 = significand * 2^exponent #ifdef DEBUG_TCH printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]); printf("significand : %16.8e\n",significand); @@ -743,30 +761,38 @@ void BP2_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding - // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) - tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int - // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1) - pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+2]; // Affect an uint16_t pointer with the - // adress where the 16-bit word result will be stored - *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the - // left place of the significand bits (nbitsig), making - // the 16-bit word to be recorded, and record it using the pointer + // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) + exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just + // the first nbitexp bits are used (0, ..., 2^nbitexp-1) + tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the + // left place of the significand bits (nbitsig), + // making the 16-bit word to be recorded + pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16 +#ifdef LSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[0]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[1]; // Record MSB of tmp_uint16 +#endif +#ifdef MSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[1]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[0]; // Record MSB of tmp_uint16 +#endif #ifdef DEBUG_TCH - printf("autocor for S22 significand : %d\n",autocor ); - printf("tmp_uint8 for S22 exponent : %d\n",tmp_uint16 ); - printf("*pt_u_short_int for S22 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int); - printf("lfr_bp2[i*NB_BYTES_BP2+3] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]); - printf("lfr_bp2[i*NB_BYTES_BP2+2] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]); + printf("autocor for S22 significand : %u\n",autocor); + printf("exp for S11 exponent : %u\n",exp); + printf("pt_uint8[1] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]); + printf("pt_uint8[0] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]); + printf("lfr_bp2[i*NB_BYTES_BP2+3] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]); + printf("lfr_bp2[i*NB_BYTES_BP2+2] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]); #endif // S33 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1 - // S33 = significand * 2^exponent + // S33 = significand * 2^exponent #ifdef DEBUG_TCH printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]); printf("significand : %16.8e\n",significand); @@ -780,30 +806,38 @@ void BP2_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding - // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) - tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int - // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1) - pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+4]; // Affect an uint16_t pointer with the - // adress where the 16-bit word result will be stored - *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the - // left place of the significand bits (nbitsig), making - // the 16-bit word to be recorded, and record it using the pointer + // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) + exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just + // the first nbitexp bits are used (0, ..., 2^nbitexp-1) + tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the + // left place of the significand bits (nbitsig), + // making the 16-bit word to be recorded + pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16 +#ifdef LSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[0]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[1]; // Record MSB of tmp_uint16 +#endif +#ifdef MSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[1]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[0]; // Record MSB of tmp_uint16 +#endif #ifdef DEBUG_TCH - printf("autocor for S33 significand : %d\n",autocor ); - printf("tmp_uint8 for S33 exponent : %d\n",tmp_uint16 ); - printf("*pt_u_short_int for S33 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int); - printf("lfr_bp2[i*NB_BYTES_BP2+5] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]); - printf("lfr_bp2[i*NB_BYTES_BP2+4] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]); + printf("autocor for S33 significand : %u\n",autocor); + printf("exp for S33 exponent : %u\n",exp); + printf("pt_uint8[1] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]); + printf("pt_uint8[0] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]); + printf("lfr_bp2[i*NB_BYTES_BP2+5] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]); + printf("lfr_bp2[i*NB_BYTES_BP2+4] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]); #endif // S44 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1 - // S44 = significand * 2^exponent + // S44 = significand * 2^exponent #ifdef DEBUG_TCH printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); printf("significand : %16.8e\n",significand); @@ -818,30 +852,38 @@ void BP2_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding - // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) - tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int - // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1) - pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+6]; // Affect an uint16_t pointer with the - // adress where the 16-bit word result will be stored - *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the - // left place of the significand bits (nbitsig), making - // the 16-bit word to be recorded, and record it using the pointer + // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) + exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just + // the first nbitexp bits are used (0, ..., 2^nbitexp-1) + tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the + // left place of the significand bits (nbitsig), + // making the 16-bit word to be recorded + pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16 +#ifdef LSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[0]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[1]; // Record MSB of tmp_uint16 +#endif +#ifdef MSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[1]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[0]; // Record MSB of tmp_uint16 +#endif #ifdef DEBUG_TCH - printf("autocor for S44 significand : %d\n",autocor ); - printf("tmp_uint8 for S44 exponent : %d\n",tmp_uint16 ); - printf("*pt_u_short_int for S44 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int); - printf("lfr_bp2[i*NB_BYTES_BP2+7] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]); - printf("lfr_bp2[i*NB_BYTES_BP2+6] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]); + printf("autocor for S44 significand : %u\n",autocor); + printf("exp for S44 exponent : %u\n",exp); + printf("pt_uint8[1] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]); + printf("pt_uint8[0] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]); + printf("lfr_bp2[i*NB_BYTES_BP2+7] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]); + printf("lfr_bp2[i*NB_BYTES_BP2+6] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]); #endif // S55 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1 - // S55 = significand * 2^exponent + // S55 = significand * 2^exponent #ifdef DEBUG_TCH printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); printf("significand : %16.8e\n",significand); @@ -855,26 +897,34 @@ void BP2_set( float * compressed_spec_ma exponent = expmax; significand = 1.0; // max value that can be recorded } - if (significand == 0) {// in that case exponent == 0 too + if (significand == 0) { // in that case exponent == 0 too exponent = expmin; - significand = 0.5; // min value that can be recorded + significand = 0.5; // min value that can be recorded } autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding - // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) - tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int - // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1) - pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+8]; // Affect an uint16_t pointer with the - // adress where the 16-bit word result will be stored - *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the - // left place of the significand bits (nbitsig), making - // the 16-bit word to be recorded, and record it using the pointer + // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1) + exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just + // the first nbitexp bits are used (0, ..., 2^nbitexp-1) + tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the + // left place of the significand bits (nbitsig), + // making the 16-bit word to be recorded + pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16 +#ifdef LSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[0]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[1]; // Record MSB of tmp_uint16 +#endif +#ifdef MSB_FIRST_TCH + lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[1]; // Record LSB of tmp_uint16 + lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[0]; // Record MSB of tmp_uint16 +#endif #ifdef DEBUG_TCH - printf("autocor for S55 significand : %d\n",autocor ); - printf("tmp_uint8 for S55 exponent : %d\n",tmp_uint16 ); - printf("*pt_u_short_int for S55 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int); - printf("lfr_bp2[i*NB_BYTES_BP2+9] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]); - printf("lfr_bp2[i*NB_BYTES_BP2+8] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]); + printf("autocor for S55 significand : %u\n",autocor); + printf("exp for S55 exponent : %u\n",exp); + printf("pt_uint8[1] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]); + printf("pt_uint8[0] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]); + printf("lfr_bp2[i*NB_BYTES_BP2+9] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]); + printf("lfr_bp2[i*NB_BYTES_BP2+8] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]); #endif } } diff --git a/basic_parameters.h b/basic_parameters.h --- a/basic_parameters.h +++ b/basic_parameters.h @@ -2,12 +2,13 @@ // version 1.0: 31/07/2013 // version 1.1: 02/04/2014 // version 1.2: 30/04/2014 +// version 1.3: 02/05/2014 #ifndef BASIC_PARAMETERS_H_INCLUDED #define BASIC_PARAMETERS_H_INCLUDED #define NB_VALUES_PER_SPECTRAL_MATRIX 25 -#define NB_BINS_COMPRESSED_MATRIX_f0 1 +#define NB_BINS_COMPRESSED_MATRIX_f0 11 #define NB_BYTES_BP1 9 #define NB_BYTES_BP2 30 diff --git a/file_utilities.c b/file_utilities.c --- a/file_utilities.c +++ b/file_utilities.c @@ -2,6 +2,7 @@ // version 1.0: 31/07/2013 // version 1.1: 02/04/2014 // version 1.2: 30/04/2014 +// version 1.3: 02/05/2014 #include @@ -17,10 +18,11 @@ int lecture_file_sm(const char *fileName } (void) fread(compressed_spectral_matrix_f0, sizeof(compressed_spectral_matrix_f0), 1, infile); (void) fclose(infile); - printf("size of compressed_spectral_matrix_f0 : %lu\n", sizeof(compressed_spectral_matrix_f0)); - printf("Number of bins: %d\n\n", NB_BINS_COMPRESSED_MATRIX_f0); - printf("compressed_spectral_matrix_f0 : \n"); + printf("Compressed_spectral_matrix_f0 : \n"); + printf("Number of bins: %d\n", NB_BINS_COMPRESSED_MATRIX_f0); + printf("Number of values per spectral matrix: %d\n", NB_VALUES_PER_SPECTRAL_MATRIX); + printf("Size of compressed_spectral_matrix_f0 : %lu\n", sizeof(compressed_spectral_matrix_f0)); for(i=0; i #include