public VstPluginChannel(int asioBuffSize) { // Create big enough buffers to fit all plugin types int inSize = 32; int outSize = 64; if (asioBuffSize != 0) { if (InputBuffers == null || inSize != InputBuffers.Count) { InputBuffers = null; // Dispose first if already existed! InputBuffers = new AudioBufferInfo(inSize, asioBuffSize); } if (OutputBuffers == null || outSize != OutputBuffers.Count) { OutputBuffers = null; // Dispose first if already existed! OutputBuffers = new AudioBufferInfo(outSize, asioBuffSize); } } InstrumentPlugin = new VstInstrumentPlugin(InputBuffers, OutputBuffers, asioBuffSize); EffectPlugins = new VstPlugin[NumberOfEffectPlugins]; for (int i = 0; i < NumberOfEffectPlugins; i++) { EffectPlugins[i] = new VstPlugin(InputBuffers, OutputBuffers, asioBuffSize, true); } }
public VstPlugin(AudioBufferInfo parentInBuffers, AudioBufferInfo parentOutBuffers, int asioBuffSize, bool dbg) { dbgIsEffect = dbg; mParentInBuffers = parentInBuffers; mParentOutBuffers = parentOutBuffers; mAsioBuffSize = asioBuffSize; }
public void AttachVstPluginContext(VstPluginContext ctx, string name) { mVstPluginContext = ctx; // Create big enough buffers to fit all plugin types int inSize = 32; // value.PluginInfo.AudioInputCount; int outSize = 64; // value.PluginInfo.AudioOutputCount; if (mAsioBuffSize != 0) { if (InputBuffers == null || inSize != InputBuffers.Count) { InputBuffers = null; // Dispose first if already existed! InputBuffers = new AudioBufferInfo(inSize, mParentInBuffers); } if (OutputBuffers == null || outSize != OutputBuffers.Count) { OutputBuffers = null; // Dispose first if already existed! OutputBuffers = new AudioBufferInfo(outSize, mParentOutBuffers); } } ctx.PluginCommandStub.MainsChanged(true); ctx.PluginCommandStub.StartProcess(); State = PluginState.Deactivated; PluginName = name; ProgramName = ctx.PluginCommandStub.GetProgramName(); UseExtendedEffectRange = (PluginName == "Nexus"); }
public VstInstrumentPlugin(AudioBufferInfo parentInBuffers, AudioBufferInfo parentOutBuffers, int asioBuffSize) : base(parentInBuffers, parentOutBuffers, asioBuffSize, false) { for (int i = 0; i < 256; i++) { Notes[i] = new Note(); } }
protected void BufferReady(byte[] data) { AudioBufferInfo abuf = new AudioBufferInfo(); abuf.Data = data; abuf.Format = fmt; Emit(abuf); }
protected override void PlayBuffer(AudioBufferInfo buffer) { Sapi4Engine.miniLog("entering PlayBuffer"); Buffers.Enqueue(buffer.Data); int pos = 0; if (Buffers.Count < 1) { return; } else { Sapi4Engine.miniLog("at PlayBuffer"); int length = 0; bool destEof = false; do { audioDest.FreeSpace(ref length, ref destEof); Sapi4Engine.miniLog(String.Format("{0} bytes. eof: {1}", length, destEof)); if (!destEof) { int copied = 0; while ((copied < length) && (Buffers.Count > 0)) { byte[] buf = Buffers.Peek(); int toCopy = length - copied; int availCopy = Math.Min(buf.Length - bufPos, toCopy); IntPtr pmem = Marshal.AllocCoTaskMem(availCopy); Marshal.Copy(buf, bufPos, pmem, availCopy); Sapi4Engine.miniLog("before DataSet"); audioDest.DataSet(pmem, availCopy); Marshal.FreeCoTaskMem(pmem); Sapi4Engine.miniLog("after DataSet"); //System.Buffer.BlockCopy(buf, bufPos, buffer, pos, availCopy); copied += availCopy; bufPos += availCopy; pos += availCopy; if (bufPos >= buf.Length) { Buffers.Dequeue(); bufPos = 0; } } audioDest.FreeSpace(ref length, ref destEof); Sapi4Engine.miniLog(String.Format("second round {0} bytes. eof: {1}", length, destEof)); } System.Threading.Thread.Sleep(0); }while ((Buffers.Count > 0) && (destEof || (length == 0))); } Sapi4Engine.miniLog("leaving PlayBuffer"); }
protected void OnGetBuffer(AudioBufferInfo audioBufferInfo) => HandleBuffer?.Invoke(this, audioBufferInfo);