public void FillBuffer(float[] SampleBuffer, int SampleRate, int Offset) { if (SampleBuffer.Length != bufferSize) { throw new InvalidOperationException("Unexpected buffer size."); } if (Carrier) { AmplitudeSource.FillBuffer(amplitudeBuffer, SampleRate, Offset / 2); PitchSource.FillBuffer(pitchBuffer, SampleRate, Offset / 2); for (int ii = 0; ii < PitchModulators.Length; ii++) { PitchModulators[ii].FillBuffer(pitchModulatorBuffers[ii], SampleRate, Offset / 2); } for (int i = 0; i < SampleBuffer.Length; i += 2) { float frequency = pitchBuffer[i / 2] * PitchMultiplier; //Console.WriteLine(frequency); /*if (frequency < 110) * { * Console.WriteLine("bruh"); * }*/ float modulation = 0F; for (int ii = 0; ii < PitchModulators.Length; ii++) { modulation += pitchModulatorBuffers[ii][i / 2]; } float sample = WaveformSource.GetSample(frequency, SampleRate, (Offset / 2) + (i / 2), modulation) * amplitudeBuffer[i / 2] * Volume; SampleBuffer[i] = sample * LVolume; SampleBuffer[i + 1] = sample * RVolume; } } else { AmplitudeSource.FillBuffer(amplitudeBuffer, SampleRate, Offset); PitchSource.FillBuffer(pitchBuffer, SampleRate, Offset); for (int ii = 0; ii < PitchModulators.Length; ii++) { PitchModulators[ii].FillBuffer(pitchModulatorBuffers[ii], SampleRate, Offset); } for (int i = 0; i < SampleBuffer.Length; i++) { float frequency = pitchBuffer[i] * PitchMultiplier; float modulation = 0F; for (int ii = 0; ii < PitchModulators.Length; ii++) { modulation += pitchModulatorBuffers[ii][i]; } float sample = WaveformSource.GetSample(frequency, SampleRate, Offset + i, modulation) * amplitudeBuffer[i] * Volume; SampleBuffer[i] = sample; } } }
private void writeNextSamples() { Input.FillBuffer(buf, 44100, position); Buffer.BlockCopy(buf, 0, stdOutBuf, 0, stdOutBuf.Length); position += stdOutBuf.Length / 4; absPosition += stdOutBuf.Length / 4; standardOut.Write(stdOutBuf, 0, stdOutBuf.Length); }
public float Multiplier = 1F; // Multiply input before shaping. public void FillBuffer(float[] SampleBuffer, int SampleRate, int Offset) { input.FillBuffer(SampleBuffer, SampleRate, Offset); for (int i = 0; i < SampleBuffer.Length; i++) { float sample = SampleBuffer[i] * Multiplier; if (sample <= 0) { SampleBuffer[i] = (float)-Math.Sqrt(1 - Math.Pow(sample + 1, Hardness)); } else { SampleBuffer[i] = (float)Math.Sqrt(1 - Math.Pow(1 - sample, Hardness)); } } }
public void FillBuffer(float[] SampleBuffer, int SampleRate, int Offset) { input.FillBuffer(SampleBuffer, SampleRate, Offset); if (Offset == 0) { lastOutput = SampleBuffer[0]; } float RC = 1F / (CutoffFrequency * 2 * (float)Math.PI); float dt = 1F / SampleRate; float alpha = dt / (RC + dt); for (int i = 0; i < SampleBuffer.Length; i++) { lastOutput = lastOutput + (alpha * (SampleBuffer[i] - lastOutput)); SampleBuffer[i] = lastOutput; } }