public void Process(bool output, bool recording) { for (int i = 0; i < _trackBuffers.Length; i++) { float[] buf = _trackBuffers[i]; Array.Clear(buf, 0, buf.Length); } _audio.Clear(); for (int i = 0; i < _pcm8Channels.Length; i++) { PCM8Channel c = _pcm8Channels[i]; if (c.Owner != null) { c.Process(_trackBuffers[c.Owner.Index]); } } for (int i = 0; i < _psgChannels.Length; i++) { PSGChannel c = _psgChannels[i]; if (c.Owner != null) { c.Process(_trackBuffers[c.Owner.Index]); } } float masterStep; float masterLevel; if (_isFading && _fadeMicroFramesLeft == 0) { masterStep = 0; masterLevel = 0; } else { float fromMaster = 1f; float toMaster = 1f; if (_fadeMicroFramesLeft > 0) { const float scale = 10f / 6f; fromMaster *= (_fadePos < 0f) ? 0f : (float)Math.Pow(_fadePos, scale); _fadePos += _fadeStepPerMicroframe; toMaster *= (_fadePos < 0f) ? 0f : (float)Math.Pow(_fadePos, scale); _fadeMicroFramesLeft--; } masterStep = (toMaster - fromMaster) * _samplesReciprocal; masterLevel = fromMaster; } for (int i = 0; i < _trackBuffers.Length; i++) { if (!Mutes[i]) { float level = masterLevel; float[] buf = _trackBuffers[i]; for (int j = 0; j < SamplesPerBuffer; j++) { _audio.FloatBuffer[j * 2] += buf[j * 2] * level; _audio.FloatBuffer[(j * 2) + 1] += buf[(j * 2) + 1] * level; level += masterStep; } } } if (output) { _buffer.AddSamples(_audio.ByteBuffer, 0, _audio.ByteBufferCount); } if (recording) { _waveWriter.Write(_audio.ByteBuffer, 0, _audio.ByteBufferCount); } }
public void Process(bool output, bool recording) { for (int i = 0; i < trackBuffers.Length; i++) { float[] buf = trackBuffers[i]; Array.Clear(buf, 0, buf.Length); } audio.Clear(); for (int i = 0; i < pcm8Channels.Length; i++) { PCM8Channel c = pcm8Channels[i]; if (c.Owner != null) { c.Process(trackBuffers[c.Owner.Index]); } } for (int i = 0; i < psgChannels.Length; i++) { PSGChannel c = psgChannels[i]; if (c.Owner != null) { c.Process(trackBuffers[c.Owner.Index]); } } float fromMaster = 1f, toMaster = 1f; if (fadeMicroFramesLeft > 0) { const float scale = 10f / 6f; fromMaster *= (fadePos < 0f) ? 0f : (float)Math.Pow(fadePos, scale); fadePos += fadeStepPerMicroframe; toMaster *= (fadePos < 0f) ? 0f : (float)Math.Pow(fadePos, scale); fadeMicroFramesLeft--; } float masterStep = (toMaster - fromMaster) * samplesReciprocal; for (int i = 0; i < trackBuffers.Length; i++) { if (!Mutes[i]) { float masterLevel = fromMaster; float[] buf = trackBuffers[i]; for (int j = 0; j < SamplesPerBuffer; j++) { audio.FloatBuffer[j * 2] += buf[j * 2] * masterLevel; audio.FloatBuffer[(j * 2) + 1] += buf[(j * 2) + 1] * masterLevel; masterLevel += masterStep; } } } if (output) { buffer.AddSamples(audio.ByteBuffer, 0, audio.ByteBufferCount); } if (recording) { waveWriter.Write(audio.ByteBuffer, 0, audio.ByteBufferCount); } }