Beispiel #1
0
void bs1770_add_sample(bs1770_t *bs1770, double fs, int channels,
    bs1770_sample_t sample)
{
  biquad_t *pre=&bs1770->pre;
  biquad_t *rlb=&bs1770->rlb;
  double wssqs=0.0;
  double *g=BS1770_G;
  int offs, size, i;
  int get_tmp;
  double den_tmp;

  if (bs1770->fs!=fs)
    bs1770_set_fs(bs1770, fs, channels);

  offs=bs1770->ring.offs;
  size=bs1770->ring.size;

  for (i=0;i<MIN(channels,BS1770_MAX_CHANNELS);++i) {
    double *buf=bs1770->ring.buf[i];
    double x=GETX(buf,offs,0)=DEN(sample[i]);

    if (1<size) {
      double y=GETY(buf,offs,0)=DEN(pre->b0*x
        +pre->b1*GETX(buf,offs,-1)+pre->b2*GETX(buf,offs,-2)
        -pre->a1*GETY(buf,offs,-1)-pre->a2*GETY(buf,offs,-2))
        ;
      double z=GETZ(buf,offs,0)=DEN(rlb->b0*y
        +rlb->b1*GETY(buf,offs,-1)+rlb->b2*GETY(buf,offs,-2)
        -rlb->a1*GETZ(buf,offs,-1)-rlb->a2*GETZ(buf,offs,-2))
        ;
      wssqs+=(*g++)*z*z;
      ++buf;
    }
  }

  if (NULL!=bs1770->lufs)
    bs1770_aggr_add_sqs(bs1770->lufs,fs,wssqs);

  if (NULL!=bs1770->lra)
    bs1770_aggr_add_sqs(bs1770->lra,fs,wssqs);

  if (size<2)
    ++bs1770->ring.size;

  if (++bs1770->ring.offs==BS1770_BUF_SIZE)
    bs1770->ring.offs=0;
}
Beispiel #2
0
/*
 * 同步一个文件,如果flag被置位的话就等直到这些文件真的被同步成功
 * 否则只是添加一个任务,然后结果什么样就不管了
 * 说实话,我并不知道这个flag原来实际上是什么用……
 */
