Example #1
0
void Chorus::update()
      {
      /* The modulating LFO goes through a full period every x samples: */
      modulation_period_samples = lrint(sample_rate / speed_Hz);

      /* The variation in delay time is x: */
      int modulation_depth_samples = (int)
         (depth_ms / 1000.0  /* convert modulation depth in ms to s*/
         * sample_rate);

      if (modulation_depth_samples > MAX_SAMPLES) {
            fluid_log(FLUID_WARN, "chorus: Too high depth. Setting it to max (%d).", MAX_SAMPLES);
            modulation_depth_samples = MAX_SAMPLES;
            }

      /* initialize LFO table */
      if (type == FLUID_CHORUS_MOD_SINE)
            sine(lookup_tab, modulation_period_samples, modulation_depth_samples);
      else if (type == FLUID_CHORUS_MOD_TRIANGLE)
            triangle(lookup_tab, modulation_period_samples, modulation_depth_samples);
      else {
            type = FLUID_CHORUS_MOD_SINE;
            sine(lookup_tab, modulation_period_samples, modulation_depth_samples);
            }

      for (int i = 0; i < number_blocks; i++) {
            /* Set the phase of the chorus blocks equally spaced */
            phase[i] = (int) ((double) modulation_period_samples
               * (double) i / (double) number_blocks);
            }

      /* Start of the circular buffer */
      counter = 0;
      }
Example #2
0
/*************************************************************
 *************************************************************
 *               ROUNDED  TO NEAREST			     *
 *************************************************************
 *************************************************************/
