public override void GetNextAudioBlock(ref AudioSourceChannelInfo bufferToFill) { var amplitude = _amplitude; var frequency = _frequency; var phasePerSample = (2.0f * frequency) / _sampleRate; var currentPhase = _currentPhase; var channels = bufferToFill.Buffer.Channels; var numSamples = bufferToFill.NumSamples; for (var i = 0; i < numSamples; ++i) { var sample = amplitude * (float)Math.Sin(currentPhase * (float)Math.PI); for (var j = bufferToFill.Buffer.NumChannels; --j >= 0;) { channels[j][bufferToFill.StartSample + i] = sample; } currentPhase += phasePerSample; if (currentPhase > 1) { currentPhase -= 2; } } _currentPhase = currentPhase; }
public override void GetNextAudioBlock(ref AudioSourceChannelInfo bufferToFill) { foreach (var item in _chain) { item.GetNextAudioBlock(ref bufferToFill); } }
public AudioSourceChannelInfo SetupGainBuffer(ref AudioSourceChannelInfo bufferToFill) { for (var channel = 0; channel < bufferToFill.Buffer.NumChannels; ++channel) { GainAmpBuffer.Channels[channel + 1] = bufferToFill.Buffer.Channels[channel]; } return(new AudioSourceChannelInfo(GainAmpBuffer, bufferToFill.StartSample, bufferToFill.NumSamples)); }
public void GetNextAudioBlock(ref AudioSourceChannelInfo bufferToFill) { // commit commands from the ui _beatSeqencer.Sequencer.StartFrame(_sampleTime); _env1.GetNextAudioBlock(_bufferPool.Env1Buffer, bufferToFill.StartSample, bufferToFill.NumSamples); // TestBuffer(_bufferPool.Env1Buffer, bufferToFill.StartSample, bufferToFill.NumSamples); _generator.GetNextAudioBlock(ref bufferToFill); // TestBuffer(bufferToFill.Buffer, bufferToFill.StartSample, bufferToFill.NumSamples); var gainChannelInfo = _bufferPool.SetupGainBuffer(ref bufferToFill); _gainAmp.GetNextAudioBlock(ref gainChannelInfo); _sampleTime += bufferToFill.NumSamples; }
public void AudioDeviceIOCallback(float *[] inputChannelData, int numInputChannels, float *[] outputChannelData, int numOutputChannels, int numSamples) { if (_source != null) { if (numInputChannels > numOutputChannels) { throw new NotImplementedException(); } var numActiveChans = 0; var channelSize = numSamples * sizeof(float); for (var i = 0; i < numInputChannels; ++i) { _channels[numActiveChans] = outputChannelData[i]; Memory.MemCopy(_channels[numActiveChans], inputChannelData[i], channelSize); ++numActiveChans; } for (var i = 0; i < numOutputChannels; ++i) { _channels[numActiveChans] = outputChannelData[i]; Memory.ZeroMem <float>(_channels[numActiveChans], numSamples); ++numActiveChans; } _renderBuffer.Wrap(_channels, numActiveChans, numSamples); var info = new AudioSourceChannelInfo(_renderBuffer, 0, numSamples); _source.GetNextAudioBlock(ref info); for (var i = 0; i < numOutputChannels; ++i) { SIMD.Mul(outputChannelData[i], _gain, outputChannelData[i], numSamples); } } else { for (var i = 0; i < numOutputChannels; ++i) { Memory.ZeroMem <float>(outputChannelData[i], numSamples); } } }
public void GetNextAudioBlock(ref AudioSourceChannelInfo bufferToFill) { var buffer = bufferToFill.Buffer; for (var i = 1; i < buffer.NumChannels; ++i) { // for (var j = 0; j < bufferToFill.NumSamples; ++j) // { // buffer.Channels[i][bufferToFill.StartSample + j] *= buffer.Channels[0][bufferToFill.StartSample + j]; // } SIMD.Mul( buffer.GetPointer(0, bufferToFill.StartSample), buffer.GetPointer(i, bufferToFill.StartSample), buffer.GetPointer(i, bufferToFill.StartSample), bufferToFill.NumSamples ); } }
public abstract void GetNextAudioBlock(ref AudioSourceChannelInfo bufferToFill);