/// <summary>
        /// driver buffer update callback to fill the wave buffer.
        /// </summary>
        /// <param name="inputChannels">The input channels.</param>
        /// <param name="outputChannels">The output channels.</param>
        void driver_BufferUpdate(IntPtr[] inputChannels, IntPtr[] outputChannels)
        {
            if (this.NumberOfOutputChannels > 0)
            {
                int read = sourceStream.Read(waveBuffer, 0, waveBuffer.Length);
                if (read < waveBuffer.Length)
                {
                    // we have stopped
                }
                // Call the convertor
                unsafe
                {
                    // TODO : check if it's better to lock the buffer at initialization?
                    fixed(void *pBuffer = &waveBuffer[0])
                    {
                        convertor(new IntPtr(pBuffer), outputChannels, NumberOfOutputChannels, nbSamples);
                    }
                }

                if (read == 0)
                {
                    // do not call stop from inside, or the asioOut will not be disposed and never return error
                    // raising the auto stop from outside
                    RaisePlaybackStopped(null);
                }
            }
            if (AudioAvailable != null)
            {
                var args = new MyAsioAudioAvailableEventArgs(inputChannels, outputChannels, nbSamples, driver.Capabilities.InputChannelInfos[0].type, driver.Capabilities.OutputChannelInfos[0].type);
                AudioAvailable(this, args);
            }
        }
예제 #2
0
 private void AudioAvailable(object sender, MyAsioAudioAvailableEventArgs e)
 {
     if (asioWriter != null)
     {
         var floatsamples = new float[e.SamplesPerBuffer * (desiredInputChannels.Length + desiredOutputChannels.Length)];
         e.GetAsInterleavedCombinedSamples(floatsamples, desiredInputChannels, desiredOutputChannels);
         asioWriter.WriteSamples(floatsamples, 0, floatsamples.Length);
         asioWriter.Flush();
     }
 }