double scs_cos_rn(double x){ 
  scs_t sc1, sc2;
  double resd;
  int N;
#if EVAL_PERF
	crlibm_second_step_taken++;
#endif

  scs_set_d(sc1, x);
  N = rem_pio2_scs(sc2, sc1);
  N = N & 0x0000003;		/* extract the 2 last bits of  N */
  switch (N){
  case 0:
    cosine(sc2);
    scs_get_d(&resd, sc2);
    return resd;
  case 1:
    sine(sc2);
    scs_get_d(&resd, sc2);
    return -resd;
  case 2:
    cosine(sc2);
    scs_get_d(&resd, sc2);
    return -resd;
  case 3:
    sine(sc2);
    scs_get_d(&resd, sc2);
    return resd;
  default:
    fprintf(stderr,"ERREUR: %d is not a valid value in s_cos \n", N);
    return 0.0;
  }
  
}
Example #3
0
File: song.c Project: fvdsn/tuned
void pouu(track_t *t, int pos, int length, int freq, float vol){
	track_t *n = trackNew(110 + 2*length);
	float hi_vol  = 0.125	*vol;
	float med_vol = 0.25	*vol;
	float low_vol = 0.5	*vol;
	int   hi_sust = 0.25	*length;
	int med_sust  = 0.5	*length;
	int low_sust  = 1.0	*length;
	fun_t *nte;
	fun_t *hi_note = note(0,10,100,hi_sust,med_sust,med_vol,hi_vol);
	fun_t *med_note = note(0,10,100,med_sust,low_sust,low_vol,med_vol);
	fun_t *low_note = note(0,10,100,low_sust,low_sust,low_vol,low_vol);
	fun_t *vhi_note = note(0,10,100,hi_sust,hi_sust,med_vol/2,hi_vol/2);
	freq/=2;
	
	
	nte = 	
			add( 	mult(low_note, sine(trapeze(0,low_sust*2,freq,freq),0,1.0)),
			add( 	mult(med_note, sine(trapeze(0,low_sust*2,freq*2,freq*2),0,1.0)),
			add(	mult(hi_note, sine(trapeze(0,low_sust*2,freq*4,freq*4),0,0.3)),
				mult(vhi_note,sine(c(freq*8),0,0.05)) )));
	nte = mult(nte,add(c(0.9),sine(c(5),100,0.1)));
	nte = mult(unit(0,0.0,1.0),mult(unit(low_sust*2,1.0,0.0),nte));
	trackAdd(n,nte,nte);
	trackMix(t,n,pos,1.0);
}
Example #4
0
float sinr(int alpha)
{
    u8 sign = 0; // positive

    // normalize the angle
    if (alpha < 0)
        alpha = 360 - ((-alpha) % 360);
    else
        alpha %= 360;

    // sin(a+180) = - sin(a)
    if (alpha >= 180)
    {
        alpha -= 180;
        sign = 1; // negative 
    }

    // now a < 180
    // sin(180-a) == sin(a);
    if (alpha > 90)
        alpha = 180 - alpha;

    if (sign)
        return -sine(alpha);
    else
        return  sine(alpha);
}
Example #5
0
void
cosine_of_angle_sum(void)
{
	p2 = cdr(p1);
	while (iscons(p2)) {
		B = car(p2);
		if (isnpi(B)) {
			push(p1);
			push(B);
			subtract();
			A = pop();
			push(A);
			cosine();
			push(B);
			cosine();
			multiply();
			push(A);
			sine();
			push(B);
			sine();
			multiply();
			subtract();
			return;
		}
		p2 = cdr(p2);
	}
	cosine_of_angle();
}
Example #6
0
int sine(int n)
{
    int i;
    if(n==0) return 0;
    printf("sin(%d",n);
    if(n==cur) {for(i=0;i<n;i++) printf(")"); chk=0; cur=n-1; return 0;}
    else if(chk==0) {printf("-"); chk=1; sine(n+1);}
    else if(chk==1) {printf("+"); chk=0; sine(n+1);}
}
Example #7
0
File: song.c Project: fvdsn/tuned
fun_t *cool_sound(fun_t *freq, fun_t *envelope, int pos, float vol){
	fun_t *freq8 = mult(freq,c(8)); //original cool noise freq is 55
	fun_t *freq54 = mult(freq,c(0.545454));
	fun_t *f = add(mult(sine(freq8,0,0.2),add(sawtooth(freq,add(c(4.0),sawtooth(c(1),c(1),0,2.0)),0,0.5),c(0.5))),
			square(freq54,add(sine(c(0.5),0,0.3),c(0.4)),0,0.2));
	f = mult(envelope,f);
	f = fdelay(c(pos),f);
	f =   mult(c(vol),f);
	return f;
}
Example #8
0
File: item.piano.c Project: ifbe/42
void piano_gen(short* pcm, float f)
{
	int j;
	for(j=0;j<16384;j++)
	{
		pcm[j] = 16384*sine(j*2*PI*f*1/44100)
				+ 8192*sine(j*2*PI*f*2/44100)
				+ 1024*sine(j*2*PI*f*3/44100)
				+ 4096*sine(j*2*PI*f*4/44100)
				+ 1024*sine(j*2*PI*f*5/44100);

		pcm[j] *= 1.0 - j/16384.0;
	}
}
Example #9
0
int main(){
	//need to use double notation here otherwise we get extremely weird printouts !NaN
	double num1= 1.5;
	double numneg1= -1.5;
	double num2= 1;
	double numneg2= -1;
	double num3= 69;
	double num4= 100;
	double numneg4= -100;
	double num5= 3.45;
	double num0= 0;
	
	printf("Absolute:\n");
    printf("abs(1.5) = %16.8lf\n", absolute(num1));
    printf("abs(-1.5) = %16.8lf\n", absolute(numneg1));
    printf("abs(69) = %16.8lf\n", absolute(num3));
    printf("abs(-100) = %16.8lf\n\n", absolute(numneg4));

	printf("Modulo(remainder of x/y where(x,y)):\n");
	printf( "modulo(0, 1) = %16.8lf\n", modulo(num0, num2));	//returns 0
	printf( "modulo(1, 0) = %16.8lf\n", modulo(num2, num0));	//returns NaN
    printf( "modulo(1, 1) = %16.8lf\n", modulo(num2, num2));
    printf( "modulo(-1.5, 1) = %16.8lf\n", modulo(numneg1, num2));	//should be positive?!
	printf( "modulo(-1, -1.5) = %16.8lf\n", modulo(numneg2, numneg1));
	printf( "modulo(100, 69) = %16.8lf\n", modulo(num4, num3));
	printf( "modulo(3.45, 1.5) = %16.8lf\n\n", modulo(num5, num1));

	//not allowed to pass in negative values, so return 0
    printf("Factorial:\n");
	printf( "1! = %16.8lf\n", factorial(1));
	printf( "-1! = %16.8lf\n", factorial(-1));
	printf( "3! = %16.8lf\n", factorial(3));
	printf( "-3! = %16.8lf\n", factorial(-3));
	printf( "5! = %16.8lf\n", factorial(5));
	printf( "10! = %16.8lf\n\n", factorial(10));
	//printf( "1.5! = %16.8lf\n", factorial(1.5));	//no testing for float exponents because unsigned int is passed in
	
    printf("Power:\n");		//no testing for float exponents because unsigned int is passed in
	printf("%d ^ %d = %16.8lf\n", 0, 2, power(0,2));
    printf("%d ^ %d = %16.8lf\n", 1, 1, power(1,1));
    printf("%d ^ %d = %16.8lf\n", 3, 3, power(3.0,3.0));
    printf("%d ^ %d = %16.8lf\n", -1, 1, power(-1,1));
    printf("%d ^ %d = %16.8lf\n", -4, 2, power(-4,2));
	printf("%d ^ %d = %16.8lf\n\n", -1, -1, power(-1,-1));
	//negative exponents and negative bases have not been fully worked out yet, really need to do additional testing(test cases)
	
	//test cases even though didn't finish sine
    printf( "sine(0): %16.8lf\n", sine(0));
    printf( "sine(pi/2): %16.8lf\n", sine(M_PI/2));
    printf( "sine(pi/3): %16.8lf\n", sine(M_PI/3));
    printf( "sine(pi/4): %16.8lf\n", sine(M_PI/4));
    printf( "sine(pi/6): %16.8lf\n", sine(M_PI/6));
    printf( "sine(pi): %16.8lf\n", sine(M_PI));
	printf( "sine(-pi): %16.8lf\n", sine(-M_PI));
	printf( "sine(-1.5): %16.8lf\n\n", sine(-1.5));

    return 0;
}
Example #10
0
File: song.c Project: fvdsn/tuned
int main(int argc, char **argv){
	track_t *t = trackRead("samples/test-guitare-raw.raw");
	/*
	fun_t *env = note(0,10,700,500,2000,1,0.2);
	fun_t *f = add( cool_sound(c(880),env,0,0.5),
		   add( cool_sound(c(140),env,500,1),
		   add( cool_sound(c(130),env,1000,1),
		   add( cool_sound(c(110),env,1500,1),
		   add( cool_sound(c(130),env,2000,1),
		   add( cool_sound(c(440),env,2500,1),
		   add( cool_sound(c(130),env,3000,1),
		   add( cool_sound(c(110),env,3500,1), c(0)
		   		))))))));
	*/
	//fun_t *f2 = add(c(0.5), square(c(5),c(0.5),0,0.5));
	//f = sine(c(440.0),0.0,0.5);
	//trackAdd(t,f,f);
	
	//trackMult(t,c(0.2),c(0.2));
	//fx_reverb(t);
	
	fx_echo(t,c(500),c(0.2),3);
	fx_cutoff(t,c(0.09),c(0.2),WAVE_BOTH); 
	//trackMult(t,f2,f2);
	//fx_echo(t,c(500),c(0.3),4);
	fx_flange(t,sine(c(0.2),0,500));
	//void fx_echo(track_t *t, fun_t *delay, fun_t *amp, int count);
	//void fx_power_dist(track_t*t, fun_t *gain, fun_t*clip, fun_t *power,
	//	int wave);
	//fx_disto(t,WAVE_BOTH);
	initAudio();
	//trackPlay(t);
	trackWrite(t,"test01.wav");
	return 1;
}
int main()
{
	/* 3 main variables to direct the program */
	int degree;
	int n;
	int exit;
	
	
	/* Declaring exit variale as 0 to indicate exit when returned to 1 */
	exit = 0;
	
	
	/* Creating a loop to countinue until user wants to exit */
	while (exit!=1)
	{
		/* Taking inputs from user */
		getInputs(&degree,&n,&exit);
		
		/* Calling functions to calculate sine and cosine values using */
		/* the angle and n data given by user */ 
		sine(degree,n); 
		cosine(degree,n); 
	}
	
	
	return (0);
}
Example #12
0
static int
process (jack_nframes_t  nframes,
         void           *arg)
{
  state *data = arg;

  jack_sample_t *sine_buffer     = jack_port_get_buffer (data->sine_port,     nframes);
  jack_sample_t *square_buffer   = jack_port_get_buffer (data->square_port,   nframes);
  jack_sample_t *triangle_buffer = jack_port_get_buffer (data->triangle_port, nframes);
  jack_sample_t *sawtooth_buffer = jack_port_get_buffer (data->sawtooth_port, nframes);

  double period = data->sample_rate / data->frequency;

  int i;

  for (i = 0; i < nframes; i++)
  {
    double current_position = (data->current_block * nframes + i) / period;

    sine_buffer[i]     = sine     (current_position);
    square_buffer[i]   = square   (current_position);
    triangle_buffer[i] = triangle (current_position);
    sawtooth_buffer[i] = sawtooth (current_position);
  }

  data->current_block++;

  return 0;
}
Example #13
0
void title_line8(void)
{
	int ofs, darken, abs_y;

	// background draw only, with effects
	if ((vga_line>=TITLE_OFS_Y) && (vga_line<TITLE_OFS_Y+TITLE_HEIGHT*3/2)) {
		if (vga_line<TITLE_OFS_Y+TITLE_HEIGHT) {
			ofs=0;
			abs_y = vga_line-TITLE_OFS_Y;
			darken=0;
		} else {
			int phi = (2*vga_frame+8*vga_line)%256;
			ofs = sine(phi) * ((int)vga_line-TITLE_OFS_Y-TITLE_HEIGHT)/(16*64); 
			abs_y = TITLE_HEIGHT-1-(int)(vga_line-TITLE_OFS_Y-TITLE_HEIGHT)*2;
			darken=1;
		}
		ofs += TITLE_OFS_X;
	
		// speedups if inlined + special cased
		switch(ofs&3) {
			case 0: _draw_tiles_title(ofs,abs_y,darken); break;
			case 1: _draw_tiles_title(ofs,abs_y,darken); break;
			case 2: _draw_tiles_title(ofs,abs_y,darken); break;
			case 3: _draw_tiles_title(ofs,abs_y,darken); break;
		}

	} else {
		memset(draw_buffer,0,VGA_H_PIXELS);
	}

}
Example #14
0
float sine(float x, int n)
{
	if (n == 0) 
		return x;

	return ( ( (pow(-1,n) / fact((2 * n) + 1)) * pow(x,(2 * n) + 1)) + sine(x,n - 1));
}
Example #15
0
void carveline2d_circle(struct arena* win, u32 rgb,
	vec3 vc, vec3 vr, vec3 vf)
{
#define lineacc (acc*2)
	int j;
	float a,c,s;

	float bb = (float)(rgb&0xff) / 256.0;
	float gg = (float)((rgb>>8)&0xff) / 256.0;
	float rr = (float)((rgb>>16)&0xff) / 256.0;

	float* vbuf;
	u16* ibuf;
	int vlen = line2d_vars(win, 0, &vbuf, &ibuf, lineacc, lineacc);

	for(j=0;j<lineacc;j++)
	{
		a = j*tau/lineacc;
		c = cosine(a);
		s = sine(a);

		vbuf[6*j+0] = vc[0] + vr[0]*c + vf[0]*s;
		vbuf[6*j+1] = vc[1] + vr[1]*c + vf[1]*s;
		vbuf[6*j+2] = vc[2] + vr[2]*c + vf[2]*s;

		vbuf[6*j+3] = rr;
		vbuf[6*j+4] = gg;
		vbuf[6*j+5] = bb;

		ibuf[2*j+0] = vlen+j;
		ibuf[2*j+1] = vlen+(j+1)%lineacc;
	}
}
Example #16
0
File: ooxx.c Project: ifbe/live
void cubie(int x,int y,int z)
{
	int i,j;

	//背景色
	for(i=256*x;i<256*x+256;i++)
		for(j=256*y;j<256*y+256;j++)
			point(i,j,0x44444444);

	for(i=256*x;i<256*x+256;i++)
	{
		point(i,256*y,0);
		point(i,256*y+255,0);
	}
	for(j=256*y;j<256*y+256;j++)
	{
		point(256*x,j,0);
		point(256*x+255,j,0);
	}

	if(z==1)	//画0
	{
		double a;
		for(a=0;a<6.28;a+=0.01)
		{
		point(		(int)(256*x+128+100*cosine(a)),
				(int)(256*y+128+100*sine(a)),
				0xff0000
		);
		point(
				(int)(256*x+129+100*cosine(a)),
				(int)(256*y+128+100*sine(a)),
				0xff0000
		);
		}
	}
	if(z==2)	//画x
	{
		for(i=28;i<228;i++)
		{
			point(256*x+i,256*y+i,0xff);
			point(256*x+i+1,256*y+i,0xff);
			point(256*x+i,256*y+256-i,0xff);
			point(256*x+i+1,256*y+256-i,0xff);
		}
	}
}
Example #17
0
// Input:  angle in fixed point notation - -128 to +127 = -180 to +~179 degrees.
// output: 16-bit -7fff to +7fff
int16_t sine(int8_t angle)
{
    if(angle == -128) return 0;
    if(angle < 0) return -sine(-angle);
    if(angle == 64) return 32767;
    if(angle < 64) return sine_table[angle];
    return sine_table[63-(angle-65)];
}
Example #18
0
void complex_power_real(float* d, float e)
{
	float mod = complexmodulus(d);
	float ang = complexangle(d);
	float ppp = power(mod, e);
	d[0] = ppp * cosine(ang * e);
	d[1] = ppp * sine(ang * e);
}
Example #19
0
int main()
{
	float x, sum;

	printf("Enter value of X to find the sum of sine series:\n");
	scanf("%f", &x);
	printf("x : %f\n", x);
	sum = sine(x,10);
	printf("Sum of sine series : %f\n", sum);
}
Example #20
0
File: song.c Project: fvdsn/tuned
void song(track_t*t){
	track_t *s = trackNew(8000);
	track_t *b = trackNew(8000);
	fun_t *f;
	fun_t *f2;
	bassloop(t,0,200);
	bassloop(t,8*200,200);
	bassloop(t,16*200,200);
	bassloop(t,24*200,200);
	bassloop(t,32*200,200);
	bassloop(t,46*200,200);
	bassloop(t,54*200,200);
	bassloop(t,62*200,200);
	f = min(c(1.0),max(ramp(4000,8400,0,1),sine(ramp(2000,8400,5,8),0,10)));
	f2 =max(unit(2400,0.2,0),unit(2400,0,1.0));
		
	trackMult(t,f,f);
	f = max(unit(5000,1,0),max(unit(8500,0,1),
		min(c(1.0),max(ramp(5000,8500,1,0),sine(ramp(5000,8000,20,200),0,10)))
		));
	trackMult(t,f,f);
	//trackMult(t,f2,f2);
	//fx_reverb(t);
	fx_disto(t,WAVE_BOTH);

	tshhloop(s,0*200,200);
	tshhloop(s,8*200,200);
	tshhloop(s,16*200,200);
	tshhloop(s,24*200,200);
	tshhloop(s,32*200,200);
	tshhloop(s,40*200,200);
	tshhloop(s,46*200,200);
	tshhloop(s,54*200,200);
	tshhloop(s,56*200,200);
	tshhloop(s,62*200,200);
	f = ramp(0,8000,0.2,0.7);
	trackMult(s,f,f);
	trackMix(t,s,0,1);
		
	//fx_reverb(b);
	//fx_disto(b);
	//trackMix(t,b,0,0.5);	
}
Example #21
0
void estYawDrift(void)
{
	// Don't update Yaw Drift while hovering, since that doesn't work right yet
	if (gps_nav_valid() && !dcm_flags._.skip_yaw_drift)
	{
		if ((estimatedWind[0] == 0 && estimatedWind[1] == 0) || (air_speed_magnitudeXY < WIND_NAV_AIR_SPEED_MIN))
		{
			dirovergndHGPS[0] = -cosine(actual_dir);
			dirovergndHGPS[1] = sine(actual_dir);
			dirovergndHGPS[2] = 0;
		}
		else
		{
			dirovergndHGPS[0] = -cosine(calculated_heading);
			dirovergndHGPS[1] = sine(calculated_heading);
			dirovergndHGPS[2] = 0;
		}
	}
}
Example #22
0
/**
 * @brief Timer1 interrupt routine
 *
 * @warning This routine is declared <dfn>__attribute__((interrupt))</dfn> so 
 * it can be interrupted by other interrupts.
 * This is necessary to keep USB from timing out.
 */
