void PrepareFloatBuffers(int bufferSize) { var deviceBufferSize = (int)(AudioSession.CurrentHardwareSampleRate * AudioSession.CurrentHardwareIOBufferDuration + 0.5f); Console.WriteLine("Prepare buffers: {0}, deviceBuffer: {1}, latency: {2}, {3}", bufferSize, deviceBufferSize, AudioSession.CurrentHardwareOutputLatency, AudioSession.CurrentHardwareOutputLatency * AudioSession.CurrentHardwareSampleRate); if (_sampleBuffer != null) { _sampleBuffer.Dispose(); } var numChannels = _numInputChannels + _numOutputChannels; if (numChannels > 0) { _sampleBuffer = new SampleBuffer(numChannels, bufferSize); for (var i = 0; i < _numInputChannels; ++i) { _inputChannels[i] = _sampleBuffer.GetPointer(i); } for (var i = 0; i < _numOutputChannels; ++i) { _outputChannels[i] = _sampleBuffer.GetPointer(i + _numInputChannels); } } }
public BufferPool(int samplesPerBlock, double sampleRate) { Console.WriteLine("Initializing buffer pool: samples:{0} sampleRate:{1}", samplesPerBlock, sampleRate); Env1Buffer = new SampleBuffer(1, samplesPerBlock); GainAmpBuffer = new SampleBuffer(new float *[3], 3, samplesPerBlock); GainAmpBuffer.Channels[0] = Env1Buffer.GetPointer(); }
private void TestBuffer(SampleBuffer buffer, int startSample, int numSamples) { for (int i = startSample; i < startSample + numSamples; i++) { if (buffer.Channels[0][i] > 0) { LOG.Debug("Sample > 0 found"); break; } } }
protected override void DisposeManagedResources() { if (Device != null) { Device.Dispose(); Device = null; } if (_tempBuffer != null) { _tempBuffer.Dispose(); _tempBuffer = null; } }
public AudioDeviceManager(AudioIODeviceFactory deviceFactory, AudioDeviceSetup setup) { var audioIODevice = deviceFactory.CreateDevice(); audioIODevice.Open( setup.NumInputChannels, setup.NumOutputChannels, setup.SampleRate, setup.BufferSize ); Device = audioIODevice; Device.Start(this); _tempBuffer = new SampleBuffer(1, 1); }
public AudioSourceChannelInfo(SampleBuffer buffer, int startSample, int numSamples) { Buffer = buffer; StartSample = startSample; NumSamples = numSamples; }
public void GetNextAudioBlock(SampleBuffer buffer, int start, int length) { var dest = buffer.GetPointer(0, start); var bufferNote = _sequencer.GetBufferNote(); if (_state != State.RELEASING && (!bufferNote.IsValid || bufferNote.Start > length)) { Memory.ZeroMem <float>(dest, length); return; } var bufferPos = 0; while (bufferPos < length) { if (bufferNote.IsTriggered(bufferPos)) { LOG.Debug("Trigger"); _state = State.ATTACKING; } else if (!bufferNote.IsPlaying(bufferPos) && _state != State.IDLE) { if (_state != State.RELEASING) { LOG.Debug("Start Release"); } _state = State.RELEASING; } switch (_state) { case State.IDLE: _level = 0; break; case State.ATTACKING: _level = _attackBase + _level * _attackCoef; if (_level >= 1.0f) { _level = 1.0f; _state = State.DECAYING; LOG.Debug("Start Decay"); } break; case State.DECAYING: _level = _decayBase + _level * _decayCoef; if (_level <= Sustain) { _level = Sustain; _state = State.SUSTAINING; LOG.Debug("Start Sustain"); } break; case State.RELEASING: _level = _releaseBase + _level * _releaseCoef; if (_level < DB90) { _level = 0; _state = State.IDLE; LOG.Debug("Start Idle"); } break; // default: // break; } dest[bufferPos++] = _level; // if (bufferPos > bufferNote.End) // { // bufferNote = _sequencer.GetBufferNote(bufferPos); // if (bufferNote.Start > length) // { // Memory.ZeroMem(dest + bufferPos, length - bufferPos); // return; // } // } } }