private CPX Scale(CPX cpx, float value) { cpx.real *= value; cpx.imag *= value; return(cpx); }
private float GetMagnitude(CPX cpx) { return((float)Math.Sqrt(cpx.real * cpx.real + cpx.imag * cpx.imag)); //if (Math.Abs(cpx.real) > Math.Abs(cpx.imag)) // return (float) (Math.Abs(cpx.real) + 0.4 * Math.Abs(cpx.imag)); //else // return (float) (Math.Abs(cpx.imag) + 0.4 * Math.Abs(cpx.real)); }
public static CPX[] ToCPX(float[] real, float[] imag) { CPX[] mycpx = new CPX[real.Length]; for (int i = 0; i < real.Length; i++) { mycpx[i].real = real[i]; mycpx[i].imag = imag[i]; } return(mycpx); }
private CPX DoFir(CPX input, int ntaps, CPX[] h, CPX[] z) { CPX accum; accum.real = 0f; accum.imaginary = 0f; z[state] = z[state + ntaps] = input; for (int i = 0; i < ntaps; i++) { accum.real += h[i].real * z[state + i].real; accum.imaginary += h[i].imaginary * z[state + i].imaginary; } if (--state < 0) { state += ntaps; } return(accum); }
public void Write(CPX data) { buffer[writePos] = data; writePos = (writePos + 1) % size; }
public void WcpAGC() { CPX[] buff = this.d.cpx; int i, j, k; double mult; for (i = 0; i < this.s.DSPBlockSize; i++) { if (++out_index >= ring_buffsize) { out_index -= ring_buffsize; } if (++in_index >= ring_buffsize) { in_index -= ring_buffsize; } out_sample = ring[out_index]; abs_out_sample = abs_ring[out_index]; ring[in_index] = buff[i]; abs_ring[in_index] = Math.Max(Math.Abs(ring[in_index].real), Math.Abs(ring[in_index].imaginary)); fast_backaverage = fast_backmult * abs_out_sample + onemfast_backmult * fast_backaverage; hang_backaverage = hang_backmult * abs_out_sample + onemhang_backmult * hang_backaverage; if ((abs_out_sample >= ring_max) && (abs_out_sample > 0)) { ring_max = 0.0; k = out_index; for (j = 0; j < attack_buffsize; j++) { if (++k == ring_buffsize) { k = 0; } if (abs_ring[k] > ring_max) { ring_max = abs_ring[k]; } } } if (abs_ring[in_index] > ring_max) { ring_max = abs_ring[in_index]; } if (hang_counter > 0) { --hang_counter; } switch (state) { case 0: { if (ring_max >= volts) { volts += (ring_max - volts) * attack_mult; } else { if (volts > pop_ratio * fast_backaverage) { state = 1; volts += (ring_max - volts) * fast_decay_mult; } else { if (hang_backaverage > hang_level) { state = 2; hang_counter = (int)(hangtime * sample_rate); decay_type = 1; } else { state = 3; volts += (ring_max - volts) * decay_mult; decay_type = 0; } } } break; } case 1: { if (ring_max >= volts) { state = 0; volts += (ring_max - volts) * attack_mult; } else { if (volts > save_volts) { volts += (ring_max - volts) * fast_decay_mult; } else { if (hang_counter > 0) { state = 2; } else { if (decay_type == 0) { state = 3; volts += (ring_max - volts) * decay_mult; } else { state = 4; volts += (ring_max - volts) * hang_decay_mult; } } } } break; } case 2: { if (ring_max >= volts) { state = 0; save_volts = volts; volts += (ring_max - volts) * attack_mult; } else { if (hang_counter == 0) { state = 4; volts += (ring_max - volts) * hang_decay_mult; } } break; } case 3: { if (ring_max >= volts) { state = 0; save_volts = volts; volts += (ring_max - volts) * attack_mult; } else { volts += (ring_max - volts) * decay_mult; } break; } case 4: { if (ring_max >= volts) { state = 0; save_volts = volts; volts += (ring_max - volts) * attack_mult; } else { volts += (ring_max - volts) * hang_decay_mult; } break; } } // end switch on state if (volts < min_volts) { volts = min_volts; } mult = (out_target - slope_constant * Math.Min(0.0, Math.Log10(inv_max_input * volts))) / volts; buff[i].real = (float)(out_sample.real * mult); buff[i].imaginary = (float)(out_sample.imaginary * mult); } }