void TIMER1_OVF_vect(void) {
  int i;

  /* We loop over all LED slots */
  for (i=0; i<4; i++) {
    /* How many times have we been here ? */
    count[i]++;

    if (count[i] >= maxcount[i]) {
      count[i] = 0;
      if (i == D) {
        PORTC ^= _BV(PC3);
      }
    }

    /* If i == 4, no need to check waveform, just bail out */
    if (i == D)
      return;
    
    /* Check current waveform and change OCRxn values accordingly */
    switch (waveform[i]) {
    case PULSEMODE_NONE:
      return;
      break;
#ifdef USE_TRIANGLE
    case PULSEMODE_TRIANGLE:
      *port[i] = triangle(count[i], maxcount[i], maxcolor[i]);
      break;
#endif
#ifdef USE_SAWTOOTH_UP
    case PULSEMODE_SAWTOOTH_UP:
      *port[i] = sawtooth_up(count[i], maxcount[i], maxcolor[i]);
      break;
#endif
#ifdef USE_SAWTOOTH_DOWN
    case PULSEMODE_SAWTOOTH_DOWN:
      *port[i] = sawtooth_down(count[i], maxcount[i], maxcolor[i]);
      break;
#endif
#ifdef USE_SIN
    case PULSEMODE_SIN:
      *port[i] = sine(count[i], maxcount[i], maxcolor[i]);
      break;
#endif
#ifdef USE_SUBPWM
    case PULSEMODE_SUBPWM:
      *port[i] = subpwm(count[i], maxcount[i], maxcolor[i], duty[i]);
      break;
#endif
    default:
      return;
    }
  }
  return;
}
Example #23
0
void
dcos(void)
{
    push(cadr(p1));
    push(p2);
    derivative();
    push(cadr(p1));
    sine();
    multiply();
    negate();
}
Example #24
0
int func(int n)
{
    if(cur2<0) return 0;
    cur=n-cur2;
    sine(1);
    if(n-min==1) return 0;
    else if(n-min>=0) printf("+%d)",n-min);
    else printf("%d)",n-min);
    min++; cur2--;
    func(n);

}
void hoverPitchCntrl(void)
{
    int16_t max_tilt_sine = sine((int8_t)(MAX_TILT*.7111));

    if (flags._.pitch_feedback && flags._.GPS_steering)
	{
        //error along y axis between aircraft position and goal (origin point here) in cm
#ifdef TestGPSPositioning
        hovering_pitch_order = RMAX;
        tofinish_line_factor10 = 30;
#endif
        if (control_position_hold)
        {
            target_pitch = compute_target_pitch(hovering_pitch_order, tofinish_line_factor10, max_tilt_sine);
        }
        else
        {
            target_pitch = 0;
            pitch_error_integral = 0;
            pitch_v_error_integral = 0;
        }

        //additional_int16_export4 = target_pitch;
        
        uint16_t horizontal_air_speed = vector2_mag(IMUvelocityx._.W1 - estimatedWind[0], 
	                                   IMUvelocityy._.W1 - estimatedWind[1]);
        
#ifdef TestGPSPositioning
        horizontal_air_speed = 0;
#endif
        
		//PI controller on pitch angle
		pitch_v_target = compute_pi_block(-rmat[7], -target_pitch, hoverpitchToWPkp, hoverpitchToWPki, &pitch_error_integral, 
                                    (int16_t)(SERVO_HZ), limitintegralpitchToWP, control_position_hold);
        
        //additional_int16_export3 = -rmat[7];
                
        pitch_v_target = limit_value(pitch_v_target, -limittargetpitchV, limittargetpitchV);
        
        pitch_hover_corr = compute_pi_block(horizontal_air_speed, pitch_v_target, hoverpitchToWPvkp, 0, &pitch_v_error_integral, 
                                  (int16_t)(SERVO_HZ), limitintegralpitchVToWP, control_position_hold);
        
        //additional_int16_export8 = pitch_hover_corr;
	}
	else
	{
		pitch_hover_corr = 0;
	}

	pitch_control = pitch_hover_corr;
}
Example #26
0
int main()
{
int gd=DETECT,gm;
float y;
initgraph(&gd,&gm,0);
line(320,0,320,480);
line(0,240,640,240);
outtextxy(317,210,"-1");
outtextxy(320,240,"0");
outtextxy(317,270,"--1");
sine() ; ncos();
getch();
closegraph();
}
Example #27
0
float Oscillator::getValue() {
    switch(type) {
    case SINE:
        return sine();
    case SAW:
        return saw();
    case SQUARE:
        return square();
    case TRIANGLE:
        return triangle();
    case NOISE:
        return noise();
    }
}
/*
 * Prepare processing.
 */
