Exemple #1
0
unsigned FLAC__fixed_compute_best_predictor( const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1] ) {
	
	hooFileLog( "FLAC__fixed_compute_best_predictor( %i, %f )\n", data_len, residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1] );
	
    static int printLimit = 0;
    
	FLAC__int32 last_error_0 = data[-1];
	FLAC__int32 last_error_1 = data[-1] - data[-2];
	FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
	FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
	FLAC__int32 error, save;
	FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
	unsigned i, order;

	for( i=0; i<data_len; i++ )
    {
		error  = data[i]     ; total_error_0 += local_abs(error);                      save = error;
		error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
		error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
		error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
		error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
	}

	if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
		order = 0;
	else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
		order = 1;
	else if(total_error_2 < min(total_error_3, total_error_4))
		order = 2;
	else if(total_error_3 < total_error_4)
		order = 3;
	else
		order = 4;

	/* Estimate the expected number of bits per residual signal sample. */
	/* 'total_error*' is linearly related to the variance of the residual */
	/* signal, so we use it directly to compute E(|x|) */
	FLAC__ASSERT( data_len > 0 || total_error_0 == 0);
	FLAC__ASSERT( data_len > 0 || total_error_1 == 0);
	FLAC__ASSERT( data_len > 0 || total_error_2 == 0);
	FLAC__ASSERT( data_len > 0 || total_error_3 == 0);
	FLAC__ASSERT( data_len > 0 || total_error_4 == 0);

    /* HOOLEYISM - VERY TEMP! DISCARD FLOATING POINT STUFF - DAMNIT - STILL DIFFERENT VALUES! */        

	residual_bits_per_sample[0] = (int)(FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
	residual_bits_per_sample[1] = (int)(FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
	residual_bits_per_sample[2] = (int)(FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
	residual_bits_per_sample[3] = (int)(FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
	residual_bits_per_sample[4] = (int)(FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);

    //FAIL
    //FAILif( printLimit<20 ) {
    hooFileLog( "residual_bits_per_sample = %f %f %f %f %f \n", residual_bits_per_sample[0], residual_bits_per_sample[1], residual_bits_per_sample[2], residual_bits_per_sample[3], residual_bits_per_sample[4] );
   //FAIL     printLimit++;
   //FAIL }  
	return order;
}
Exemple #2
0
void FLAC__fixed_compute_residual( const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]) {
	
	hooFileLog( "FLAC__fixed_compute_residual( %i )\n", data_len );
	
	const int idata_len = (int)data_len;
	int i;
    
    static int printLimit = 0;
	switch(order) {
		case 0:
			FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
			memcpy(residual, data, sizeof(residual[0])*data_len);
			break;
            
		case 1:
			for( i=0; i<idata_len; i++)
            {
				residual[i] = data[i] - data[i-1];
                hooFileLog( "CASE 1 residual[%i] = %i \n", i, residual[i] );
            }
			break;
            
		case 2:
			for(i = 0; i < idata_len; i++) {
                int var1 = data[i];
                int var2 = (data[i-1] << 1);
                int var3 = data[i-2];
				residual[i] = var1 - var2 + var3;
                hooFileLog( "CASE 2: residual[%i]=%i ( %i, %i, %i) \n", i, residual[i], var1, var2, var3 );                                
            }
			break;
            
		case 3:
			for(i = 0; i < idata_len; i++){
				residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
                hooFileLog( "CASE 3: residual[%i] = %i \n", i, residual[i] );                                
            }
			break;
        
		case 4:
			for(i = 0; i < idata_len; i++) {
				residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
                hooFileLog( "CASE 4: residual[%i] = %i \n", i, residual[i] );                                
            }
			break;
            
		default:
			FLAC__ASSERT(0);
	}
}
Exemple #3
0
FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
{
    hooFileLog( "FLAC__memory_alloc_aligned_uint64_array()\n", NULL );

    FLAC__uint64 *pu; /* unaligned pointer */
    union { /* union needed to comply with C99 pointer aliasing rules */
        FLAC__uint64 *pa; /* aligned pointer */
        void         *pv; /* aligned pointer alias */
    } u;

    FLAC__ASSERT(elements > 0);
    FLAC__ASSERT(0 != unaligned_pointer);
    FLAC__ASSERT(0 != aligned_pointer);
    FLAC__ASSERT(unaligned_pointer != aligned_pointer);

    if((size_t)elements > SIZE_MAX / sizeof(*pu)) /* overflow check */
        return false;

    pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
    if(0 == pu) {
        return false;
    }
    else {
        if(*unaligned_pointer != 0)
            free(*unaligned_pointer);
        *unaligned_pointer = pu;
        *aligned_pointer = u.pa;
        return true;
    }
}
Exemple #4
0
/* An example of what FLAC__bitmath_ilog2() computes:
 *
 * ilog2( 0) = assertion failure
 * ilog2( 1) = 0
 * ilog2( 2) = 1
 * ilog2( 3) = 1
 * ilog2( 4) = 2
 * ilog2( 5) = 2
 * ilog2( 6) = 2
 * ilog2( 7) = 2
 * ilog2( 8) = 3
 * ilog2( 9) = 3
 * ilog2(10) = 3
 * ilog2(11) = 3
 * ilog2(12) = 3
 * ilog2(13) = 3
 * ilog2(14) = 3
 * ilog2(15) = 3
 * ilog2(16) = 4
 * ilog2(17) = 4
 * ilog2(18) = 4
 */
unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
{    
	unsigned l = 0;
    FLAC__ASSERT(v > 0);
	while(v >>= 1)
		l++;
    hooFileLog( "FLAC__bitmath_ilog2( %i %i )\n", v, l );

	return l;
}
Exemple #5
0
void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
{
    hooFileLog( "FLAC__memory_alloc_aligned()\n", NULL );

    void *x;

    FLAC__ASSERT(0 != aligned_address);


    /* align on 32-byte (256-bit) boundary */
    x = safe_malloc_add_2op_(bytes, /*+*/31);


    *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));


    return x;
}