int main(int argc,char **argv){ unsigned int i; printf("please enter an i\n"); scanf("%u",&i); printf("%u\n",(unsigned int)log2f((float)i)); }
/** * two-loop quantizers search taken from ISO 13818-7 Appendix C */ static void search_for_quantizers_twoloop(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) { int start = 0, i, w, w2, g; int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels; float dists[128], uplims[128]; float maxvals[128]; int fflag, minscaler; int its = 0; int allz = 0; float minthr = INFINITY; //XXX: some heuristic to determine initial quantizers will reduce search time memset(dists, 0, sizeof(dists)); //determine zero bands and upper limits for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { for (g = 0; g < sce->ics.num_swb; g++) { int nz = 0; float uplim = 0.0f; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; uplim += band->threshold; if (band->energy <= band->threshold || band->threshold == 0.0f) { sce->zeroes[(w+w2)*16+g] = 1; continue; } nz = 1; } uplims[w*16+g] = uplim *512; sce->zeroes[w*16+g] = !nz; if (nz) minthr = FFMIN(minthr, uplim); allz = FFMAX(allz, nz); } } for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { for (g = 0; g < sce->ics.num_swb; g++) { if (sce->zeroes[w*16+g]) { sce->sf_idx[w*16+g] = SCALE_ONE_POS; continue; } sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59); } } if (!allz) return; abs_pow34_v(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { const float *scaled = s->scoefs + start; maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled); start += sce->ics.swb_sizes[g]; } } //perform two-loop search //outer loop - improve quality do { int tbits, qstep; minscaler = sce->sf_idx[0]; //inner loop - quantize spectrum to fit into given number of bits qstep = its ? 1 : 32; do { int prev = -1; tbits = 0; fflag = 0; for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { const float *coefs = sce->coeffs + start; const float *scaled = s->scoefs + start; int bits = 0; int cb; float dist = 0.0f; if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) { start += sce->ics.swb_sizes[g]; continue; } minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]); cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { int b; dist += quantize_band_cost(s, coefs + w2*128, scaled + w2*128, sce->ics.swb_sizes[g], sce->sf_idx[w*16+g], cb, 1.0f, INFINITY, &b); bits += b; } dists[w*16+g] = dist - bits; if (prev != -1) { bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO]; } tbits += bits; start += sce->ics.swb_sizes[g]; prev = sce->sf_idx[w*16+g]; } } if (tbits > destbits) { for (i = 0; i < 128; i++) if (sce->sf_idx[i] < 218 - qstep) sce->sf_idx[i] += qstep; } else { for (i = 0; i < 128; i++) if (sce->sf_idx[i] > 60 - qstep) sce->sf_idx[i] -= qstep; } qstep >>= 1; if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217) qstep = 1; } while (qstep); fflag = 0; minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { for (g = 0; g < sce->ics.num_swb; g++) { int prevsc = sce->sf_idx[w*16+g]; if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) { if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1)) sce->sf_idx[w*16+g]--; else //Try to make sure there is some energy in every band sce->sf_idx[w*16+g]-=2; } sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF); sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219); if (sce->sf_idx[w*16+g] != prevsc) fflag = 1; sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); } } its++; } while (fflag && its < 10); }
static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) { int i, w, w2, g; int minq = 255; memset(sce->sf_idx, 0, sizeof(sce->sf_idx)); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { for (g = 0; g < sce->ics.num_swb; g++) { for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; if (band->energy <= band->threshold) { sce->sf_idx[(w+w2)*16+g] = 218; sce->zeroes[(w+w2)*16+g] = 1; } else { sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2f(band->threshold), 80, 218); sce->zeroes[(w+w2)*16+g] = 0; } minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]); } } } for (i = 0; i < 128; i++) { sce->sf_idx[i] = 140; //av_clip(sce->sf_idx[i], minq, minq + SCALE_MAX_DIFF - 1); } //set the same quantizers inside window groups for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) for (g = 0; g < sce->ics.num_swb; g++) for (w2 = 1; w2 < sce->ics.group_len[w]; w2++) sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g]; }
void dicho_tree_notrecursive(node_t *head, const int size, item_t *items){ int p_size = 1, pnext_size = 2; node_t *p = head, *pnext, *t1, *t2; int *sizes = (int*)malloc(2*sizeof(int)), // size of accordingly subtree items *indexes = sizes + 1, // start index of items that belongs to accordingly subtree *tmpsizes, *tmpindexes, *ss, *ii, *ss2, *ii2; *sizes = size; *indexes = 0; // creating a maximum symmetric tree int dp = (int)log2f ((float)size); // tree's depth int i; for ( i = 0 ; i < dp ; i++ ){ //1: pnext = (node_t*)calloc (pnext_size, NODE_SIZE); // the next level of tree pnext = p + p_size; // the next level of tree ss = (int*)malloc (2*pnext_size*sizeof(int)); ii = ss + pnext_size; t2 = pnext; ss2 = ss; ii2 = ii; tmpsizes = sizes; // for free() //tmpindexes = indexes; // for free() int j = 0, d; for( t1 = p ; t1 < p + p_size ; t1++ ){ d = (*sizes) / 2; *ss2 = d; *(ss2+1) = (*sizes) - d; ss2 = ss2 + 2; *ii2 = (*indexes); *(ii2+1) = (*indexes) + d; ii2 = ii2 + 2; sizes++; indexes++; t1->lnode = t2; t2->hnode = t1; t2++; t1->rnode = t2; t2->hnode = t1; t2++; j++; } sizes = ss; indexes = ii; free (tmpsizes); //free(tmpindexes); commented because ss = malloc; ii = ss + ... p = pnext; p_size = pnext_size; pnext_size <<= 1; } // for i // hang up all remaining items (where sizes[i]==2) //t2 = p; item_t *tmp; pnext = p + p_size; for( i = 0 ; i < p_size ; i++ ){ if( sizes[i] > 2 ) { printf("size of leaf more than 2\n"); fflush(stdout); } if( sizes[i] == 2 ){ //1: pnext = (node_t*)calloc (2,NODE_SIZE); pnext->items = NULL; tmp = copyitem (&items[indexes[i]]); HASH_ADD_KEYPTR (hh, pnext->items, tmp->w, KNINT_SIZE, tmp); pnext->length = 1; p->lnode = pnext; pnext->hnode = p; pnext++; pnext->items = NULL; tmp = copyitem (&items[indexes[i]+1]); HASH_ADD_KEYPTR (hh, pnext->items, tmp->w, KNINT_SIZE, tmp); pnext->length = 1; p->rnode = pnext; pnext->hnode = p; pnext++; } else if( sizes[i] == 1 ){ p->items = NULL; tmp = copyitem (&items[indexes[i]]); HASH_ADD_KEYPTR (hh, p->items, tmp->w, KNINT_SIZE, tmp); p->length = 1; } else { // error printf("size of leaf is non-positive?\n"); fflush(stdout); } p++; } }// dicho_tree_notrecursive()
TEST(math, log2f) { ASSERT_FLOAT_EQ(12.0f, log2f(4096.0f)); }
void drawPitchLocation() { float cols = PitchHandler_getColCount(phctx); float dx = 0.0125; float rows = PitchHandler_getRowCount(phctx); float dy = 1.0 / rows; VertexObjectBuilder_startColoredObject(voCtxDynamic, GRAPHICS_TRIANGLES); for(int f=0; f<FINGERMAX; f++) { struct FingerInfo* fInfo = PitchHandler_fingerState(phctx,f); if(fInfo->isActive) { VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, fInfo->pitchY ,0, 0,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX-dx, fInfo->pitchY ,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX , fInfo->pitchY-dy,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, fInfo->pitchY ,0, 0,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX , fInfo->pitchY+dy,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX+dx, fInfo->pitchY ,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, fInfo->pitchY ,0, 0,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX , fInfo->pitchY+dy,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX-dx, fInfo->pitchY ,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, fInfo->pitchY ,0, 0,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX+dx, fInfo->pitchY ,0,127,255,127, 0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX , fInfo->pitchY-dy,0,127,255,127, 0); } } VertexObjectBuilder_startColoredObject(voCtxDynamic, GRAPHICS_LINES); for(int f=0; f<FINGERMAX; f++) { struct FingerInfo* fInfo = PitchHandler_fingerState(phctx,f); if(fInfo->isActive) { //TODO: this is ONLY right for uniform tunings float y = ((int)(rows*fInfo->pitchY) + 0.5)/rows; float dy = 1.0/rows; float detune; float detune2; if(PitchHandler_getRowCount(phctx)>1.5) { detune = PitchHandler_getStrDetune(phctx,(int)(fInfo->pitchY*rows)); float dx3 = (12*log2f(3.0/2) - detune)/cols; float dx4 = (12*log2f(4.0/3) - detune)/cols; float dx5 = (12*log2f(5.0/4) - detune)/cols; float dx6 = (12*log2f(6.0/5) - detune)/cols; VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 0,0, 255,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX+0.75*dx3, y+0.75*dy,0, 0,0, 255,0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 0,0,255,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX+dx4, y+dy,0, 0,0,255,0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 0,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX+0.75*dx5, y+0.75*dy,0, 0,255, 0,0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 50,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX+0.75*dx6, y+0.75*dy,0, 50,255, 0,0); int bottomRow = ((fInfo->pitchY*rows)>0)==0; detune2 = PitchHandler_getStrDetune(phctx,bottomRow + (int)(fInfo->pitchY*rows - 1)); float dx32 = (12*log2f(3.0/2) - detune2)/cols; float dx42 = (12*log2f(4.0/3) - detune2)/cols; float dx52 = (12*log2f(5.0/4) - detune2)/cols; float dx62 = (12*log2f(6.0/5) - detune2)/cols; VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 0,0, 255,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX-0.75*dx32, y-0.75*dy,0, 0,0, 255,0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 0,0, 255,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX-dx42, y-dy,0, 0,0,255,0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 0,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX-0.75*dx52, y-0.75*dy,0, 0,255, 0,0); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX, y,0, 50,255, 0,255); VertexObjectBuilder_addColoredVertex(voCtxDynamic,fInfo->pitchX-0.75*dx62, y-0.75*dy,0, 50,255, 0,0); } } } }
ir_constant* ir_expression::constant_expression_value() { if (this->type->is_error()) { return NULL; } ir_constant* op[Elements(this->operands)] = { NULL, }; ir_constant_data data; memset(&data, 0, sizeof(data)); for (unsigned operand = 0; operand < this->get_num_operands(); operand++) { op[operand] = this->operands[operand]->constant_expression_value(); if (!op[operand]) { return NULL; } } check(op[0]); if (op[1] != NULL) { check(op[0]->type->base_type == op[1]->type->base_type || this->operation == ir_binop_lshift || this->operation == ir_binop_rshift); } bool op0_scalar = op[0]->type->is_scalar(); bool op1_scalar = op[1] != NULL && op[1]->type->is_scalar(); bool op2_scalar = op[2] ? op[2]->type->is_scalar() : false; unsigned c2_inc = op2_scalar ? 0 : 1; /* When iterating over a vector or matrix's components, we want to increase * the loop counter. However, for scalars, we want to stay at 0. */ unsigned c0_inc = op0_scalar ? 0 : 1; unsigned c1_inc = op1_scalar ? 0 : 1; unsigned components; if (op1_scalar || !op[1]) { components = op[0]->type->components(); } else { components = op[1]->type->components(); } void *ctx = ralloc_parent(this); /* Handle array operations here, rather than below. */ if (op[0]->type->is_array()) { check(op[1] != NULL && op[1]->type->is_array()); switch (this->operation) { case ir_binop_all_equal: return new(ctx)ir_constant(op[0]->has_value(op[1])); case ir_binop_any_nequal: return new(ctx)ir_constant(!op[0]->has_value(op[1])); default: break; } return NULL; } switch (this->operation) { case ir_unop_bit_not: switch (op[0]->type->base_type) { case GLSL_TYPE_INT: for (unsigned c = 0; c < components; c++) { data.i[c] = ~op[0]->value.i[c]; } break; case GLSL_TYPE_UINT: for (unsigned c = 0; c < components; c++) { data.u[c] = ~op[0]->value.u[c]; } break; default: check(0); } break; case ir_unop_logic_not: check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = !op[0]->value.b[c]; } break; case ir_unop_h2i: check(op[0]->type->base_type == GLSL_TYPE_HALF); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.i[c] = (int)op[0]->value.f[c]; } break; case ir_unop_f2i: check(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.i[c] = (int)op[0]->value.f[c]; } break; case ir_unop_i2f: case ir_unop_i2h: check(op[0]->type->base_type == GLSL_TYPE_INT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = (float)op[0]->value.i[c]; } break; case ir_unop_u2h: case ir_unop_u2f: check(op[0]->type->base_type == GLSL_TYPE_UINT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = (float)op[0]->value.u[c]; } break; case ir_unop_f2h: check(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = op[0]->value.f[c]; } break; case ir_unop_f2u: check(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.u[c] = (unsigned)op[0]->value.f[c]; } break; case ir_unop_b2h: case ir_unop_b2f: check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = op[0]->value.b[c] ? 1.0F : 0.0F; } break; case ir_unop_h2b: check(op[0]->type->base_type == GLSL_TYPE_HALF); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = op[0]->value.f[c] != 0.0F ? true : false; } break; case ir_unop_f2b: check(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = op[0]->value.f[c] != 0.0F ? true : false; } break; case ir_unop_b2i: check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.u[c] = op[0]->value.b[c] ? 1 : 0; } break; case ir_unop_i2b: check(op[0]->type->is_integer()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = op[0]->value.u[c] ? true : false; } break; case ir_unop_u2i: check(op[0]->type->base_type == GLSL_TYPE_UINT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.i[c] = op[0]->value.u[c]; } break; case ir_unop_i2u: check(op[0]->type->base_type == GLSL_TYPE_INT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.u[c] = op[0]->value.i[c]; } break; case ir_unop_b2u: check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.u[c] = (unsigned)op[0]->value.b[c]; } break; case ir_unop_u2b: check(op[0]->type->base_type == GLSL_TYPE_UINT); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = (bool)op[0]->value.u[c]; } break; case ir_unop_any: check(op[0]->type->is_boolean()); data.b[0] = false; for (unsigned c = 0; c < op[0]->type->components(); c++) { if (op[0]->value.b[c]) { data.b[0] = true; } } break; case ir_unop_all: check(op[0]->type->is_boolean()); data.b[0] = true; for (unsigned c = 0; c < op[0]->type->components(); c++) { if (op[0]->value.b[c] == false) { data.b[0] = false; } } break; case ir_unop_trunc: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = truncf(op[0]->value.f[c]); } break; case ir_unop_round: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = (float)(IROUND(op[0]->value.f[c])); } break; case ir_unop_ceil: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = ceilf(op[0]->value.f[c]); } break; case ir_unop_floor: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = floorf(op[0]->value.f[c]); } break; case ir_unop_fract: for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = 0; break; case GLSL_TYPE_INT: data.i[c] = 0; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]); break; default: check(0); } } break; case ir_unop_sin: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = sinf(op[0]->value.f[c]); } break; case ir_unop_cos: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = cosf(op[0]->value.f[c]); } break; case ir_unop_tan: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = tanf(op[0]->value.f[c]); } break; case ir_unop_asin: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = asinf(op[0]->value.f[c]); } break; case ir_unop_acos: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = acosf(op[0]->value.f[c]); } break; case ir_unop_atan: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = atanf(op[0]->value.f[c]); } break; case ir_unop_sinh: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = sinhf(op[0]->value.f[c]); } break; case ir_unop_cosh: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = coshf(op[0]->value.f[c]); } break; case ir_unop_tanh: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = tanhf(op[0]->value.f[c]); } break; case ir_unop_neg: for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = -((int)op[0]->value.u[c]); break; case GLSL_TYPE_INT: data.i[c] = -op[0]->value.i[c]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = -op[0]->value.f[c]; break; default: check(0); } } break; case ir_unop_abs: for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c]; break; case GLSL_TYPE_INT: data.i[c] = op[0]->value.i[c]; if (data.i[c] < 0) { data.i[c] = -data.i[c]; } break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = fabs(op[0]->value.f[c]); break; default: check(0); } } break; case ir_unop_sign: for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.i[c] > 0; break; case GLSL_TYPE_INT: data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0); break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = float((op[0]->value.f[c] > 0) - (op[0]->value.f[c] < 0)); break; default: check(0); } } break; case ir_unop_rcp: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (this->type->base_type) { case GLSL_TYPE_UINT: if (op[0]->value.u[c] != 0.0) { data.u[c] = 1 / op[0]->value.u[c]; } break; case GLSL_TYPE_INT: if (op[0]->value.i[c] != 0.0) { data.i[c] = 1 / op[0]->value.i[c]; } break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: if (op[0]->value.f[c] != 0.0) { data.f[c] = 1.0F / op[0]->value.f[c]; } break; default: check(0); } } break; case ir_unop_rsq: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]); } break; case ir_unop_sqrt: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = sqrtf(op[0]->value.f[c]); } break; case ir_unop_exp: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = expf(op[0]->value.f[c]); } break; case ir_unop_exp2: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = exp2f(op[0]->value.f[c]); } break; case ir_unop_log: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = logf(op[0]->value.f[c]); } break; case ir_unop_log2: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = log2f(op[0]->value.f[c]); } break; case ir_unop_normalize: check(op[0]->type->is_float()); { float mag = 0.0f; for (unsigned c = 0; c < op[0]->type->components(); c++) { mag += op[0]->value.f[c] * op[0]->value.f[c]; } mag = sqrtf(mag); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = op[0]->value.f[c] / mag; } } break; case ir_unop_dFdx: case ir_unop_dFdy: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = 0.0; } break; case ir_binop_pow: check(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]); } break; case ir_binop_atan2: check(op[0]->type->is_float()); check(op[1] && op[1]->type->base_type == op[0]->type->base_type); for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = atan2f(op[0]->value.f[c], op[1]->value.f[c]); } break; case ir_binop_cross: check(op[0]->type == glsl_type::vec3_type || op[0]->type == glsl_type::half3_type); check(op[1] && (op[1]->type == glsl_type::vec3_type || op[1]->type == glsl_type::half3_type)); data.f[0] = (op[0]->value.f[1] * op[1]->value.f[2]) - (op[0]->value.f[2] * op[1]->value.f[1]); data.f[1] = (op[0]->value.f[2] * op[1]->value.f[0]) - (op[0]->value.f[0] * op[1]->value.f[2]); data.f[2] = (op[0]->value.f[0] * op[1]->value.f[1]) - (op[0]->value.f[1] * op[1]->value.f[0]); break; case ir_binop_dot: data.f[0] = dot(op[0], op[1]); break; case ir_binop_min: check(op[1]); check(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = MIN2(op[0]->value.u[c0], op[1]->value.u[c1]); break; case GLSL_TYPE_INT: data.i[c] = MIN2(op[0]->value.i[c0], op[1]->value.i[c1]); break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]); break; default: check(0); } } break; case ir_binop_max: check(op[1]); check(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = MAX2(op[0]->value.u[c0], op[1]->value.u[c1]); break; case GLSL_TYPE_INT: data.i[c] = MAX2(op[0]->value.i[c0], op[1]->value.i[c1]); break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]); break; default: check(0); } } break; case ir_binop_add: check(op[1]); check(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1]; break; case GLSL_TYPE_INT: data.i[c] = op[0]->value.i[c0] + op[1]->value.i[c1]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1]; break; default: check(0); } } break; case ir_binop_sub: check(op[1]); check(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1]; break; case GLSL_TYPE_INT: data.i[c] = op[0]->value.i[c0] - op[1]->value.i[c1]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]; break; default: check(0); } } break; case ir_binop_mul: /* Check for equal types, or unequal types involving scalars */ check(op[1]); if ((op[0]->type == op[1]->type) || op0_scalar || op1_scalar) { for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1]; break; case GLSL_TYPE_INT: data.i[c] = op[0]->value.i[c0] * op[1]->value.i[c1]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1]; break; default: check(0); } } } break; case ir_binop_div: /* FINISHME: Emit warning when division-by-zero is detected. */ check(op[1]); check(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: if (op[1]->value.u[c1] == 0) { data.u[c] = 0; } else { data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; } break; case GLSL_TYPE_INT: if (op[1]->value.i[c1] == 0) { data.i[c] = 0; } else { data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1]; } break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1]; break; default: check(0); } } break; case ir_binop_mod: /* FINISHME: Emit warning when division-by-zero is detected. */ check(op[1]); check(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: if (op[1]->value.u[c1] == 0) { data.u[c] = 0; } else { data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; } break; case GLSL_TYPE_INT: if (op[1]->value.i[c1] == 0) { data.i[c] = 0; } else { data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1]; } break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: /* We don't use fmod because it rounds toward zero; GLSL specifies * the use of floor. */ data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1] * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]); break; default: check(0); } } break; case ir_binop_logic_and: check(op[1]); check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; break; case ir_binop_logic_xor: check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c]; break; case ir_binop_logic_or: check(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; break; case ir_binop_less: check(op[1]); check(op[0]->type == op[1]->type); for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] < op[1]->value.u[0]; break; case GLSL_TYPE_INT: data.b[0] = op[0]->value.i[0] < op[1]->value.i[0]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.b[0] = op[0]->value.f[0] < op[1]->value.f[0]; break; default: check(0); } } break; case ir_binop_greater: check(op[1]); check(op[0]->type == op[1]->type); for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[c] = op[0]->value.u[c] > op[1]->value.u[c]; break; case GLSL_TYPE_INT: data.b[c] = op[0]->value.i[c] > op[1]->value.i[c]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.b[c] = op[0]->value.f[c] > op[1]->value.f[c]; break; default: check(0); } } break; case ir_binop_lequal: check(op[1]); check(op[0]->type == op[1]->type); for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0]; break; case GLSL_TYPE_INT: data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0]; break; default: check(0); } } break; case ir_binop_gequal: check(op[1]); check(op[0]->type == op[1]->type); for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0]; break; case GLSL_TYPE_INT: data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0]; break; default: check(0); } } break; case ir_binop_equal: check(op[1]); check(op[0]->type == op[1]->type); for (unsigned c = 0; c < components; c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[c] = op[0]->value.u[c] == op[1]->value.u[c]; break; case GLSL_TYPE_INT: data.b[c] = op[0]->value.i[c] == op[1]->value.i[c]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.b[c] = op[0]->value.f[c] == op[1]->value.f[c]; break; case GLSL_TYPE_BOOL: data.b[c] = op[0]->value.b[c] == op[1]->value.b[c]; break; default: check(0); } } break; case ir_binop_nequal: check(op[1]); check(op[0]->type == op[1]->type); for (unsigned c = 0; c < components; c++) { switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[c] = op[0]->value.u[c] != op[1]->value.u[c]; break; case GLSL_TYPE_INT: data.b[c] = op[0]->value.i[c] != op[1]->value.i[c]; break; case GLSL_TYPE_HALF: case GLSL_TYPE_FLOAT: data.b[c] = op[0]->value.f[c] != op[1]->value.f[c]; break; case GLSL_TYPE_BOOL: data.b[c] = op[0]->value.b[c] != op[1]->value.b[c]; break; default: check(0); } } break; case ir_binop_all_equal: check(op[1]); data.b[0] = op[0]->has_value(op[1]); break; case ir_binop_any_nequal: check(op[1]); data.b[0] = !op[0]->has_value(op[1]); break; case ir_binop_lshift: for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { check(op[1]); if (op[0]->type->base_type == GLSL_TYPE_INT && op[1]->type->base_type == GLSL_TYPE_INT) { data.i[c] = op[0]->value.i[c0] << op[1]->value.i[c1]; } else if (op[0]->type->base_type == GLSL_TYPE_INT && op[1]->type->base_type == GLSL_TYPE_UINT) { data.i[c] = op[0]->value.i[c0] << op[1]->value.u[c1]; } else if (op[0]->type->base_type == GLSL_TYPE_UINT && op[1]->type->base_type == GLSL_TYPE_INT) { data.u[c] = op[0]->value.u[c0] << op[1]->value.i[c1]; } else if (op[0]->type->base_type == GLSL_TYPE_UINT && op[1]->type->base_type == GLSL_TYPE_UINT) { data.u[c] = op[0]->value.u[c0] << op[1]->value.u[c1]; } } break; case ir_binop_rshift: for (unsigned c = 0, c0 = 0, c1 = 0; c < components; c0 += c0_inc, c1 += c1_inc, c++) { check(op[1]); if (op[0]->type->base_type == GLSL_TYPE_INT && op[1]->type->base_type == GLSL_TYPE_INT) { data.i[c] = op[0]->value.i[c0] >> op[1]->value.i[c1]; } else if (op[0]->type->base_type == GLSL_TYPE_INT && op[1]->type->base_type == GLSL_TYPE_UINT) { data.i[c] = op[0]->value.i[c0] >> op[1]->value.u[c1]; }
bool RawInput::open (const std::string &name, ImageSpec &newspec, const ImageSpec &config) { int ret; // open the image if ( (ret = m_processor.open_file(name.c_str()) ) != LIBRAW_SUCCESS) { error ("Could not open file \"%s\", %s", name.c_str(), libraw_strerror(ret)); return false; } if ( (ret = m_processor.unpack() ) != LIBRAW_SUCCESS) { error ("Could not unpack \"%s\", %s",name.c_str(), libraw_strerror(ret)); return false; } // Forcing the Libraw to adjust sizes based on the capture device orientation m_processor.adjust_sizes_info_only(); // Set file information m_spec = ImageSpec(m_processor.imgdata.sizes.iwidth, m_processor.imgdata.sizes.iheight, 3, // LibRaw should only give us 3 channels TypeDesc::UINT16); // Output 16 bit images m_processor.imgdata.params.output_bps = 16; // Set the gamma curve to Linear m_spec.attribute("oiio:ColorSpace","Linear"); m_processor.imgdata.params.gamm[0] = 1.0; m_processor.imgdata.params.gamm[1] = 1.0; // Disable exposure correction (unless config "raw:auto_bright" == 1) m_processor.imgdata.params.no_auto_bright = ! config.get_int_attribute("raw:auto_bright", 0); // Use camera white balance if "raw:use_camera_wb" is not 0 m_processor.imgdata.params.use_camera_wb = config.get_int_attribute("raw:use_camera_wb", 1); // Turn off maximum threshold value (unless set to non-zero) m_processor.imgdata.params.adjust_maximum_thr = config.get_float_attribute("raw:adjust_maximum_thr", 0.0f); // Use camera matrix (if config "raw:use_camera_matrix" is not 0) m_processor.imgdata.params.use_camera_matrix = config.get_int_attribute("raw:use_camera_matrix", 0); // Check to see if the user has explicitly set the output colorspace primaries std::string cs = config.get_string_attribute ("raw:ColorSpace", "sRGB"); if (cs.size()) { static const char *colorspaces[] = { "raw", "sRGB", "Adobe", "Wide", "ProPhoto", "XYZ", NULL }; size_t c; for (c=0; c < sizeof(colorspaces) / sizeof(colorspaces[0]); c++) if (cs == colorspaces[c]) break; if (cs == colorspaces[c]) m_processor.imgdata.params.output_color = c; else { error("raw:ColorSpace set to unknown value"); return false; } // Set the attribute in the output spec m_spec.attribute("raw:ColorSpace", cs); } else { // By default we use sRGB primaries for simplicity m_processor.imgdata.params.output_color = 1; m_spec.attribute("raw:ColorSpace", "sRGB"); } // Exposure adjustment float exposure = config.get_float_attribute ("raw:Exposure", -1.0f); if (exposure >= 0.0f) { if (exposure < 0.25f || exposure > 8.0f) { error("raw:Exposure invalid value. range 0.25f - 8.0f"); return false; } m_processor.imgdata.params.exp_correc = 1; // enable exposure correction m_processor.imgdata.params.exp_shift = exposure; // set exposure correction // Set the attribute in the output spec m_spec.attribute ("raw:Exposure", exposure); } // Interpolation quality // note: LibRaw must be compiled with demosaic pack GPL2 to use // demosaic algorithms 5-9. It must be compiled with demosaic pack GPL3 for // algorithm 10. If either of these packs are not includeded, it will silently use option 3 - AHD std::string demosaic = config.get_string_attribute ("raw:Demosaic"); if (demosaic.size()) { static const char *demosaic_algs[] = { "linear", "VNG", "PPG", "AHD", "DCB", "Modified AHD", "AFD", "VCD", "Mixed", "LMMSE", "AMaZE", // Future demosaicing algorithms should go here NULL }; size_t d; for (d=0; d < sizeof(demosaic_algs) / sizeof(demosaic_algs[0]); d++) if (demosaic == demosaic_algs[d]) break; if (demosaic == demosaic_algs[d]) m_processor.imgdata.params.user_qual = d; else if (demosaic == "none") { #ifdef LIBRAW_DECODER_FLATFIELD // See if we can access the Bayer patterned data for this raw file libraw_decoder_info_t decoder_info; m_processor.get_decoder_info(&decoder_info); if (!(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD)) { error("Unable to extract unbayered data from file \"%s\"", name.c_str()); return false; } #endif // User has selected no demosaicing, so no processing needs to be done m_process = false; // The image width and height may be different now, so update with new values // Also we will only be reading back a single, bayered channel m_spec.width = m_processor.imgdata.sizes.raw_width; m_spec.height = m_processor.imgdata.sizes.raw_height; m_spec.nchannels = 1; m_spec.channelnames.clear(); m_spec.channelnames.push_back("R"); // Also, any previously set demosaicing options are void, so remove them m_spec.erase_attribute("oiio:Colorspace", TypeDesc::STRING); m_spec.erase_attribute("raw:Colorspace", TypeDesc::STRING); m_spec.erase_attribute("raw:Exposure", TypeDesc::STRING); } else { error("raw:Demosaic set to unknown value"); return false; } // Set the attribute in the output spec m_spec.attribute("raw:Demosaic", demosaic); } else { m_processor.imgdata.params.user_qual = 3; m_spec.attribute("raw:Demosaic", "AHD"); } // Metadata const libraw_image_sizes_t &sizes (m_processor.imgdata.sizes); m_spec.attribute ("PixelAspectRatio", (float)sizes.pixel_aspect); // FIXME: sizes. top_margin, left_margin, raw_pitch, flip, mask? const libraw_iparams_t &idata (m_processor.imgdata.idata); if (idata.make[0]) m_spec.attribute ("Make", idata.make); if (idata.model[0]) m_spec.attribute ("Model", idata.model); // FIXME: idata. dng_version, is_foveon, colors, filters, cdesc const libraw_colordata_t &color (m_processor.imgdata.color); m_spec.attribute("Exif:Flash", (int) color.flash_used); if (color.model2[0]) m_spec.attribute ("Software", color.model2); // FIXME -- all sorts of things in this struct const libraw_imgother_t &other (m_processor.imgdata.other); m_spec.attribute ("Exif:ISOSpeedRatings", (int) other.iso_speed); m_spec.attribute ("ExposureTime", other.shutter); m_spec.attribute ("Exif:ShutterSpeedValue", -log2f(other.shutter)); m_spec.attribute ("FNumber", other.aperture); m_spec.attribute ("Exif:ApertureValue", 2.0f * log2f(other.aperture)); m_spec.attribute ("Exif:FocalLength", other.focal_len); struct tm * m_tm = localtime(&m_processor.imgdata.other.timestamp); char datetime[20]; strftime (datetime, 20, "%Y-%m-%d %H:%M:%S", m_tm); m_spec.attribute ("DateTime", datetime); // FIXME: other.shot_order // FIXME: other.gpsdata if (other.desc[0]) m_spec.attribute ("ImageDescription", other.desc); if (other.artist[0]) m_spec.attribute ("Artist", other.artist); // FIXME -- thumbnail possibly in m_processor.imgdata.thumbnail read_tiff_metadata (name); // Copy the spec to return to the user newspec = m_spec; return true; }
void alignment(std::vector<cv::Mat> images, std::vector<cv::Point>& out) { int num = images.size(); out.resize(num); int i, j, m, n, x, y; for (m = 0; m < num-1; m++){ long int same_counter, max_same; int shift_xoffset = 0, shift_yoffset = 0, answer = 4; //the initial of answer is 4 IplImage *input, *comparison; IplImage *bitmap, *comparison_bitmap; IplImage *exbitmap, *comparison_exbitmap; IplImage *shifted_bitmap, *shifted_exbitmap ,*tmp; IplImage *grade; memset(offset, 0, 2*sizeof(int)); //input = cvLoadImage(argv[1], CV_LOAD_IMAGE_GRAYSCALE); cv::Mat input_gray; cv::cvtColor(images[0], input_gray, cv::COLOR_BGR2GRAY); IplImage input_inst = input_gray; input = &input_inst; if (!input){ //printf("%s doesn't exist!", argv[n+1]); exit(0); } //comparison = cvLoadImage(argv[m+2], CV_LOAD_IMAGE_GRAYSCALE); cv::Mat comparison_gray; cv::cvtColor(images[m+1], comparison_gray, cv::COLOR_BGR2GRAY); IplImage comparison_inst = comparison_gray; comparison = &comparison_inst; if (!comparison){ //printf("%s doesn't exist!", argv[n+2]); exit(0); } int loop = (int)(log2f(std::min(input->width, input->height))); for (n = 0; n < loop; n++){ //--------------------generate MTB from original input 2 images----------------------- bitmap = cvCreateImage(cvSize(input->width/pow(2, loop-1-n), input->height/pow(2, loop-1-n)), 8, 1); exbitmap = cvCreateImage(cvSize(input->width/pow(2, loop-1-n), input->height/pow(2, loop-1-n)), 8, 1); GenerateMTB(input, bitmap, exbitmap); comparison_bitmap = cvCreateImage(cvSize(comparison->width/pow(2, loop-1-n), comparison->height/pow(2, loop-1-n)), 8, 1); comparison_exbitmap = cvCreateImage(cvSize(comparison->width/pow(2, loop-1-n), comparison->height/pow(2, loop-1-n)), 8, 1); GenerateMTB(comparison, comparison_bitmap, comparison_exbitmap); //--------------------generating over------------------------------------------------- //Use shifted_exbitmap to find the most accurate offset. shifted_bitmap = cvCreateImage(cvSize(comparison->width/pow(2, loop-1-n), comparison->height/pow(2, loop-1-n)), 8, 1); shifted_exbitmap = cvCreateImage(cvSize(comparison->width/pow(2, loop-1-n), comparison->height/pow(2, loop-1-n)), 8, 1); //Use grade to calculate minimum inaccuracy offset. grade = cvCreateImage(cvSize(comparison->width/pow(2, loop-1-n), comparison->height/pow(2, loop-1-n)), 8, 1); max_same = 0; for (x = -1; x <= 1; x++){ for (y = -1; y <= 1; y++){ ShiftBitmap(comparison_bitmap, shifted_bitmap, x+shift_xoffset, y+shift_yoffset); ShiftBitmap(comparison_exbitmap, shifted_exbitmap, x+shift_xoffset, y+shift_yoffset); //XOR bitmap and comparison_bitmap for (i = 0; i < grade->height/1; i++) for (j = 0; j < grade->width/1; j++) grade->imageData[i*grade->widthStep+j] = bitmap->imageData[i*bitmap->widthStep+j] ^ shifted_bitmap->imageData[i*shifted_bitmap->widthStep+j]; //AND with exbitmap (first one) for (i = 0; i < grade->height/1; i++) for (j = 0; j < grade->width/1; j++) grade->imageData[i*grade->widthStep+j] = grade->imageData[i*grade->widthStep+j] & exbitmap->imageData[i*exbitmap->widthStep+j]; //AND with comparison_exbitmap (second one) for (i = 0; i < grade->height/1; i++) for (j = 0; j < grade->width/1; j++) grade->imageData[i*grade->widthStep+j] = grade->imageData[i*grade->widthStep+j] & shifted_exbitmap->imageData[i*shifted_exbitmap->widthStep+j]; //Count how many sames are there same_counter = 0; for (i = 0; i < grade->height/1; i++){ for (j = 0; j < grade->width/1; j++){ if (grade->imageData[i*grade->widthStep+j] == 0) same_counter++; } } //same[3*x+y+4] = same_counter; // (-1, -1)=[0] ... (1, 1)=[8] if (same_counter > max_same){ max_same = same_counter; answer = 3*x+y+4; } } } offset[0] += (answer/3 - 1) * pow(2, 5-n); offset[1] += (answer%3 - 1) * pow(2, 5-n); shift_xoffset += answer/3 - 1; shift_yoffset += answer%3 - 1; shift_xoffset *= 2; shift_yoffset *= 2; //printf("offset is %d %d %d\n", answer, offset[0], offset[1]); } total_offset[0][m] = offset[0]; total_offset[1][m] = offset[1]; } out[0].x = 0, out[0].y = 0; for (i = 0; i < m; i++) { out[i+1].x = total_offset[0][i]; out[i+1].y = total_offset[1][i]; } }
void compute(int dimX, int dimY, int dimZ, int length, REAL_POINTER out1, REAL_POINTER out2) { // Shows an efficient way of tiling the original code. // Define number of tiles based on tile_size. int num_tile = dimY / tile_size; #pragma omp parallel for collapse(3) for (int i = 0; i < dimX; i++) { //!!a Tile loop j. for (int j = 0; j < num_tile; j++) { //!!a Tile loop k. //%% EXERCISE: Correctly put limits for loop k as shown in loop j. for (int k = 0; k < num_tile; k++) { int startj = j * tile_size; int endj = startj + tile_size; int startk = k * tile_size; int endk = startk + tile_size; //!!b Indexing inside a particular j tile. for (int jj = startj; jj < endj; jj++) { //!!b Indexing inside a particular k tile. for (int kk = startk; kk < endk; kk++) { //!!b Notice how the index offset was found in the code shown in folder 0. //%% EXERCISE: Correctly fill in % % based following example in folder 0. int idx = (i * dimY * dimZ + jj * dimZ + kk) * length; REAL_POINTER pout1 = out1 + idx; REAL_POINTER pout2 = out2 + idx; for (int n = 0; n < length; n++) { REAL val1 = log2f(i + n + 2.0); for (int m = 0; m < length; m++) { /* NOTE: For MIC architecture, Intel compiler * understands the importance of aligned memory * access. Therefore, in this case, Intel * compiler will perform loop peeling which * splits the whole loop into three sections. * The middle part will have aligned memory * access, while the first part (PEEL) and the * last part (REMAINDER) may have unaligned * memory accesses. Adding "#pragma vector * aligned" makes the code generation for the * PEEL part unnecessary. */ REAL val2 = log2f(j + m + 2.0); #pragma vector aligned for (int l = 0; l < length - 16; l++) { REAL val3 = log2f(k + l + 2.0); REAL inc = sqrtf(val1 + val2) - sqrtf( val2 + val3); pout1[l] = pout1[l + 16] + inc; pout2[l] = pout2[l] + inc; } } } } } } } } }
static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce) { FFPsyBand *band; int w, g, w2, i; int wlen = 1024 / sce->ics.num_windows; int bandwidth, cutoff; float *PNS = &s->scoefs[0*128], *PNS34 = &s->scoefs[1*128]; float *NOR34 = &s->scoefs[3*128]; uint8_t nextband[128]; const float lambda = s->lambda; const float freq_mult = avctx->sample_rate*0.5f/wlen; const float thr_mult = NOISE_LAMBDA_REPLACE*(100.0f/lambda); const float spread_threshold = FFMIN(0.75f, NOISE_SPREAD_THRESHOLD*FFMAX(0.5f, lambda/100.f)); const float dist_bias = av_clipf(4.f * 120 / lambda, 0.25f, 4.0f); const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f); int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / ((avctx->flags & CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels) * (lambda / 120.f); /** Keep this in sync with twoloop's cutoff selection */ float rate_bandwidth_multiplier = 1.5f; int prev = -1000, prev_sf = -1; int frame_bit_rate = (avctx->flags & CODEC_FLAG_QSCALE) ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024) : (avctx->bit_rate / avctx->channels); frame_bit_rate *= 1.15f; if (avctx->cutoff > 0) { bandwidth = avctx->cutoff; } else { bandwidth = FFMAX(3000, AAC_CUTOFF_FROM_BITRATE(frame_bit_rate, 1, avctx->sample_rate)); } cutoff = bandwidth * 2 * wlen / avctx->sample_rate; memcpy(sce->band_alt, sce->band_type, sizeof(sce->band_type)); ff_init_nextband_map(sce, nextband); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { int wstart = w*128; for (g = 0; g < sce->ics.num_swb; g++) { int noise_sfi; float dist1 = 0.0f, dist2 = 0.0f, noise_amp; float pns_energy = 0.0f, pns_tgt_energy, energy_ratio, dist_thresh; float sfb_energy = 0.0f, threshold = 0.0f, spread = 2.0f; float min_energy = -1.0f, max_energy = 0.0f; const int start = wstart+sce->ics.swb_offset[g]; const float freq = (start-wstart)*freq_mult; const float freq_boost = FFMAX(0.88f*freq/NOISE_LOW_LIMIT, 1.0f); if (freq < NOISE_LOW_LIMIT || (start-wstart) >= cutoff) { if (!sce->zeroes[w*16+g]) prev_sf = sce->sf_idx[w*16+g]; continue; } for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; sfb_energy += band->energy; spread = FFMIN(spread, band->spread); threshold += band->threshold; if (!w2) { min_energy = max_energy = band->energy; } else { min_energy = FFMIN(min_energy, band->energy); max_energy = FFMAX(max_energy, band->energy); } } /* Ramps down at ~8000Hz and loosens the dist threshold */ dist_thresh = av_clipf(2.5f*NOISE_LOW_LIMIT/freq, 0.5f, 2.5f) * dist_bias; /* PNS is acceptable when all of these are true: * 1. high spread energy (noise-like band) * 2. near-threshold energy (high PE means the random nature of PNS content will be noticed) * 3. on short window groups, all windows have similar energy (variations in energy would be destroyed by PNS) * * At this stage, point 2 is relaxed for zeroed bands near the noise threshold (hole avoidance is more important) */ if ((!sce->zeroes[w*16+g] && !ff_sfdelta_can_remove_band(sce, nextband, prev_sf, w*16+g)) || ((sce->zeroes[w*16+g] || !sce->band_alt[w*16+g]) && sfb_energy < threshold*sqrtf(1.0f/freq_boost)) || spread < spread_threshold || (!sce->zeroes[w*16+g] && sce->band_alt[w*16+g] && sfb_energy > threshold*thr_mult*freq_boost) || min_energy < pns_transient_energy_r * max_energy ) { sce->pns_ener[w*16+g] = sfb_energy; if (!sce->zeroes[w*16+g]) prev_sf = sce->sf_idx[w*16+g]; continue; } pns_tgt_energy = sfb_energy*FFMIN(1.0f, spread*spread); noise_sfi = av_clip(roundf(log2f(pns_tgt_energy)*2), -100, 155); /* Quantize */ noise_amp = -ff_aac_pow2sf_tab[noise_sfi + POW_SF2_ZERO]; /* Dequantize */ if (prev != -1000) { int noise_sfdiff = noise_sfi - prev + SCALE_DIFF_ZERO; if (noise_sfdiff < 0 || noise_sfdiff > 2*SCALE_MAX_DIFF) { if (!sce->zeroes[w*16+g]) prev_sf = sce->sf_idx[w*16+g]; continue; } } for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { float band_energy, scale, pns_senergy; const int start_c = (w+w2)*128+sce->ics.swb_offset[g]; band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; for (i = 0; i < sce->ics.swb_sizes[g]; i++) { s->random_state = lcg_random(s->random_state); PNS[i] = s->random_state; } band_energy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]); scale = noise_amp/sqrtf(band_energy); s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]); pns_senergy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]); pns_energy += pns_senergy; s->abs_pow34(NOR34, &sce->coeffs[start_c], sce->ics.swb_sizes[g]); s->abs_pow34(PNS34, PNS, sce->ics.swb_sizes[g]); dist1 += quantize_band_cost(s, &sce->coeffs[start_c], NOR34, sce->ics.swb_sizes[g], sce->sf_idx[(w+w2)*16+g], sce->band_alt[(w+w2)*16+g], lambda/band->threshold, INFINITY, NULL, NULL, 0); /* Estimate rd on average as 5 bits for SF, 4 for the CB, plus spread energy * lambda/thr */ dist2 += band->energy/(band->spread*band->spread)*lambda*dist_thresh/band->threshold; } if (g && sce->band_type[w*16+g-1] == NOISE_BT) { dist2 += 5; } else { dist2 += 9; } energy_ratio = pns_tgt_energy/pns_energy; /* Compensates for quantization error */ sce->pns_ener[w*16+g] = energy_ratio*pns_tgt_energy; if (sce->zeroes[w*16+g] || !sce->band_alt[w*16+g] || (energy_ratio > 0.85f && energy_ratio < 1.25f && dist2 < dist1)) { sce->band_type[w*16+g] = NOISE_BT; sce->zeroes[w*16+g] = 0; prev = noise_sfi; } else { if (!sce->zeroes[w*16+g]) prev_sf = sce->sf_idx[w*16+g]; } } } }
static float bw_to_dial (float v) { if (v < .0625) return 0.f; if (v > 4.0) return 1.f; return log2f (16.f * v) / 6.f; }
template <typename PointFeature> bool pcl::PyramidFeatureHistogram<PointFeature>::initializeHistogram () { // a few consistency checks before starting the computations if (!PCLBase<PointFeature>::initCompute ()) { PCL_ERROR ("[pcl::PyramidFeatureHistogram::initializeHistogram] PCLBase initCompute failed\n"); return false; } if (dimension_range_input_.size () == 0) { PCL_ERROR ("[pcl::PyramidFeatureHistogram::initializeHistogram] Input dimension range was not set\n"); return false; } if (dimension_range_target_.size () == 0) { PCL_ERROR ("[pcl::PyramidFeatureHistogram::initializeHistogram] Target dimension range was not set\n"); return false; } if (dimension_range_input_.size () != dimension_range_target_.size ()) { PCL_ERROR ("[pcl::PyramidFeatureHistogram::initializeHistogram] Input and target dimension ranges do not agree in size: %u vs %u\n", dimension_range_input_.size (), dimension_range_target_.size ()); return false; } nr_dimensions = dimension_range_target_.size (); nr_features = input_->points.size (); float D = 0.0f; for (std::vector<std::pair<float, float> >::iterator range_it = dimension_range_target_.begin (); range_it != dimension_range_target_.end (); ++range_it) { float aux = range_it->first - range_it->second; D += aux * aux; } D = sqrtf (D); nr_levels = static_cast<size_t> (ceilf (log2f (D))); PCL_DEBUG ("[pcl::PyramidFeatureHistogram::initializeHistogram] Pyramid will have %u levels with a hyper-parallelepiped diagonal size of %f\n", nr_levels, D); hist_levels.resize (nr_levels); for (size_t level_i = 0; level_i < nr_levels; ++level_i) { std::vector<size_t> bins_per_dimension (nr_dimensions); std::vector<float> bin_step (nr_dimensions); for (size_t dim_i = 0; dim_i < nr_dimensions; ++dim_i) { bins_per_dimension[dim_i] = static_cast<size_t> (ceilf ((dimension_range_target_[dim_i].second - dimension_range_target_[dim_i].first) / (powf (2.0f, static_cast<float> (level_i)) * sqrtf (static_cast<float> (nr_dimensions))))); bin_step[dim_i] = powf (2.0f, static_cast<float> (level_i)) * sqrtf (static_cast<float> (nr_dimensions)); } hist_levels[level_i] = PyramidFeatureHistogramLevel (bins_per_dimension, bin_step); PCL_DEBUG ("[pcl::PyramidFeatureHistogram::initializeHistogram] Created vector of size %u at level %u\nwith #bins per dimension:", hist_levels.back ().hist.size (), level_i); for (size_t dim_i = 0; dim_i < nr_dimensions; ++dim_i) PCL_DEBUG ("%u ", bins_per_dimension[dim_i]); PCL_DEBUG ("\n"); } return true; }
void GLScope::handleMode() { switch(m_mode) { case ModeIQ: m_displayTrace = &m_rawTrace; m_amp1 = m_amp; m_amp2 = m_amp; m_ofs1 = 0.0; m_ofs2 = 0.0; break; case ModeMagLinPha: { m_mathTrace.resize(m_rawTrace.size()); std::vector<Complex>::iterator dst = m_mathTrace.begin(); for(std::vector<Complex>::const_iterator src = m_rawTrace.begin(); src != m_rawTrace.end(); ++src) *dst++ = Complex(abs(*src), arg(*src) / M_PI); m_displayTrace = &m_mathTrace; m_amp1 = m_amp; m_amp2 = 1.0; m_ofs1 = -1.0 / m_amp1; m_ofs2 = 0.0; break; } case ModeMagdBPha: { m_mathTrace.resize(m_rawTrace.size()); std::vector<Complex>::iterator dst = m_mathTrace.begin(); Real mult = (10.0f / log2f(10.0f)); for(std::vector<Complex>::const_iterator src = m_rawTrace.begin(); src != m_rawTrace.end(); ++src) { Real v = src->real() * src->real() + src->imag() * src->imag(); v = (96.0 + (mult * log2f(v))) / 96.0; *dst++ = Complex(v, arg(*src) / M_PI); } m_displayTrace = &m_mathTrace; m_amp1 = 2.0 * m_amp; m_amp2 = 1.0; m_ofs1 = -1.0 / m_amp1; m_ofs2 = 0.0; break; } case ModeDerived12: { if(m_rawTrace.size() > 3) { m_mathTrace.resize(m_rawTrace.size() - 3); std::vector<Complex>::iterator dst = m_mathTrace.begin(); for(uint i = 3; i < m_rawTrace.size() ; i++) { *dst++ = Complex( abs(m_rawTrace[i] - m_rawTrace[i - 1]), abs(m_rawTrace[i] - m_rawTrace[i - 1]) - abs(m_rawTrace[i - 2] - m_rawTrace[i - 3])); } m_displayTrace = &m_mathTrace; m_amp1 = m_amp; m_amp2 = m_amp; m_ofs1 = -1.0 / m_amp1; m_ofs2 = 0.0; } break; } case ModeCyclostationary: { if(m_rawTrace.size() > 2) { m_mathTrace.resize(m_rawTrace.size() - 2); std::vector<Complex>::iterator dst = m_mathTrace.begin(); for(uint i = 2; i < m_rawTrace.size() ; i++) *dst++ = Complex(abs(m_rawTrace[i] - conj(m_rawTrace[i - 1])), 0); m_displayTrace = &m_mathTrace; m_amp1 = m_amp; m_amp2 = m_amp; m_ofs1 = -1.0 / m_amp1; m_ofs2 = 0.0; } break; } } }
static gboolean spectrogram_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { w_spectrogram_t *w = user_data; GtkAllocation a; gtk_widget_get_allocation (widget, &a); if (!w->samples || a.height < 1) { return FALSE; } int width, height; width = a.width; height = a.height; int ratio = ftoi (FFT_SIZE/(a.height*2)); ratio = CLAMP (ratio,0,1023); if (deadbeef->get_output ()->state () == OUTPUT_STATE_PLAYING) { do_fft (w); float log_scale = (log2f(w->samplerate/2)-log2f(25.))/(a.height); float freq_res = w->samplerate / FFT_SIZE; if (a.height != w->height) { w->height = MIN (a.height, MAX_HEIGHT); for (int i = 0; i < w->height; i++) { w->log_index[i] = ftoi (powf(2.,((float)i) * log_scale + log2f(25.)) / freq_res); if (i > 0 && w->log_index[i-1] == w->log_index [i]) { w->low_res_end = i; } } } } // start drawing if (!w->surf || cairo_image_surface_get_width (w->surf) != a.width || cairo_image_surface_get_height (w->surf) != a.height) { if (w->surf) { cairo_surface_destroy (w->surf); w->surf = NULL; } w->surf = cairo_image_surface_create (CAIRO_FORMAT_RGB24, a.width, a.height); } cairo_surface_flush (w->surf); unsigned char *data = cairo_image_surface_get_data (w->surf); if (!data) { return FALSE; } int stride = cairo_image_surface_get_stride (w->surf); if (deadbeef->get_output ()->state () == OUTPUT_STATE_PLAYING) { for (int i = 0; i < a.height; i++) { // scrolling: move line i 1px to the left memmove (data + (i*stride), data + sizeof (uint32_t) + (i*stride), stride - sizeof (uint32_t)); } for (int i = 0; i < a.height; i++) { float f = 1.0; int index0, index1; int bin0, bin1, bin2; if (CONFIG_LOG_SCALE) { bin0 = w->log_index[CLAMP (i-1,0,height-1)]; bin1 = w->log_index[i]; bin2 = w->log_index[CLAMP (i+1,0,height-1)]; } else { bin0 = (i-1) * ratio; bin1 = i * ratio; bin2 = (i+1) * ratio; } index0 = bin0 + ftoi ((bin1 - bin0)/2.f); if (index0 == bin0) index0 = bin1; index1 = bin1 + ftoi ((bin2 - bin1)/2.f); if (index1 == bin2) index1 = bin1; index0 = CLAMP (index0,0,FFT_SIZE/2-1); index1 = CLAMP (index1,0,FFT_SIZE/2-1); f = spectrogram_get_value (w, index0, index1); float x = 10 * log10f (f); // interpolate if (i <= w->low_res_end && CONFIG_LOG_SCALE) { int j = 0; // find index of next value while (i+j < height && w->log_index[i+j] == w->log_index[i]) { j++; } float v0 = x; float v1 = w->data[w->log_index[i+j]]; if (v1 != 0) { v1 = 10 * log10f (v1); } int k = 0; while ((k+i) >= 0 && w->log_index[k+i] == w->log_index[i]) { j++; k--; } x = linear_interpolate (v0,v1,(1.0/(j-1)) * ((-1 * k) - 1)); } // TODO: get rid of hardcoding x += CONFIG_DB_RANGE - 63; x = CLAMP (x, 0, CONFIG_DB_RANGE); int color_index = GRADIENT_TABLE_SIZE - ftoi (GRADIENT_TABLE_SIZE/(float)CONFIG_DB_RANGE * x); color_index = CLAMP (color_index, 0, GRADIENT_TABLE_SIZE-1); _draw_point (data, stride, width-1, height-1-i, w->colors[color_index]); } } cairo_surface_mark_dirty (w->surf); cairo_save (cr); cairo_set_source_surface (cr, w->surf, 0, 0); cairo_rectangle (cr, 0, 0, a.width, a.height); cairo_fill (cr); cairo_restore (cr); return FALSE; }
bool DataHDDIOTensorQuantized::_readIdsRanksScales( ) { assert( _nodesIds && _ranks && _scales ); const size_t size = _nodesIds->size(); if( _ranks->size() != size || _scales->size() != size ) { LOG_ERROR << "Size of _ranks or _scales is incorect " << std::endl; return false; } memset( &((*_nodesIds)[ 0]), 0, size*sizeof((*_nodesIds)[0])); memset( &((*_ranks)[ 0]), 0, size*sizeof((*_ranks)[ 0])); memset( &((*_scales)[ 0]), 0, size*sizeof((*_scales)[ 0])); std::vector<NodeId> tNodes( size ); std::vector<byte> tRanks( size ); std::vector<float> tScales( size ); memset( &tNodes[ 0], 0, tNodes.size() *sizeof(tNodes[ 0])); memset( &tRanks[ 0], 0, tRanks.size() *sizeof(tRanks[ 0])); memset( &tScales[0], 0, tScales.size()*sizeof(tScales[0])); std::string fName = getRanksFileName(); // Read ranks, build ids std::vector<double> data( size ); const uint32_t bytesToRead = data.size()*sizeof(data[0]); util::InFile inFile; if( !inFile.open( fName, std::ios::binary, true ) || !inFile.read( bytesToRead, bytesToRead, &data[0] )) return false; byte maxRank = 0; for( size_t i = 0; i < data.size(); ++i ) { int32_t rank = static_cast<int32_t>( data[i]+0.5 ); if( rank < 0 || rank > 255 ) { LOG_ERROR << "Incorrect rank? (" << rank << ")" << std::endl; break; } if( rank > 0 ) { tNodes[i] = i+1; tRanks[i] = rank; if( maxRank < rank ) maxRank = rank; } } setMaxRankDim( maxRank ); // Read scales if( !inFile.read( bytesToRead*4, bytesToRead, &data[0] )) return false; for( size_t i = 0; i < data.size(); ++i ) { if( tRanks[i] > 0 ) tScales[i] = log2f( 1.0 + data[i] ) / 127.f; } // Fix wrong order from TENSOR iteration uint32_t side = 1; uint32_t current = 0; uint32_t start = 0; std::cout << "size: " << size << std::endl; for( size_t i = 0; i < size; ++i ) { if( current == side*side*side ) { start = VolumeTreeBase::getChild( start ); side *= 2; current = 0; } Vec3_ui32 p = VolumeTreeBase::getIndexPosition( current++ ); uint32_t pos = start + (p.z*side+p.y)*side+p.x; // std::cout << "i: " << i << " pos: " << pos << " current: " << (current-1) << " side: " << side << std::endl; assert( pos < size ); (*_nodesIds)[i] = tNodes[ pos]; (*_ranks)[ i] = tRanks[ pos]; (*_scales)[ i] = tScales[pos]; } #if 0 // print first elements of rank array for( size_t i = 0; i < 1+8+64; ++i ) { std::cout << "i: " << i << " id: " << (int)nodes[i].id << " rank: " << (int)ranks[i] << " scale: " << scales[i] << std::endl; } #endif return true; }
__host__ void single_precision_math_functions() { int iX; float fX, fY; acosf(1.0f); acoshf(1.0f); asinf(0.0f); asinhf(0.0f); atan2f(0.0f, 1.0f); atanf(0.0f); atanhf(0.0f); cbrtf(0.0f); ceilf(0.0f); copysignf(1.0f, -2.0f); cosf(0.0f); coshf(0.0f); //cospif(0.0f); //cyl_bessel_i0f(0.0f); //cyl_bessel_i1f(0.0f); erfcf(0.0f); //erfcinvf(2.0f); //erfcxf(0.0f); erff(0.0f); //erfinvf(1.0f); exp10f(0.0f); exp2f(0.0f); expf(0.0f); expm1f(0.0f); fabsf(1.0f); fdimf(1.0f, 0.0f); //fdividef(0.0f, 1.0f); floorf(0.0f); fmaf(1.0f, 2.0f, 3.0f); fmaxf(0.0f, 0.0f); fminf(0.0f, 0.0f); fmodf(0.0f, 1.0f); frexpf(0.0f, &iX); hypotf(1.0f, 0.0f); ilogbf(1.0f); isfinite(0.0f); isinf(0.0f); isnan(0.0f); ///j0f(0.0f); ///j1f(0.0f); ///jnf(-1.0f, 1.0f); ldexpf(0.0f, 0); ///lgammaf(1.0f); ///llrintf(0.0f); ///llroundf(0.0f); log10f(1.0f); log1pf(-1.0f); log2f(1.0f); logbf(1.0f); logf(1.0f); ///lrintf(0.0f); ///lroundf(0.0f); modff(0.0f, &fX); ///nanf("1"); nearbyintf(0.0f); //nextafterf(0.0f); //norm3df(1.0f, 0.0f, 0.0f); //norm4df(1.0f, 0.0f, 0.0f, 0.0f); //normcdff(0.0f); //normcdfinvf(1.0f); //fX = 1.0f; normf(1, &fX); powf(1.0f, 0.0f); //rcbrtf(1.0f); remainderf(2.0f, 1.0f); remquof(1.0f, 2.0f, &iX); //rhypotf(0.0f, 1.0f); ///rintf(1.0f); //rnorm3df(0.0f, 0.0f, 1.0f); //rnorm4df(0.0f, 0.0f, 0.0f, 1.0f); //fX = 1.0f; rnormf(1, &fX); roundf(0.0f); //rsqrtf(1.0f); ///scalblnf(0.0f, 1); scalbnf(0.0f, 1); signbit(1.0f); sincosf(0.0f, &fX, &fY); //sincospif(0.0f, &fX, &fY); sinf(0.0f); sinhf(0.0f); //sinpif(0.0f); sqrtf(0.0f); tanf(0.0f); tanhf(0.0f); tgammaf(2.0f); truncf(0.0f); ///y0f(1.0f); ///y1f(1.0f); ///ynf(1, 1.0f); }
bool DataHDDIOTensorQuantized2G::_readIdsRanksScales( ) { assert( _nodesIds && _ranks && _scales ); const size_t size = _nodesIds->size(); if( _ranks->size() != size || _scales->size() != size ) { LOG_ERROR << "Size of _ranks or _scales is incorect " << std::endl; return false; } memset( &((*_nodesIds)[ 0]), 0, size*sizeof((*_nodesIds)[0])); memset( &((*_ranks)[ 0]), 0, size*sizeof((*_ranks)[ 0])); memset( &((*_scales)[ 0]), 0, size*sizeof((*_scales)[ 0])); std::string fName = getRanksFileName(); // Read ranks, build ids std::vector<double> data( size ); const uint32_t bytesToRead = data.size()*sizeof(data[0]); util::InFile inFile; if( !inFile.open( fName, std::ios::binary, true ) || !inFile.read( bytesToRead, bytesToRead, &data[0] )) return false; byte maxRank = 0; uint32_t currentId = 0; for( size_t i = 0; i < data.size(); ++i ) { int32_t rank = static_cast<int32_t>( data[i]+0.5 ); if( rank < 0 || rank > 255 ) { LOG_ERROR << "Incorrect rank? (" << rank << ")" << std::endl; break; } if( rank > 0 ) { currentId++; (*_nodesIds)[i] = currentId; (*_ranks)[ i] = rank; if( maxRank < rank ) maxRank = rank; } } setMaxRankDim( maxRank ); // check that all non zero ranks have the same size for( size_t i = 0; i < size; ++i ) if( (*_ranks)[i] != 0 && (*_ranks)[i] != maxRank ) { LOG_ERROR << "One of the non-zero ranks is not equal to maxRank!" << std::endl; abort(); } // Read scales if( !inFile.read( bytesToRead*4, bytesToRead, &data[0] )) return false; for( size_t i = 0; i < data.size(); ++i ) { if( (*_ranks)[i] > 0 ) (*_scales)[i] = log2f( 1.0 + data[i] ) / 127.f; } #if 0 // print first elements of rank array for( size_t i = 0; i < 1+8+64; ++i ) { std::cout << "i: " << i << " id: " << (int)nodes[i].id << " rank: " << (int)ranks[i] << " scale: " << scales[i] << std::endl; } #endif return true; }
static gboolean gtk_tuner_expose (GtkWidget *widget, GdkEventExpose *event) { static const char* note[12] = {"F#","G ","G#","A ","A#","B ","C ","C#","D ","D#","E ","F "}; static const char* octave[] = {"0","1","2","3","4","5"," "}; GxTuner *tuner = GX_TUNER(widget); cairo_t *cr; double x0 = (widget->allocation.width - 100 * tuner->scale) * 0.5; double y0 = (widget->allocation.height - 90 * tuner->scale) * 0.5; cr = gdk_cairo_create(widget->window); cairo_set_source_surface(cr, tuner->surface_tuner, x0, y0); cairo_scale(cr, tuner->scale, tuner->scale); cairo_paint (cr); float scale = -0.5; if (tuner->freq) { float fvis = 12 * (log2f(tuner->freq/tuner->reference_pitch) + 4) + 3; float fvisr = round(fvis); int vis = fvisr; int indicate_oc = round(fvisr/12); const int octsz = sizeof(octave) / sizeof(octave[0]); if (indicate_oc < 0 || indicate_oc >= octsz) { // just safety, should not happen with current parameters // (pitch tracker output 23 .. 999 Hz) indicate_oc = octsz - 1; } scale = (fvis-vis) / 2; vis = vis % 12; if (vis < 0) { vis += 12; } // display note float pitch_add = fabsf(tuner->reference_pitch - 440.00); cairo_set_source_rgba(cr, fabsf(scale)*2+(pitch_add*0.1), 1-(scale*scale*4+(pitch_add*0.1)), 0.2,1-(fabsf(scale)*2)); cairo_set_font_size(cr, 18.0); cairo_move_to(cr,x0+50 -9 , y0+30 +9 ); cairo_show_text(cr, note[vis]); cairo_set_font_size(cr, 8.0); cairo_move_to(cr,x0+54 , y0+30 +16 ); cairo_show_text(cr, octave[indicate_oc]); } // display frequency char s[10]; snprintf(s, sizeof(s), "%.0f Hz", tuner->freq); cairo_set_source_rgba (cr, 0.8, 0.8, 0.2,0.6); cairo_set_font_size (cr, 8.0); cairo_text_extents_t ex; cairo_text_extents(cr, s, &ex); cairo_move_to (cr, x0+90-ex.width, y0+58); cairo_show_text(cr, s); // indicator (line) cairo_move_to(cr,x0+50, y0+rect_height-5); cairo_set_dash (cr, dash_ind, sizeof(dash_ind)/sizeof(dash_ind[0]), 0); cairo_line_to(cr, (scale*2*rect_width)+x0+50, y0+(scale*scale*30)+2); cairo_set_source_rgb(cr, 0.5, 0.1, 0.1); cairo_stroke(cr); cairo_destroy(cr); return FALSE; }
static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce) { FFPsyBand *band; int w, g, w2, i, start, count = 0; float *PNS = &s->scoefs[0*128], *PNS34 = &s->scoefs[1*128]; float *NOR34 = &s->scoefs[3*128]; const float lambda = s->lambda; const float freq_mult = avctx->sample_rate/(1024.0f/sce->ics.num_windows)/2.0f; const float thr_mult = NOISE_LAMBDA_REPLACE*(100.0f/lambda); const float spread_threshold = NOISE_SPREAD_THRESHOLD*(lambda/100.f); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = 0; for (g = 0; g < sce->ics.num_swb; g++) { int noise_sfi, try_pns = 0; float dist1 = 0.0f, dist2 = 0.0f, noise_amp; float energy = 0.0f, threshold = 0.0f, spread = 0.0f; if (start*freq_mult < NOISE_LOW_LIMIT) { start += sce->ics.swb_sizes[g]; continue; } for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; energy += band->energy; spread += band->spread; threshold += band->threshold; } sce->pns_ener[w*16+g] = energy; if (sce->zeroes[w*16+g]) { try_pns = 1; } else if (energy < threshold) { try_pns = 1; } else if (spread > spread_threshold) { try_pns = 0; } else if (energy < threshold*thr_mult) { try_pns = 1; } if (!try_pns || !energy) { start += sce->ics.swb_sizes[g]; continue; } noise_sfi = av_clip(roundf(log2f(energy)*2), -100, 155); /* Quantize */ noise_amp = -ff_aac_pow2sf_tab[noise_sfi + POW_SF2_ZERO]; /* Dequantize */ for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { float band_energy, scale; band = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g]; for (i = 0; i < sce->ics.swb_sizes[g]; i++) PNS[i] = s->random_state = lcg_random(s->random_state); band_energy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]); scale = noise_amp/sqrtf(band_energy); s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]); abs_pow34_v(NOR34, &sce->coeffs[start+(w+w2)*128], sce->ics.swb_sizes[g]); abs_pow34_v(PNS34, PNS, sce->ics.swb_sizes[g]); dist1 += quantize_band_cost(s, &sce->coeffs[start + (w+w2)*128], NOR34, sce->ics.swb_sizes[g], sce->sf_idx[(w+w2)*16+g], sce->band_alt[(w+w2)*16+g], lambda/band->threshold, INFINITY, NULL, 0); dist2 += quantize_band_cost(s, PNS, PNS34, sce->ics.swb_sizes[g], noise_sfi, NOISE_BT, lambda/band->threshold, INFINITY, NULL, 0); } if (dist2 < dist1) { sce->band_type[w*16+g] = NOISE_BT; sce->zeroes[w*16+g] = 0; if (sce->band_type[w*16+g-1] != NOISE_BT && /* Prevent holes */ sce->band_type[w*16+g-2] == NOISE_BT) { sce->band_type[w*16+g-1] = NOISE_BT; sce->zeroes[w*16+g-1] = 0; } count++; } start += sce->ics.swb_sizes[g]; } } }
/** * two-loop quantizers search taken from ISO 13818-7 Appendix C */ static void search_for_quantizers_twoloop(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) { int start = 0, i, w, w2, g; int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f); const float freq_mult = avctx->sample_rate/(1024.0f/sce->ics.num_windows)/2.0f; float dists[128] = { 0 }, uplims[128] = { 0 }; float maxvals[128]; int noise_sf[128] = { 0 }; int fflag, minscaler, minscaler_n; int its = 0; int allz = 0; float minthr = INFINITY; // for values above this the decoder might end up in an endless loop // due to always having more bits than what can be encoded. destbits = FFMIN(destbits, 5800); //XXX: some heuristic to determine initial quantizers will reduce search time //determine zero bands and upper limits for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = 0; for (g = 0; g < sce->ics.num_swb; g++) { int nz = 0; float uplim = 0.0f, energy = 0.0f; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; uplim += band->threshold; energy += band->energy; if (band->energy <= band->threshold || band->threshold == 0.0f) { sce->zeroes[(w+w2)*16+g] = 1; continue; } nz = 1; } uplims[w*16+g] = uplim *512; if (s->options.pns && start*freq_mult > NOISE_LOW_LIMIT && energy < uplim * 1.2f) { noise_sf[w*16+g] = av_clip(4+FFMIN(log2f(energy)*2,255), -100, 155); sce->band_type[w*16+g] = NOISE_BT; nz= 1; } else { /** Band type will be determined by the twoloop algorithm */ sce->band_type[w*16+g] = 0; } sce->zeroes[w*16+g] = !nz; if (nz) minthr = FFMIN(minthr, uplim); allz |= nz; start += sce->ics.swb_sizes[g]; } } for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { for (g = 0; g < sce->ics.num_swb; g++) { if (sce->zeroes[w*16+g]) { sce->sf_idx[w*16+g] = SCALE_ONE_POS; continue; } sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59); } } if (!allz) return; abs_pow34_v(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { const float *scaled = s->scoefs + start; maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled); start += sce->ics.swb_sizes[g]; } } //perform two-loop search //outer loop - improve quality do { int tbits, qstep; minscaler = sce->sf_idx[0]; minscaler_n = sce->sf_idx[0]; //inner loop - quantize spectrum to fit into given number of bits qstep = its ? 1 : 32; do { int prev = -1; tbits = 0; for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { const float *coefs = sce->coeffs + start; const float *scaled = s->scoefs + start; int bits = 0; int cb; float dist = 0.0f; if (sce->band_type[w*16+g] == NOISE_BT) { minscaler_n = FFMIN(minscaler_n, noise_sf[w*16+g]); start += sce->ics.swb_sizes[g]; continue; } else if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) { start += sce->ics.swb_sizes[g]; continue; } minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]); cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { int b; dist += quantize_band_cost(s, coefs + w2*128, scaled + w2*128, sce->ics.swb_sizes[g], sce->sf_idx[w*16+g], cb, 1.0f, INFINITY, &b); bits += b; } dists[w*16+g] = dist - bits; if (prev != -1) { bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO]; } tbits += bits; start += sce->ics.swb_sizes[g]; prev = sce->sf_idx[w*16+g]; } } if (tbits > destbits) { for (i = 0; i < 128; i++) if (sce->sf_idx[i] < 218 - qstep) sce->sf_idx[i] += qstep; } else { for (i = 0; i < 128; i++) if (sce->sf_idx[i] > 60 - qstep) sce->sf_idx[i] -= qstep; } qstep >>= 1; if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217) qstep = 1; } while (qstep); fflag = 0; minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) for (g = 0; g < sce->ics.num_swb; g++) if (sce->band_type[w*16+g] == NOISE_BT) sce->sf_idx[w*16+g] = av_clip(noise_sf[w*16+g], minscaler_n, minscaler_n + SCALE_MAX_DIFF); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { for (g = 0; g < sce->ics.num_swb; g++) { int prevsc = sce->sf_idx[w*16+g]; if (sce->band_type[w*16+g] == NOISE_BT) continue; if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) { if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1)) sce->sf_idx[w*16+g]--; else //Try to make sure there is some energy in every band sce->sf_idx[w*16+g]-=2; } sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF); sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219); if (sce->sf_idx[w*16+g] != prevsc) fflag = 1; sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); } } its++; } while (fflag && its < 10); }
static int testf(float float_x, long double long_double_x, /*float complex float_complex_x,*/ int int_x, long long_x) { int r = 0; r += acosf(float_x); r += acoshf(float_x); r += asinf(float_x); r += asinhf(float_x); r += atan2f(float_x, float_x); r += atanf(float_x); r += atanhf(float_x); /*r += cargf(float_complex_x); - will fight with complex numbers later */ r += cbrtf(float_x); r += ceilf(float_x); r += copysignf(float_x, float_x); r += cosf(float_x); r += coshf(float_x); r += erfcf(float_x); r += erff(float_x); r += exp2f(float_x); r += expf(float_x); r += expm1f(float_x); r += fabsf(float_x); r += fdimf(float_x, float_x); r += floorf(float_x); r += fmaf(float_x, float_x, float_x); r += fmaxf(float_x, float_x); r += fminf(float_x, float_x); r += fmodf(float_x, float_x); r += frexpf(float_x, &int_x); r += gammaf(float_x); r += hypotf(float_x, float_x); r += ilogbf(float_x); r += ldexpf(float_x, int_x); r += lgammaf(float_x); r += llrintf(float_x); r += llroundf(float_x); r += log10f(float_x); r += log1pf(float_x); r += log2f(float_x); r += logbf(float_x); r += logf(float_x); r += lrintf(float_x); r += lroundf(float_x); r += modff(float_x, &float_x); r += nearbyintf(float_x); r += nexttowardf(float_x, long_double_x); r += powf(float_x, float_x); r += remainderf(float_x, float_x); r += remquof(float_x, float_x, &int_x); r += rintf(float_x); r += roundf(float_x); #ifdef __UCLIBC_SUSV3_LEGACY__ r += scalbf(float_x, float_x); #endif r += scalblnf(float_x, long_x); r += scalbnf(float_x, int_x); r += significandf(float_x); r += sinf(float_x); r += sinhf(float_x); r += sqrtf(float_x); r += tanf(float_x); r += tanhf(float_x); r += tgammaf(float_x); r += truncf(float_x); return r; }
void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ) { int csp = param->i_csp & X264_CSP_MASK; sps->i_id = i_id; sps->i_mb_width = ( param->i_width + 15 ) / 16; sps->i_mb_height= ( param->i_height + 15 ) / 16; sps->i_chroma_format_idc = csp >= X264_CSP_I444 ? CHROMA_444 : csp >= X264_CSP_I422 ? CHROMA_422 : CHROMA_420; sps->b_qpprime_y_zero_transform_bypass = param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant == 0; if( sps->b_qpprime_y_zero_transform_bypass || sps->i_chroma_format_idc == CHROMA_444 ) sps->i_profile_idc = PROFILE_HIGH444_PREDICTIVE; else if( sps->i_chroma_format_idc == CHROMA_422 ) sps->i_profile_idc = PROFILE_HIGH422; else if( BIT_DEPTH > 8 ) sps->i_profile_idc = PROFILE_HIGH10; else if( param->analyse.b_transform_8x8 || param->i_cqm_preset != X264_CQM_FLAT ) sps->i_profile_idc = PROFILE_HIGH; else if( param->b_cabac || param->i_bframe > 0 || param->b_interlaced || param->b_fake_interlaced || param->analyse.i_weighted_pred > 0 ) sps->i_profile_idc = PROFILE_MAIN; else sps->i_profile_idc = PROFILE_BASELINE; sps->b_constraint_set0 = sps->i_profile_idc == PROFILE_BASELINE; /* x264 doesn't support the features that are in Baseline and not in Main, * namely arbitrary_slice_order and slice_groups. */ sps->b_constraint_set1 = sps->i_profile_idc <= PROFILE_MAIN; /* Never set constraint_set2, it is not necessary and not used in real world. */ sps->b_constraint_set2 = 0; sps->b_constraint_set3 = 0; sps->i_level_idc = param->i_level_idc; if( param->i_level_idc == 9 && ( sps->i_profile_idc == PROFILE_BASELINE || sps->i_profile_idc == PROFILE_MAIN ) ) { sps->b_constraint_set3 = 1; /* level 1b with Baseline or Main profile is signalled via constraint_set3 */ sps->i_level_idc = 11; } /* Intra profiles */ if( param->i_keyint_max == 1 && sps->i_profile_idc > PROFILE_HIGH ) sps->b_constraint_set3 = 1; sps->vui.i_num_reorder_frames = param->i_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0; /* extra slot with pyramid so that we don't have to override the * order of forgetting old pictures */ sps->vui.i_max_dec_frame_buffering = sps->i_num_ref_frames = X264_MIN(X264_REF_MAX, X264_MAX4(param->i_frame_reference, 1 + sps->vui.i_num_reorder_frames, param->i_bframe_pyramid ? 4 : 1, param->i_dpb_size)); sps->i_num_ref_frames -= param->i_bframe_pyramid == X264_B_PYRAMID_STRICT; if( param->i_keyint_max == 1 ) { sps->i_num_ref_frames = 0; sps->vui.i_max_dec_frame_buffering = 0; } /* number of refs + current frame */ int max_frame_num = sps->vui.i_max_dec_frame_buffering * (!!param->i_bframe_pyramid+1) + 1; /* Intra refresh cannot write a recovery time greater than max frame num-1 */ if( param->b_intra_refresh ) { int time_to_recovery = X264_MIN( sps->i_mb_width - 1, param->i_keyint_max ) + param->i_bframe - 1; max_frame_num = X264_MAX( max_frame_num, time_to_recovery+1 ); } sps->i_log2_max_frame_num = 4; while( (1 << sps->i_log2_max_frame_num) <= max_frame_num ) sps->i_log2_max_frame_num++; sps->i_poc_type = param->i_bframe || param->b_interlaced || param->i_avcintra_class ? 0 : 2; if( sps->i_poc_type == 0 ) { int max_delta_poc = (param->i_bframe + 2) * (!!param->i_bframe_pyramid + 1) * 2; sps->i_log2_max_poc_lsb = 4; while( (1 << sps->i_log2_max_poc_lsb) <= max_delta_poc * 2 ) sps->i_log2_max_poc_lsb++; } sps->b_vui = 1; sps->b_gaps_in_frame_num_value_allowed = 0; sps->b_frame_mbs_only = !(param->b_interlaced || param->b_fake_interlaced); if( !sps->b_frame_mbs_only ) sps->i_mb_height = ( sps->i_mb_height + 1 ) & ~1; sps->b_mb_adaptive_frame_field = param->b_interlaced; sps->b_direct8x8_inference = 1; sps->crop.i_left = param->crop_rect.i_left; sps->crop.i_top = param->crop_rect.i_top; sps->crop.i_right = param->crop_rect.i_right + sps->i_mb_width*16 - param->i_width; sps->crop.i_bottom = (param->crop_rect.i_bottom + sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only; sps->b_crop = sps->crop.i_left || sps->crop.i_top || sps->crop.i_right || sps->crop.i_bottom; sps->vui.b_aspect_ratio_info_present = 0; if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 ) { sps->vui.b_aspect_ratio_info_present = 1; sps->vui.i_sar_width = param->vui.i_sar_width; sps->vui.i_sar_height= param->vui.i_sar_height; } sps->vui.b_overscan_info_present = param->vui.i_overscan > 0 && param->vui.i_overscan <= 2; if( sps->vui.b_overscan_info_present ) sps->vui.b_overscan_info = ( param->vui.i_overscan == 2 ? 1 : 0 ); sps->vui.b_signal_type_present = 0; sps->vui.i_vidformat = ( param->vui.i_vidformat >= 0 && param->vui.i_vidformat <= 5 ? param->vui.i_vidformat : 5 ); sps->vui.b_fullrange = ( param->vui.b_fullrange >= 0 && param->vui.b_fullrange <= 1 ? param->vui.b_fullrange : ( csp >= X264_CSP_BGR ? 1 : 0 ) ); sps->vui.b_color_description_present = 0; sps->vui.i_colorprim = ( param->vui.i_colorprim >= 0 && param->vui.i_colorprim <= 9 ? param->vui.i_colorprim : 2 ); sps->vui.i_transfer = ( param->vui.i_transfer >= 0 && param->vui.i_transfer <= 15 ? param->vui.i_transfer : 2 ); sps->vui.i_colmatrix = ( param->vui.i_colmatrix >= 0 && param->vui.i_colmatrix <= 10 ? param->vui.i_colmatrix : ( csp >= X264_CSP_BGR ? 0 : 2 ) ); if( sps->vui.i_colorprim != 2 || sps->vui.i_transfer != 2 || sps->vui.i_colmatrix != 2 ) { sps->vui.b_color_description_present = 1; } if( sps->vui.i_vidformat != 5 || sps->vui.b_fullrange || sps->vui.b_color_description_present ) { sps->vui.b_signal_type_present = 1; } /* FIXME: not sufficient for interlaced video */ sps->vui.b_chroma_loc_info_present = param->vui.i_chroma_loc > 0 && param->vui.i_chroma_loc <= 5 && sps->i_chroma_format_idc == CHROMA_420; if( sps->vui.b_chroma_loc_info_present ) { sps->vui.i_chroma_loc_top = param->vui.i_chroma_loc; sps->vui.i_chroma_loc_bottom = param->vui.i_chroma_loc; } sps->vui.b_timing_info_present = param->i_timebase_num > 0 && param->i_timebase_den > 0; if( sps->vui.b_timing_info_present ) { sps->vui.i_num_units_in_tick = param->i_timebase_num; sps->vui.i_time_scale = param->i_timebase_den * 2; sps->vui.b_fixed_frame_rate = !param->b_vfr_input; } sps->vui.b_vcl_hrd_parameters_present = 0; // we don't support VCL HRD sps->vui.b_nal_hrd_parameters_present = !!param->i_nal_hrd; sps->vui.b_pic_struct_present = param->b_pic_struct; // NOTE: HRD related parts of the SPS are initialised in x264_ratecontrol_init_reconfigurable sps->vui.b_bitstream_restriction = param->i_keyint_max > 1; if( sps->vui.b_bitstream_restriction ) { sps->vui.b_motion_vectors_over_pic_boundaries = 1; sps->vui.i_max_bytes_per_pic_denom = 0; sps->vui.i_max_bits_per_mb_denom = 0; sps->vui.i_log2_max_mv_length_horizontal = sps->vui.i_log2_max_mv_length_vertical = (int)log2f( X264_MAX( 1, param->analyse.i_mv_range*4-1 ) ) + 1; } }
organicInstrument::organicInstrument( InstrumentTrack * _instrument_track ) : Instrument( _instrument_track, &organic_plugin_descriptor ), m_modulationAlgo( Oscillator::SignalMix, Oscillator::SignalMix, Oscillator::SignalMix), m_fx1Model( 0.0f, 0.0f, 0.99f, 0.01f , this, tr( "Distortion" ) ), m_volModel( 100.0f, 0.0f, 200.0f, 1.0f, this, tr( "Volume" ) ) { m_numOscillators = 8; m_osc = new OscillatorObject*[ m_numOscillators ]; for (int i=0; i < m_numOscillators; i++) { m_osc[i] = new OscillatorObject( this, i ); m_osc[i]->m_numOscillators = m_numOscillators; // Connect events connect( &m_osc[i]->m_oscModel, SIGNAL( dataChanged() ), m_osc[i], SLOT ( oscButtonChanged() ) ); connect( &m_osc[i]->m_harmModel, SIGNAL( dataChanged() ), m_osc[i], SLOT( updateDetuning() ) ); connect( &m_osc[i]->m_volModel, SIGNAL( dataChanged() ), m_osc[i], SLOT( updateVolume() ) ); connect( &m_osc[i]->m_panModel, SIGNAL( dataChanged() ), m_osc[i], SLOT( updateVolume() ) ); connect( &m_osc[i]->m_detuneModel, SIGNAL( dataChanged() ), m_osc[i], SLOT( updateDetuning() ) ); m_osc[i]->updateVolume(); } /* m_osc[0]->m_harmonic = log2f( 0.5f ); // one octave below m_osc[1]->m_harmonic = log2f( 0.75f ); // a fifth below m_osc[2]->m_harmonic = log2f( 1.0f ); // base freq m_osc[3]->m_harmonic = log2f( 2.0f ); // first overtone m_osc[4]->m_harmonic = log2f( 3.0f ); // second overtone m_osc[5]->m_harmonic = log2f( 4.0f ); // . m_osc[6]->m_harmonic = log2f( 5.0f ); // . m_osc[7]->m_harmonic = log2f( 6.0f ); // .*/ if( s_harmonics == NULL ) { s_harmonics = new float[ NUM_HARMONICS ]; s_harmonics[0] = log2f( 0.5f ); s_harmonics[1] = log2f( 0.75f ); s_harmonics[2] = log2f( 1.0f ); s_harmonics[3] = log2f( 2.0f ); s_harmonics[4] = log2f( 3.0f ); s_harmonics[5] = log2f( 4.0f ); s_harmonics[6] = log2f( 5.0f ); s_harmonics[7] = log2f( 6.0f ); s_harmonics[8] = log2f( 7.0f ); s_harmonics[9] = log2f( 8.0f ); s_harmonics[10] = log2f( 9.0f ); s_harmonics[11] = log2f( 10.0f ); s_harmonics[12] = log2f( 11.0f ); s_harmonics[13] = log2f( 12.0f ); s_harmonics[14] = log2f( 13.0f ); s_harmonics[15] = log2f( 14.0f ); s_harmonics[16] = log2f( 15.0f ); s_harmonics[17] = log2f( 16.0f ); } for (int i=0; i < m_numOscillators; i++) { m_osc[i]->updateVolume(); m_osc[i]->updateDetuning(); } connect( engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( updateAllDetuning() ) ); }
static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) { int q, w, w2, g, start = 0; int i, j; int idx; TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES]; int bandaddr[TRELLIS_STAGES]; int minq; float mincost; float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f; int q0, q1, qcnt = 0; for (i = 0; i < 1024; i++) { float t = fabsf(sce->coeffs[i]); if (t > 0.0f) { q0f = FFMIN(q0f, t); q1f = FFMAX(q1f, t); qnrgf += t*t; qcnt++; } } if (!qcnt) { memset(sce->sf_idx, 0, sizeof(sce->sf_idx)); memset(sce->zeroes, 1, sizeof(sce->zeroes)); return; } //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped q0 = coef2minsf(q0f); //maximum scalefactor index is when maximum coefficient after quantizing is still not zero q1 = coef2maxsf(q1f); //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); if (q1 - q0 > 60) { int q0low = q0; int q1high = q1; //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512); q1 = qnrg + 30; q0 = qnrg - 30; //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); if (q0 < q0low) { q1 += q0low - q0; q0 = q0low; } else if (q1 > q1high) { q0 -= q1 - q1high; q1 = q1high; } } //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); for (i = 0; i < TRELLIS_STATES; i++) { paths[0][i].cost = 0.0f; paths[0][i].prev = -1; } for (j = 1; j < TRELLIS_STAGES; j++) { for (i = 0; i < TRELLIS_STATES; i++) { paths[j][i].cost = INFINITY; paths[j][i].prev = -2; } } idx = 1; abs_pow34_v(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { const float *coefs = sce->coeffs + start; float qmin, qmax; int nz = 0; bandaddr[idx] = w * 16 + g; qmin = INT_MAX; qmax = 0.0f; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; if (band->energy <= band->threshold || band->threshold == 0.0f) { sce->zeroes[(w+w2)*16+g] = 1; continue; } sce->zeroes[(w+w2)*16+g] = 0; nz = 1; for (i = 0; i < sce->ics.swb_sizes[g]; i++) { float t = fabsf(coefs[w2*128+i]); if (t > 0.0f) qmin = FFMIN(qmin, t); qmax = FFMAX(qmax, t); } } if (nz) { int minscale, maxscale; float minrd = INFINITY; float maxval; //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped minscale = coef2minsf(qmin); //maximum scalefactor index is when maximum coefficient after quantizing is still not zero maxscale = coef2maxsf(qmax); minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES); maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start); for (q = minscale; q < maxscale; q++) { float dist = 0; int cb = find_min_book(maxval, sce->sf_idx[w*16+g]); for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g], q + q0, cb, lambda / band->threshold, INFINITY, NULL); } minrd = FFMIN(minrd, dist); for (i = 0; i < q1 - q0; i++) { float cost; cost = paths[idx - 1][i].cost + dist + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; if (cost < paths[idx][q].cost) { paths[idx][q].cost = cost; paths[idx][q].prev = i; } } } } else { for (q = 0; q < q1 - q0; q++) { paths[idx][q].cost = paths[idx - 1][q].cost + 1; paths[idx][q].prev = q; } } sce->zeroes[w*16+g] = !nz; start += sce->ics.swb_sizes[g]; idx++; } } idx--; mincost = paths[idx][0].cost; minq = 0; for (i = 1; i < TRELLIS_STATES; i++) { if (paths[idx][i].cost < mincost) { mincost = paths[idx][i].cost; minq = i; } } while (idx) { sce->sf_idx[bandaddr[idx]] = minq + q0; minq = paths[idx][minq].prev; idx--; } //set the same quantizers inside window groups for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) for (g = 0; g < sce->ics.num_swb; g++) for (w2 = 1; w2 < sce->ics.group_len[w]; w2++) sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g]; }
/*--------------------------------------------------------------------Quick Sort------------------*/ int main() { ItemNode *reclist[232657] = {NULL}; train = fopen(trainData,"r"); ulist = malloc(sizeof(uList)); ulist->counter = 0; ulist->next = NULL; probe_header = malloc(sizeof(uList)); probe_header->counter = 0; probe_header->next = NULL; ilist = malloc(sizeof(ItemList)); ilist->counter = 0; ilist->next = NULL; result = fopen(resultData,"a+"); //初始化用户和商品列表 while(fscanf(train,"%d%d",&CID,&IID) != EOF){ CItem = IListInsert(ilist,IID,&position,reclist); UListInsert(ulist,CID,IID,CItem); counter++; if( counter > 1000000) printf("%d\n",counter); } counter = 0; //printf("R0:%d\tR1:%d\tR2:%d\tR3:%d\n",t[0],t[1],t[2],t[3]); fclose(train); /*----------------------------------------------------------------------------Initial Probe User List-----------*/ probe = fopen(probeData,"r"); while(fscanf(probe,"%d%d",&CID,&IID) != EOF ){ UListInsert(probe_header,CID,IID,NULL); } printf("\ntest\n"); index_position = get_nozero_position(reclist,0,position); printf("fish\n"); quickSort(reclist,0,index_position); //根据商品Degree排名开始形成用户的推荐列 printf("t\n"); //getchar(); printf("FinishRec\n"); printf("TotalUser:%d\tTotalItems:%d\n",ulist->counter,ilist->counter); //对形成的推荐列表进行测试 train_User = ulist->next; while(train_User != NULL){ //printf("User:%d\n",train_User->id); itemlist = train_User->uilist->next; while(itemlist != NULL){ itemlist->self->own = TRUE; itemlist = itemlist->next; } k = 0; recLength = 0; /*--------------------------------------------------------------Initial Top L reclist-----*/ while(recLength < L){ if(reclist[k]->own != TRUE){ RECListInsert(train_User->rlist,reclist[k]->id,reclist[k]->degree); recLength++; } k++; } /*---------------------------------------------------------------End Top L Reclist--------*/ probe_User = probe_header->next; flag = FALSE; while( (probe_User != NULL) && (flag != TRUE) ){ if(probe_User->id == train_User->id){ probe_User->self = train_User; itemlist = probe_User->uilist->next; //RecordCounterProbe += probe_User->uilist->counter; counter++; DIL = 0; while(itemlist != NULL){ length = ilist->counter - train_User->uilist->counter; dou = FALSE; rank = 0; for(k = 0;(k <= position)&&(dou != TRUE) ;k++){ if( reclist[k]->own != TRUE ){ rank++; if(reclist[k]->id == itemlist->id){ RecordCounterProbe++; RS += (rank / length); if( rank <= L)DIL++; dou = TRUE; } } } itemlist = itemlist->next; } EPL = EPL + DIL / L; flag = TRUE; } probe_User = probe_User->next; } /*--------------------------------------------------------------Initial itemlist----------*/ itemlist = train_User->uilist->next; while(itemlist != NULL){ itemlist->self->own = FALSE; itemlist = itemlist->next; } train_User = train_User->next; } RS = RS / RecordCounterProbe; EPL = EPL / counter; EPL = (EPL * ulist->counter / RecordCounterProbe) * ilist->counter; //printf("Test finish\n"); fclose(probe); /*-----------------------------------------------------------------------------------------Diversity Test Begin-----------------*/ probe_User = probe_header->next; uNode *neighbor; counter = 0; RecordCounterProbe = 0; HL = 0; int total = 0; while( probe_User->next != NULL ){ kDegree = 0; IL = 0; if( probe_User->self != NULL ){ RecordCounterProbe++; neighbor = probe_User->next; itemlist = probe_User->self->rlist->next; while( itemlist != NULL){ kDegree = itemlist->degree; IL += log2f( ( ulist->counter / kDegree) ); itemlist = itemlist->next; } IL = IL / L; MEANIL += IL; while( neighbor != NULL){ if( neighbor->self != NULL){ HL += (1 - Get_QIJL(probe_User->self->rlist,neighbor->self->rlist) / L); counter++; } neighbor = neighbor->next; } total = counter; } probe_User = probe_User->next; } HL = HL / counter; MEANIL = MEANIL / RecordCounterProbe; /*-----------------------------------------------------------------------------------------Diversity Test END-----------------*/ printf("\nRS:%f\tEPL:%f\tHL:%f\tMEANIL:%f\n",RS,EPL,HL,MEANIL); fprintf(result,"RS:%1.4f\tEPL:%f\tHL:%f\tMEANIL:%f\n",RS,EPL,HL,MEANIL); fclose(result); return 0; }
static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) { int start = 0, i, w, w2, g; float uplim[128], maxq[128]; int minq, maxsf; float distfact = ((sce->ics.num_windows > 1) ? 85.80 : 147.84) / lambda; int last = 0, lastband = 0, curband = 0; float avg_energy = 0.0; if (sce->ics.num_windows == 1) { start = 0; for (i = 0; i < 1024; i++) { if (i - start >= sce->ics.swb_sizes[curband]) { start += sce->ics.swb_sizes[curband]; curband++; } if (sce->coeffs[i]) { avg_energy += sce->coeffs[i] * sce->coeffs[i]; last = i; lastband = curband; } } } else { for (w = 0; w < 8; w++) { const float *coeffs = sce->coeffs + w*128; start = 0; for (i = 0; i < 128; i++) { if (i - start >= sce->ics.swb_sizes[curband]) { start += sce->ics.swb_sizes[curband]; curband++; } if (coeffs[i]) { avg_energy += coeffs[i] * coeffs[i]; last = FFMAX(last, i); lastband = FFMAX(lastband, curband); } } } } last++; avg_energy /= last; if (avg_energy == 0.0f) { for (i = 0; i < FF_ARRAY_ELEMS(sce->sf_idx); i++) sce->sf_idx[i] = SCALE_ONE_POS; return; } for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { float *coefs = sce->coeffs + start; const int size = sce->ics.swb_sizes[g]; int start2 = start, end2 = start + size, peakpos = start; float maxval = -1, thr = 0.0f, t; maxq[w*16+g] = 0.0f; if (g > lastband) { maxq[w*16+g] = 0.0f; start += size; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) memset(coefs + w2*128, 0, sizeof(coefs[0])*size); continue; } for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { for (i = 0; i < size; i++) { float t = coefs[w2*128+i]*coefs[w2*128+i]; maxq[w*16+g] = FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 + i])); thr += t; if (sce->ics.num_windows == 1 && maxval < t) { maxval = t; peakpos = start+i; } } } if (sce->ics.num_windows == 1) { start2 = FFMAX(peakpos - 2, start2); end2 = FFMIN(peakpos + 3, end2); } else { start2 -= start; end2 -= start; } start += size; thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband); t = 1.0 - (1.0 * start2 / last); uplim[w*16+g] = distfact / (1.4 * thr + t*t*t + 0.075); } } memset(sce->sf_idx, 0, sizeof(sce->sf_idx)); abs_pow34_v(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { const float *coefs = sce->coeffs + start; const float *scaled = s->scoefs + start; const int size = sce->ics.swb_sizes[g]; int scf, prev_scf, step; int min_scf = -1, max_scf = 256; float curdiff; if (maxq[w*16+g] < 21.544) { sce->zeroes[w*16+g] = 1; start += size; continue; } sce->zeroes[w*16+g] = 0; scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2f(1/maxq[w*16+g])*16/3, 60, 218); step = 16; for (;;) { float dist = 0.0f; int quant_max; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { int b; dist += quantize_band_cost(s, coefs + w2*128, scaled + w2*128, sce->ics.swb_sizes[g], scf, ESC_BT, lambda, INFINITY, &b); dist -= b; } dist *= 1.0f / 512.0f / lambda; quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); if (quant_max >= 8191) { // too much, return to the previous quantizer sce->sf_idx[w*16+g] = prev_scf; break; } prev_scf = scf; curdiff = fabsf(dist - uplim[w*16+g]); if (curdiff <= 1.0f) step = 0; else step = log2f(curdiff); if (dist > uplim[w*16+g]) step = -step; scf += step; scf = av_clip_uint8(scf); step = scf - prev_scf; if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) { sce->sf_idx[w*16+g] = av_clip(scf, min_scf, max_scf); break; } if (step > 0) min_scf = prev_scf; else max_scf = prev_scf; } start += size; } } minq = sce->sf_idx[0] ? sce->sf_idx[0] : INT_MAX; for (i = 1; i < 128; i++) { if (!sce->sf_idx[i]) sce->sf_idx[i] = sce->sf_idx[i-1]; else minq = FFMIN(minq, sce->sf_idx[i]); } if (minq == INT_MAX) minq = 0; minq = FFMIN(minq, SCALE_MAX_POS); maxsf = FFMIN(minq + SCALE_MAX_DIFF, SCALE_MAX_POS); for (i = 126; i >= 0; i--) { if (!sce->sf_idx[i]) sce->sf_idx[i] = sce->sf_idx[i+1]; sce->sf_idx[i] = av_clip(sce->sf_idx[i], minq, maxsf); } }
static void radialBeamformSetWNG (RadialBeamform *x, t_object *attr, int argc, t_atom *argv) { float max_wng,curr_lvl,next_lvl,curr_omega,next_omega,curr_slope,next_slope; float *shn_bpnum=sph_omega_bp[x->sh_degree]; int n_bpnum=sph_bp_n[x->sh_degree]; float *shn_bpden=sph_omega_bp[x->sh_degree];; int n_bpden=sph_bp_n[x->sh_degree]; int knum=0; int kden=0; float one_over_dn=1.0f/x->delta_n; float one_over_dn0=1.0f/x->delta_n0; if ((argc<1)|(argv[0].a_type!=A_FLOAT && (argv[0].a_type!=A_LONG))) { post("radial_beamform~: no value given for wng"); max_wng=20.0f; } else max_wng = atom_getfloat(&argv[0]); x->max_wng=max_wng; if (x->bf_mode==VELOCITY) { shn_bpden = sph_omega_bpd[x->sh_degree]; n_bpden = sph_bpd_n[x->sh_degree]; } next_slope=0.0f; next_omega=1000.0f; next_lvl=0.0f; do { curr_omega=next_omega; curr_lvl=next_lvl; curr_slope=next_slope; if ((knum<n_bpnum)&&(kden<n_bpden)) { if (shn_bpden[kden]*one_over_dn0>shn_bpnum[knum]*one_over_dn) { next_omega=shn_bpden[kden++]*one_over_dn0; next_slope+=6.0f; } else{ next_omega=shn_bpnum[knum++]*one_over_dn; next_slope-=6.0f; } } else if (kden<n_bpden) { next_omega=shn_bpden[kden++]*one_over_dn0; next_slope+=6.0f; } else if (knum<n_bpnum) { next_omega=shn_bpnum[knum++]*one_over_dn; next_slope-=6.0f; } else { break; } next_lvl = curr_lvl + curr_slope * (log2f(curr_omega)-log2f(next_omega)); } while (next_lvl<max_wng); if (curr_slope>0.0f) { next_omega=curr_omega*pow(2.0f,(curr_lvl-max_wng)/curr_slope); } else { next_omega=0; } x->omega_cutoff=next_omega; x->slope_cutoff=curr_slope; // radialBeamformInfo(x); }
/** Return the maximum scalefactor where the quantized coef is not zero. */ static av_always_inline uint8_t coef2maxsf(float coef) { return av_clip_uint8(log2f(coef)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); }
int riv_nbits(int nof_prb) { return (int) ceilf(log2f((float) nof_prb * ((float) nof_prb + 1) / 2)); }