// // compressor runtime process public void Process(ref double in1, ref double in2) { // sidechain // rectify input double rect1 = Math.Abs(in1); // n.b. was fabs double rect2 = Math.Abs(in2); // n.b. was fabs // if desired, one could use another EnvelopeDetector to smooth // the rectified signal. double link = Math.Max(rect1, rect2); // link channels with greater of 2 link += DC_OFFSET; // add DC offset to avoid log( 0 ) double keydB = Decibels.LinearToDecibels(link); // convert linear -> dB // threshold double overdB = keydB - Threshold; // delta over threshold if (overdB < 0.0) { overdB = 0.0; } // attack/release overdB += DC_OFFSET; // add DC offset to avoid denormal Run(overdB, ref envdB); // run attack/release envelope overdB = envdB - DC_OFFSET; // subtract DC offset // Regarding the DC offset: In this case, since the offset is added before // the attack/release processes, the envelope will never fall below the offset, // thereby avoiding denormals. However, to prevent the offset from causing // constant gain reduction, we must subtract it from the envelope, yielding // a minimum value of 0dB. // transfer function double gr = overdB * (Ratio - 1.0); // gain reduction (dB) gr = Decibels.DecibelsToLinear(gr) * Decibels.DecibelsToLinear(MakeUpGain); // convert dB -> linear // output gain in1 *= gr; // apply gain reduction to input in2 *= gr; }
public void Process(ref double in1, ref double in2) { double arg_10_0 = Math.Abs(in1); double val = Math.Abs(in2); double num = Decibels.LinearToDecibels(Math.Max(arg_10_0, val) + 1E-25) - this.Threshold; if (num < 0.0) { num = 0.0; } num += 1E-25; base.Run(num, ref this.envdB); num = this.envdB - 1E-25; double num2 = num * (this.Ratio - 1.0); num2 = Decibels.DecibelsToLinear(num2) * Decibels.DecibelsToLinear(this.MakeUpGain); in1 *= num2; in2 *= num2; }
public void compressSample(ref float sample) { double doubleSample = Convert.ToDouble(Math.Abs(sample)); //returns absolute value for sample and converts to double to account for decibel conversion doubleSample = Decibels.LinearToDecibels(doubleSample); // convert to Decibels float dBOverLimit = (float)doubleSample + Threshold; //figure out how many decibels over limit the sample is if (dBOverLimit > 0.0f) // if over the threshold then apply the compression ratio to the sample { float gainReduction = -dBOverLimit * (Ratio - 1.0f); gainReduction = (float)Decibels.DecibelsToLinear(gainReduction); sample *= gainReduction; } else // if under threshold then leave the sample be { } }
protected override void SetOutputs(int i, FFTOutSignal instance) { if (instance != null) { // var spreadComplex = FFFTOutComplex[i]; var spread = FFFTOut[i]; double[] fftData = instance.FFTOut; if (fftData != null) { if (spread == null) { spread = new Spread <double>(fftData.Length); } // if (spreadComplex == null) // { // spreadComplex = new Spread<double>(val.Length); // } var halfSize = fftData.Length / 2; spread.SliceCount = halfSize; spread[0] = 0; var nn = 2; for (int n = 1; n < halfSize; n++) { var real = fftData[nn++]; var imag = fftData[nn++]; spread[n] = Decibels.LinearToDecibels(Math.Max(Math.Sqrt(real * real + imag * imag), FMindB)) / FdBRange[i] + 1; } // spreadComplex.SliceCount = val.Length; // spreadComplex.AssignFrom(val); } } else { FFFTOut[i].SliceCount = 0; } }
// Token: 0x0600036F RID: 879 RVA: 0x0000BC7C File Offset: 0x00009E7C public void Process(ref double in1, ref double in2) { double val = Math.Abs(in1); double val2 = Math.Abs(in2); double num = Math.Max(val, val2); num += 1E-25; double num2 = Decibels.LinearToDecibels(num); double num3 = num2 - this.Threshold; if (num3 < 0.0) { num3 = 0.0; } num3 += 1E-25; base.Run(num3, ref this.envdB); num3 = this.envdB - 1E-25; double num4 = num3 * (this.Ratio - 1.0); num4 = Decibels.DecibelsToLinear(num4) * Decibels.DecibelsToLinear(this.MakeUpGain); in1 *= num4; in2 *= num4; }
private void Compress(float[,] samples, int sampleCount, float thresholddB, float ratio, float makeupGaindB) { const int threadCount = 512; var makeupGainLin = Decibels.ToLinear(makeupGaindB); AllocateGpuResources(sampleCount); var devOverdBs = m_DevOverdBs; Gpu.Launch(threadCount, 1).GetOverDecibels(samples, thresholddB, devOverdBs); var overdBs = new float[sampleCount]; Gpu.CopyFromDevice(devOverdBs, overdBs); // This bit is serial, can't be done on GPU for (int i = 0; i < sampleCount; i++) { // attack/release var overdB = overdBs[i]; // assumes that: // positive delta = attack // negative delta = release // good for linear & log values if (overdB > m_EnvdB) { m_Attack.Run(overdB, ref m_EnvdB); // attack } else { m_Release.Run(overdB, ref m_EnvdB); // release } overdBs[i] = m_EnvdB; } Gpu.CopyToDevice(overdBs, devOverdBs); Gpu.Launch(threadCount, 1).ApplyGains(samples, devOverdBs, ratio, makeupGainLin); }
private void osc3Gain_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { osc3.Gain = Decibels.DecibelsToLinear(e.NewValue); InitMixer(); }
private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { wave.Gain = Decibels.DecibelsToLinear(e.NewValue); }
// Calcul TaskBar to Gain private void tbToGain() { lblGain.Text = tbGain.Value.ToString(); wg.Gain = Decibels.DecibelsToLinear(tbGain.Value); }
private void CalculateTrackBarToGain() { lblGain.Text = tbGain.Value.ToString(); wg.Gain = Decibels.DecibelsToLinear(tbGain.Value); }