int baiduapi_fsync(const char *path, int flag, struct fuse_file_info *fi)
{
    if (fi->fh) {
        int i ;
        filedec *f = (filedec *) fi->fh;
        switch (f->type) {
        case forread:
            break;
        case forwrite:
            pthread_mutex_lock(&f->lock);
            for (i = 0; i <= GetWriteBlkNo(f->lengh); ++i) {
                if ((f->cache.w.taskid[i] == 0) && 
                    (GETD(f->cache.w.flags, i) || GETZ(f->cache.w.flags, i))) {
                    block *b = malloc(sizeof(block));
                    b->bno = i;
                    b->fd = f;
                    f->cache.w.taskid[i] = addtask((taskfunc) uploadblock, b, 0);
                }
            }
            pthread_mutex_unlock(&f->lock);
            if (flag) {
                int done = 0;
                while (!done) {
                    done = 1;
                    for (i = 0; i <= GetWriteBlkNo(f->lengh); ++i) {
                        if (f->cache.w.taskid[i]) {
                            waittask(f->cache.w.taskid[i]);
                        }
                        if (GETD(f->cache.w.flags, i) || GETZ(f->cache.w.flags, i)) {
                            pthread_mutex_lock(&f->lock);
                            block *b = malloc(sizeof(block));
                            b->bno = i;
                            b->fd =  f;
                            f->cache.w.taskid[i] = addtask((taskfunc) uploadblock, b, 0);
                            pthread_mutex_unlock(&f->lock);
                            done = 0;
                        }
                    };

                }
            }
            break;
        }
    }

    return 0;
}
static void vrml_ellipse(GVJ_t * job, pointf * A, int filled)
{
    obj_state_t *obj = job->obj;
    node_t *n;
    edge_t *e;
    double z = obj->z;
    double rx, ry;
    int dx, dy;
    pointf npf, nqf;
    point np;
    int pen;
    gdImagePtr brush = NULL;

    rx = A[1].x - A[0].x;
    ry = A[1].y - A[0].y;

    switch (obj->type) {
    case ROOTGRAPH_OBJTYPE:
    case CLUSTER_OBJTYPE:
	break;
    case NODE_OBJTYPE:
	n = obj->u.n;
	if (shapeOf(n) == SH_POINT) {
	    doSphere (job, n, A[0], z, rx, ry);
	    return;
	}
	pen = set_penstyle(job, im, brush);

	npf = vrml_node_point(job, n, A[0]);
	nqf = vrml_node_point(job, n, A[1]);

	dx = ROUND(2 * (nqf.x - npf.x));
	dy = ROUND(2 * (nqf.y - npf.y));

	PF2P(npf, np);

	if (filled)
	    gdImageFilledEllipse(im, np.x, np.y, dx, dy, color_index(im, obj->fillcolor));
	gdImageArc(im, np.x, np.y, dx, dy, 0, 360, pen);

	if (brush)
	    gdImageDestroy(brush);

	gvputs(job,   "Transform {\n");
	gvprintf(job, "  translation %.3f %.3f %.3f\n", A[0].x, A[0].y, z);
	gvprintf(job, "  scale %.3f %.3f 1\n", rx, ry);
	gvputs(job,   "  children [\n");
	gvputs(job,   "    Transform {\n");
	gvputs(job,   "      rotation 1 0 0   1.57\n");
	gvputs(job,   "      children [\n");
	gvputs(job,   "        Shape {\n");
	gvputs(job,   "          geometry Cylinder { side FALSE }\n");
	gvputs(job,   "          appearance Appearance {\n");
	gvputs(job,   "            material Material {\n");
	gvputs(job,   "              ambientIntensity 0.33\n");
	gvputs(job,   "              diffuseColor 1 1 1\n");
	gvputs(job,   "            }\n");
	gvprintf(job, "            texture ImageTexture { url \"node%ld.png\" }\n", AGSEQ(n));
	gvputs(job,   "          }\n");
	gvputs(job,   "        }\n");
	gvputs(job,   "      ]\n");
	gvputs(job,   "    }\n");
	gvputs(job,   "  ]\n");
	gvputs(job,   "}\n");
	break;
    case EDGE_OBJTYPE:
	e = obj->u.e;
	z = GETZ(job,obj,A[0],e);

	gvputs(job,   "Transform {\n");
	gvprintf(job, "  translation %.3f %.3f %.3f\n", A[0].x, A[0].y, z);
	gvputs(job,   "  children [\n");
	gvputs(job,   "    Shape {\n");
	gvprintf(job, "      geometry Sphere {radius %.3f }\n", (double) rx);
	gvprintf(job, "      appearance USE E%d\n", AGSEQ(e));
	gvputs(job,   "    }\n");
	gvputs(job,   "  ]\n");
	gvputs(job,   "}\n");
    }
}
static void vrml_polygon(GVJ_t *job, pointf * A, int np, int filled)
{
    obj_state_t *obj = job->obj;
    node_t *n;
    edge_t *e;
    double z = obj->z;
    pointf p, mp;
    gdPoint *points;
    int i, pen;
    gdImagePtr brush = NULL;
    double theta;

    switch (obj->type) {
    case ROOTGRAPH_OBJTYPE:
	gvprintf(job, " Background { skyColor %.3f %.3f %.3f }\n",
	    obj->fillcolor.u.rgba[0] / 255.,
	    obj->fillcolor.u.rgba[1] / 255.,
	    obj->fillcolor.u.rgba[2] / 255.);
	Saw_skycolor = TRUE;
	break;
    case CLUSTER_OBJTYPE:
	break;
    case NODE_OBJTYPE:
	n = obj->u.n;
	pen = set_penstyle(job, im, brush);
	points = N_GGNEW(np, gdPoint);
	for (i = 0; i < np; i++) {
	    mp = vrml_node_point(job, n, A[i]);
	    points[i].x = ROUND(mp.x);
	    points[i].y = ROUND(mp.y);
	}
	if (filled)
	    gdImageFilledPolygon(im, points, np, color_index(im, obj->fillcolor));
	gdImagePolygon(im, points, np, pen);
	free(points);
	if (brush)
	    gdImageDestroy(brush);

	gvputs(job,   "Shape {\n");
	gvputs(job,   "  appearance Appearance {\n");
	gvputs(job,   "    material Material {\n");
	gvputs(job,   "      ambientIntensity 0.33\n");
	gvputs(job,   "        diffuseColor 1 1 1\n");
	gvputs(job,   "    }\n");
	gvprintf(job, "    texture ImageTexture { url \"node%ld.png\" }\n", AGSEQ(n));
	gvputs(job,   "  }\n");
	gvputs(job,   "  geometry Extrusion {\n");
	gvputs(job,   "    crossSection [");
	for (i = 0; i < np; i++) {
	    p.x = A[i].x - ND_coord(n).x;
	    p.y = A[i].y - ND_coord(n).y;
	    gvprintf(job, " %.3f %.3f,", p.x, p.y);
	}
	p.x = A[0].x - ND_coord(n).x;
	p.y = A[0].y - ND_coord(n).y;
	gvprintf(job, " %.3f %.3f ]\n", p.x, p.y);
	gvprintf(job, "    spine [ %.5g %.5g %.5g, %.5g %.5g %.5g ]\n",
		ND_coord(n).x, ND_coord(n).y, z - .01,
		ND_coord(n).x, ND_coord(n).y, z + .01);
	gvputs(job,   "  }\n");
	gvputs(job,   "}\n");
	break;
    case EDGE_OBJTYPE:
	e = obj->u.e;
	if (np != 3) {
	    static int flag;
	    if (!flag) {
		flag++;
		agerr(AGWARN,
		  "vrml_polygon: non-triangle arrowheads not supported - ignoring\n");
	    }
	}
	if (IsSegment) {
	    doArrowhead (job, A);
	    return;
	}
	p.x = p.y = 0.0;
	for (i = 0; i < np; i++) {
	    p.x += A[i].x;
	    p.y += A[i].y;
	}
	p.x = p.x / np;
	p.y = p.y / np;

	/* it is bad to know that A[1] is the aiming point, but we do */
	theta =
	    atan2((A[0].y + A[2].y) / 2.0 - A[1].y,
		  (A[0].x + A[2].x) / 2.0 - A[1].x) + M_PI / 2.0;

	z = GETZ(job,obj,p,e);

	/* FIXME: arrow vector ought to follow z coord of bezier */
	gvputs(job,   "Transform {\n");
	gvprintf(job, "  translation %.3f %.3f %.3f\n", p.x, p.y, z);
	gvputs(job,   "  children [\n");
	gvputs(job,   "    Transform {\n");
	gvprintf(job, "      rotation 0 0 1 %.3f\n", theta);
	gvputs(job,   "      children [\n");
	gvputs(job,   "        Shape {\n");
	gvprintf(job, "          geometry Cone {bottomRadius %.3f height %.3f }\n",
		obj->penwidth * 2.5, obj->penwidth * 10.0);
	gvprintf(job, "          appearance USE E%ld\n", AGSEQ(e));
	gvputs(job,   "        }\n");
	gvputs(job,   "      ]\n");
	gvputs(job,   "    }\n");
	gvputs(job,   "  ]\n");
	gvputs(job,   "}\n");
	break;
    }
}