int st_vibro_start(eff_t effp)
{
	vibro_t vibro = (vibro_t) effp->priv;

	vibro->length = effp->ininfo.rate / vibro->speed;
	if (! (vibro->sinetab = (short*) malloc(vibro->length * sizeof(short))))
	{
		st_fail("Vibro: Cannot malloc %d bytes",
			vibro->length * sizeof(short));
		return (ST_EOF);
	}

	sine(vibro->sinetab, vibro->length, vibro->depth);
	vibro->counter = 0;
	return (ST_SUCCESS);
}
Example #29
0
void complex_power_complex(float* d, float* s)
{
/*
=(R*exp(i(θ+2kπ))) ^ (a+ib)
=(exp(i(θ+2kπ)+lnR)) ^ (a+ib)
=exp((i(θ+2kπ)+lnR) * (a+ib))
=exp(alnR-(θ+2kπ)*b)*exp(i((θ+2kπ)*a+blnR))
=exp(alnR-(θ+2kπ)*b)*(cos((θ+2kπ)*a+blnR)+i*sin((θ+2kπ)*a+blnR))
*/
	float lnr = 0.5 * ln(d[0]*d[0] + d[1]*d[1]);
	float ang = arctan2(d[1], d[0]);
	float j = power(2.71828, s[0]*lnr - s[1]*ang);
	float k = s[0]*ang + s[1]*lnr;
	d[0] = j * cosine(k);
	d[1] = j * sine(k);
}
Example #30
0
File: math.c Project: ifbe/live
double cosine(double x)
{
	int i;
	if(x<0)x=-x;

	if(x<3.141592653/2)
	{
		i=(int)(x/(3.141592653/2)*158);
		return table[157-i];
	}
	if(x<3.141592653)
	{
		return -sine(x-3.141592653);
	}
	return 0;
}