当前位置: 首页>>代码示例>>C++>>正文


C++ SIN函数代码示例

本文整理汇总了C++中SIN函数的典型用法代码示例。如果您正苦于以下问题:C++ SIN函数的具体用法?C++ SIN怎么用?C++ SIN使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SIN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AUBIO_NEW

aubio_wavetable_t *new_aubio_wavetable(uint_t samplerate, uint_t blocksize)
{
  uint_t i = 0;
  aubio_wavetable_t *s = AUBIO_NEW(aubio_wavetable_t);
  if ((sint_t)samplerate <= 0) {
    AUBIO_ERR("Can not create wavetable with samplerate %d\n", samplerate);
    goto beach;
  }
  s->samplerate = samplerate;
  s->blocksize = blocksize;
  s->wavetable_length = WAVETABLE_LEN;
  s->wavetable = new_fvec(s->wavetable_length + 3);
  for (i = 0; i < s->wavetable_length; i++) {
    s->wavetable->data[i] = SIN(TWO_PI * i / (smpl_t) s->wavetable_length );
  }
  s->wavetable->data[s->wavetable_length] = s->wavetable->data[0];
  s->wavetable->data[s->wavetable_length + 1] = s->wavetable->data[1];
  s->wavetable->data[s->wavetable_length + 2] = s->wavetable->data[2];
  s->playing = 0;
  s->last_pos = 0.;
  s->freq = new_aubio_parameter( 0., s->samplerate / 2., 10 );
  s->amp = new_aubio_parameter( 0., 1., 100 );
  return s;
beach:
  AUBIO_FREE(s);
  return NULL;
}
开发者ID:EQ4,项目名称:aubio-mod,代码行数:27,代码来源:wavetable.c

示例2: lfoset

int lfoset(CSOUND *csound, LFO *p)
{
  /* Types: 0:  sine
            1:  triangles
            2:  square (biplar)
            3:  square (unipolar)
            4:  saw-tooth
            5:  saw-tooth(down)
            */
    int type = (int)*p->type;
    if (type == 0) {            /* Sine wave so need to create */
      int i;
      if (p->auxd.auxp==NULL) {
        csound->AuxAlloc(csound, sizeof(MYFLT)*4097L, &p->auxd);
        p->sine = (MYFLT*)p->auxd.auxp;
      }
      for (i=0; i<4096; i++)
        p->sine[i] = SIN(TWOPI_F*(MYFLT)i/FL(4096.0));
/*        csound->Message(csound,"Table set up (max is %d)\n", MAXPHASE>>10); */
    }
    else if (UNLIKELY(type>5 || type<0)) {
      return csound->InitError(csound, Str("LFO: unknown oscilator type %d"),
                                       type);
    }
    p->lasttype = type;
    p->phs = 0;
    return OK;
}
开发者ID:amitkumar3968,项目名称:csound,代码行数:28,代码来源:schedule.c

示例3: SIN

void DCT::calcDCTI(float *data) {
    int n = 1 << _bits;

    float next = -0.5f * (data[0] - data[n]);

    for (int i = 0; i < (n / 2); i++) {
        float tmp1 = data[i    ];
        float tmp2 = data[n - i];

        float s = SIN(n, 2 * i);
        float c = COS(n, 2 * i);

        c *= tmp1 - tmp2;
        s *= tmp1 - tmp2;

        next += c;

        tmp1 = (tmp1 + tmp2) * 0.5f;

        data[i    ] = tmp1 - s;
        data[n - i] = tmp1 + s;
    }

    _rdft->calc(data);

    data[n] = data[1];
    data[1] = next;

    for (int i = 3; i <= n; i += 2)
        data[i] = data[i - 2] - data[i];
}
开发者ID:xoreos,项目名称:xoreos,代码行数:31,代码来源:dct.cpp

示例4: ff_dct_calc_III_c

