/// <summary> /// Creates the buffers for playing. /// </summary> /// <param name="numberOfOutputChannels">The number of outputs channels.</param> /// <param name="numberOfInputChannels">The number of input channel.</param> /// <param name="useMaxBufferSize">if set to <c>true</c> [use max buffer size] else use Prefered size</param> public int CreateBuffers(int numberOfOutputChannels, int numberOfInputChannels, bool useMaxBufferSize) { if (numberOfOutputChannels < 0 || numberOfOutputChannels > capability.NbOutputChannels) { throw new ArgumentException(String.Format( "Invalid number of channels {0}, must be in the range [0,{1}]", numberOfOutputChannels, capability.NbOutputChannels)); } if (numberOfInputChannels < 0 || numberOfInputChannels > capability.NbInputChannels) { throw new ArgumentException("numberOfInputChannels", String.Format("Invalid number of input channels {0}, must be in the range [0,{1}]", numberOfInputChannels, capability.NbInputChannels)); } // each channel needs a buffer info this.numberOfOutputChannels = numberOfOutputChannels; this.numberOfInputChannels = numberOfInputChannels; // Ask for maximum of output channels even if we use only the nbOutputChannelsArg int nbTotalChannels = capability.NbInputChannels + capability.NbOutputChannels; bufferInfos = new ASIOBufferInfo[nbTotalChannels]; currentOutputBuffers = new IntPtr[numberOfOutputChannels]; currentInputBuffers = new IntPtr[numberOfInputChannels]; // and do the same for output channels // ONLY work on output channels (just put isInput = true for InputChannel) int totalIndex = 0; for (int index = 0; index < capability.NbInputChannels; index++, totalIndex++) { bufferInfos[totalIndex].isInput = true; bufferInfos[totalIndex].channelNum = index; bufferInfos[totalIndex].pBuffer0 = IntPtr.Zero; bufferInfos[totalIndex].pBuffer1 = IntPtr.Zero; } for (int index = 0; index < capability.NbOutputChannels; index++, totalIndex++) { bufferInfos[totalIndex].isInput = false; bufferInfos[totalIndex].channelNum = index; bufferInfos[totalIndex].pBuffer0 = IntPtr.Zero; bufferInfos[totalIndex].pBuffer1 = IntPtr.Zero; } if (useMaxBufferSize) { // use the drivers maximum buffer size bufferSize = capability.BufferMaxSize; } else { // use the drivers preferred buffer size bufferSize = capability.BufferPreferredSize; } unsafe { fixed(ASIOBufferInfo *infos = &bufferInfos[0]) { IntPtr pOutputBufferInfos = new IntPtr(infos); // Create the ASIO Buffers with the callbacks driver.createBuffers(pOutputBufferInfos, nbTotalChannels, bufferSize, ref callbacks); } } // Check if outputReady is supported isOutputReadySupported = (driver.outputReady() == ASIOError.ASE_OK); return(bufferSize); }