static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data)
{
    int n = 1 << ctx->nbits;
    int i;

    float next  = data[n - 1];
    float inv_n = 1.0f / n;

    for (i = n - 2; i >= 2; i -= 2) {
        float val1 = data[i];
        float val2 = data[i - 1] - data[i + 1];
        float c    = COS(ctx, n, i);
        float s    = SIN(ctx, n, i);

        data[i]     = c * val1 + s * val2;
        data[i + 1] = s * val1 - c * val2;
    }

    data[1] = 2 * next;

    ctx->rdft.rdft_calc(&ctx->rdft, data);

    for (i = 0; i < n / 2; i++) {
        float tmp1 = data[i]         * inv_n;
        float tmp2 = data[n - i - 1] * inv_n;
        float csc  = ctx->csc2[i] * (tmp1 - tmp2);

        tmp1            += tmp2;
        data[i]          = tmp1 + csc;
        data[n - i - 1]  = tmp1 - csc;
    }
}
开发者ID:0x0B501E7E,项目名称:ffmpeg,代码行数:32,代码来源:dct.c

示例5: aubio_fft_get_imag

void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
  uint_t i;
  for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) {
    compspec->data[compspec->length - i] =
      spectrum->norm[i]*SIN(spectrum->phas[i]);
  }
}
开发者ID:apanly,项目名称:hackprinceton13,代码行数:7,代码来源:fft.c

示例6: spRegionAttachment_updateOffset

void spRegionAttachment_updateOffset (spRegionAttachment* self) {
	float regionScaleX = self->width / self->regionOriginalWidth * self->scaleX;
	float regionScaleY = self->height / self->regionOriginalHeight * self->scaleY;
	float localX = -self->width / 2 * self->scaleX + self->regionOffsetX * regionScaleX;
	float localY = -self->height / 2 * self->scaleY + self->regionOffsetY * regionScaleY;
	float localX2 = localX + self->regionWidth * regionScaleX;
	float localY2 = localY + self->regionHeight * regionScaleY;
	float radians = self->rotation * DEG_RAD;
	float cosine = COS(radians), sine = SIN(radians);
	float localXCos = localX * cosine + self->x;
	float localXSin = localX * sine;
	float localYCos = localY * cosine + self->y;
	float localYSin = localY * sine;
	float localX2Cos = localX2 * cosine + self->x;
	float localX2Sin = localX2 * sine;
	float localY2Cos = localY2 * cosine + self->y;
	float localY2Sin = localY2 * sine;
	self->offset[SP_VERTEX_X1] = localXCos - localYSin;
	self->offset[SP_VERTEX_Y1] = localYCos + localXSin;
	self->offset[SP_VERTEX_X2] = localXCos - localY2Sin;
	self->offset[SP_VERTEX_Y2] = localY2Cos + localXSin;
	self->offset[SP_VERTEX_X3] = localX2Cos - localY2Sin;
	self->offset[SP_VERTEX_Y3] = localY2Cos + localX2Sin;
	self->offset[SP_VERTEX_X4] = localX2Cos - localYSin;
	self->offset[SP_VERTEX_Y4] = localYCos + localX2Sin;
}
开发者ID:253056965,项目名称:cocos2d-x-lite,代码行数:26,代码来源:RegionAttachment.c

示例7: SIN

void DCT::calcDSTI(float *data) {
	int n = 1 << _bits;

	data[0] = 0;

	for (int i = 1; i < (n / 2); i++) {
		float tmp1 = data[i    ];
		float tmp2 = data[n - i];
		float s = SIN(n, 2 * i);

		s   *=  tmp1 + tmp2;
		tmp1 = (tmp1 - tmp2) * 0.5;

		data[i    ] = s + tmp1;
		data[n - i] = s - tmp1;
	}

	data[n / 2] *= 2;

	_rdft->calc(data);

	data[0] *= 0.5;

	for (int i = 1; i < (n - 2); i += 2) {
		data[i + 1] +=  data[i - 1];
		data[i    ]  = -data[i + 2];
	}

	data[n - 1] = 0;
}
开发者ID:AdamRi,项目名称:scummvm-pink,代码行数:30,代码来源:dct.cpp

示例8: ff_dst_calc_I_c

static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data)
{
    int n = 1 << ctx->nbits;
    int i;

    data[0] = 0;
    for (i = 1; i < n / 2; i++) {
        float tmp1   = data[i    ];
        float tmp2   = data[n - i];
        float s      = SIN(ctx, n, 2 * i);

        s           *= tmp1 + tmp2;
        tmp1         = (tmp1 - tmp2) * 0.5f;
        data[i]      = s + tmp1;
        data[n - i]  = s - tmp1;
    }

    data[n / 2] *= 2;
    ctx->rdft.rdft_calc(&ctx->rdft, data);

    data[0] *= 0.5f;

    for (i = 1; i < n - 2; i += 2) {
        data[i + 1] +=  data[i - 1];
        data[i]      = -data[i + 2];
    }

    data[n - 1] = 0;
}
开发者ID:0x0B501E7E,项目名称:ffmpeg,代码行数:29,代码来源:dct.c

示例9: ff_dct_calc_I_c

static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
{
    int n = 1 << ctx->nbits;
    int i;
    float next = -0.5f * (data[0] - data[n]);

    for (i = 0; i < n / 2; i++) {
        float tmp1 = data[i];
        float tmp2 = data[n - i];
        float s    = SIN(ctx, n, 2 * i);
        float c    = COS(ctx, n, 2 * i);

        c *= tmp1 - tmp2;
        s *= tmp1 - tmp2;

        next += c;

        tmp1        = (tmp1 + tmp2) * 0.5f;
        data[i]     = tmp1 - s;
        data[n - i] = tmp1 + s;
    }

    ctx->rdft.rdft_calc(&ctx->rdft, data);
    data[n] = data[1];
    data[1] = next;

    for (i = 3; i <= n; i += 2)
        data[i] = data[i - 2] - data[i];
}
开发者ID:0x0B501E7E,项目名称:ffmpeg,代码行数:29,代码来源:dct.c

示例10: spTransformConstraint_apply

void spTransformConstraint_apply (spTransformConstraint* self) {
	float rotateMix = self->rotateMix, translateMix = self->translateMix, scaleMix = self->scaleMix, shearMix = self->shearMix;
	spBone* target = self->target;
	float ta = target->a, tb = target->b, tc = target->c, td = target->d;
	int i;
	for (i = 0; i < self->bonesCount; ++i) {
		spBone* bone = self->bones[i];

		if (rotateMix > 0) {
			float a = bone->a, b = bone->b, c = bone->c, d = bone->d;
			float r = ATAN2(tc, ta) - ATAN2(c, a) + self->data->offsetRotation * DEG_RAD;
			float cosine, sine;
			if (r > PI) r -= PI2;
			else if (r < -PI) r += PI2;
			r *= rotateMix;
			cosine = COS(r);
			sine = SIN(r);
			CONST_CAST(float, bone->a) = cosine * a - sine * c;
			CONST_CAST(float, bone->b) = cosine * b - sine * d;
			CONST_CAST(float, bone->c) = sine * a + cosine * c;
			CONST_CAST(float, bone->d) = sine * b + cosine * d;
		}

		if (translateMix > 0) {
			float x, y;
			spBone_localToWorld(target, self->data->offsetX, self->data->offsetY, &x, &y);
			CONST_CAST(float, bone->worldX) += (x - bone->worldX) * translateMix;
			CONST_CAST(float, bone->worldY) += (y - bone->worldY) * translateMix;
		}
开发者ID:leafnsand,项目名称:xEngine,代码行数:29,代码来源:TransformConstraint.c

示例11: esweep_imag

int esweep_imag(esweep_object *obj) { /* UNTESTED */
    Complex *cpx;
    Polar *polar;
    int i;

    ESWEEP_OBJ_NOTEMPTY(obj, ERR_EMPTY_OBJECT);

    switch (obj->type) {
    case COMPLEX:
        cpx=(Complex*) obj->data;
        for (i=0; i<obj->size; i++) cpx[i].real=0;
        break;
    case POLAR:
        polar=(Polar*) obj->data;
        cpx=(Complex*) polar;
        for (i=0; i<obj->size; i++) {
            cpx[i].imag=polar[i].abs*SIN(polar[i].arg);
            cpx[i].real=0;
        }
        obj->type=COMPLEX;
        break;
    default:
        ESWEEP_NOT_THIS_TYPE(obj->type, ERR_NOT_ON_THIS_TYPE);
    }
    ESWEEP_ASSERT(correctFpException(obj), ERR_FP);
    return ERR_OK;
}
开发者ID:BackupTheBerlios,项目名称:esweep,代码行数:27,代码来源:esweep_math.c

示例12: COS

Vector3D Vector3D::rotateAroundAxis(const Vector3D& axis,
                                    const Angle& theta) const {
  const double u = axis._x;
  const double v = axis._y;
  const double w = axis._z;
  
//  const double cosTheta = theta.cosinus();
//  const double sinTheta = theta.sinus();
  const double cosTheta = COS(theta._radians);
  const double sinTheta = SIN(theta._radians);

  const double ms = axis.squaredLength();
  const double m = IMathUtils::instance()->sqrt(ms);
  
  return Vector3D(
                  ((u * (u * _x + v * _y + w * _z)) +
                   (((_x * (v * v + w * w)) - (u * (v * _y + w * _z))) * cosTheta) +
                   (m * ((-w * _y) + (v * _z)) * sinTheta)) / ms,
                  
                  ((v * (u * _x + v * _y + w * _z)) +
                   (((_y * (u * u + w * w)) - (v * (u * _x + w * _z))) * cosTheta) +
                   (m * ((w * _x) - (u * _z)) * sinTheta)) / ms,
                  
                  ((w * (u * _x + v * _y + w * _z)) +
                   (((_z * (u * u + v * v)) - (w * (u * _x + v * _y))) * cosTheta) +
                   (m * (-(v * _x) + (u * _y)) * sinTheta)) / ms
                  
                  );
}
开发者ID:ccarducci,项目名称:Ushahidi_local,代码行数:29,代码来源:Vector3D.cpp

示例13:

		Vec2 Vec2::rotateBy(REAL angle) const
		{
			REAL c,s;
			c=COS(angle);
			s=SIN(angle);
			return Vec2(x*c-y*s,y*c+x*s);
		}
开发者ID:vinceplusplus,项目名称:z3D,代码行数:7,代码来源:Vector2.cpp

示例14: COS

void DCT::calcDCTIII(float *data) {
	int n = 1 << _bits;

	float next  = data[n - 1];
	float inv_n = 1.0 / n;

	for (int i = n - 2; i >= 2; i -= 2) {
		float val1 = data[i    ];
		float val2 = data[i - 1] - data[i + 1];

		float c = COS(n, i);
		float s = SIN(n, i);

		data[i    ] = c * val1 + s * val2;
		data[i + 1] = s * val1 - c * val2;
	}

	data[1] = 2 * next;

	_rdft->calc(data);

	for (int i = 0; i < (n / 2); i++) {
		float tmp1 = data[i        ] * inv_n;
		float tmp2 = data[n - i - 1] * inv_n;

		float csc = _csc2[i] * (tmp1 - tmp2);

		tmp1 += tmp2;

		data[i        ] = tmp1 + csc;
		data[n - i - 1] = tmp1 - csc;
	}
}
开发者ID:AdamRi,项目名称:scummvm-pink,代码行数:33,代码来源:dct.cpp

示例15: gnome_vfs_address_get_sockaddr

/**
 * gnome_vfs_address_get_sockaddr:
 * @address: A #GnomeVFSAddress
 * @port: A valid port in host byte order to set in the returned sockaddr
 * structure.
 * @len: A pointer to an int which will contain the length of the
 * return sockaddr structure.
 *
 * This function tanslates @address into a equivalent
 * sockaddr structure. The port specified at @port will
 * be set in the structure and @len will be set to the length
 * of the structure.
 * 
 * 
 * Return value: A newly allocated sockaddr structure the caller must free
 * or %NULL if @address did not point to a valid #GnomeVFSAddress.
 **/
struct sockaddr *
gnome_vfs_address_get_sockaddr (GnomeVFSAddress *address,
				guint16          port,
				int             *len)
{
	struct sockaddr *sa;

	g_return_val_if_fail (address != NULL, NULL);

	sa = g_memdup (address->sa, SA_SIZE (address->sa));

	switch (address->sa->sa_family) {
#ifdef ENABLE_IPV6
	case AF_INET6:
		SIN6 (sa)->sin6_port = g_htons (port);

		if (len != NULL) {
			*len = SIN6_LEN;
		}
		
		break;
#endif
	case AF_INET:
		SIN (sa)->sin_port = g_htons (port);

		if (len != NULL) {
			*len = SIN_LEN;
		}
		break;

	}

	return sa;
}
开发者ID:Distrotech,项目名称:gnome-vfs,代码行数:51,代码来源:gnome-vfs-address.c


注:本文中的SIN函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。