예제 #1
0
        public AudioBufferInfo(int count, AudioBufferInfo parentBuffer)
        {
            // Create child from existing parent buffers
            Count = count;

            Raw     = new float *[count];
            Buffers = new VstAudioBuffer[count];

            // Point to parent
            for (int i = 0; i < count; i++)
            {
                Buffers[i] = parentBuffer.Buffers[i];
                Raw[i]     = parentBuffer.Raw[i];
            }
        }
예제 #2
0
        public unsafe void asioThread()
        {
            if (mSettingsMgr.Settings.MidiInDeviceNumbers == null)
            {
                mSettingsMgr.Settings.MidiInDeviceNumbers = new List <int>();
            }
            for (int i = 0; i < mSettingsMgr.Settings.MidiInDeviceNumbers.Count(); i++)
            {
                mMidiDevice.OpenInPort(mSettingsMgr.Settings.MidiInDeviceNumbers[i]);
            }

            try
            {
#if NAUDIO_ASIO
                mAsio = new NAudio.Wave.AsioOut(mSettingsMgr.Settings.AsioDeviceNr);
#else
                mAsio = AsioDriver.SelectDriver(AsioDriver.InstalledDrivers[mSettingsMgr.Settings.AsioDeviceNr]);
#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (mAsio != null)
            {
#if NAUDIO_ASIO
                if (mAsio != null)
                {
                    mWaveProvider = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat(44100, 16, 2));
                    mAsio.InitRecordAndPlayback(mWaveProvider, 2, 44100);
                    mAsio.AudioAvailable += mAsio_AudioAvailable;
                    mAsioBuffSize         = mSettingsMgr.Settings.AsioBufferSize;
                }
#else
                int p   = mAsio.BufferSizex.PreferredSize;
                int max = mAsio.BufferSizex.MaxSize;
                int min = mAsio.BufferSizex.MinSize;

                if (mSettingsMgr.Settings.AsioBufferSize < min)
                {
                    mSettingsMgr.Settings.AsioBufferSize = min;
                    mSettingsMgr.SaveSettings();
                }

                if (mSettingsMgr.Settings.AsioBufferSize > max)
                {
                    mSettingsMgr.Settings.AsioBufferSize = max;
                    mSettingsMgr.SaveSettings();
                }
                mAsioBuffSize = mSettingsMgr.Settings.AsioBufferSize;

                // get our driver wrapper to create its buffers
                mAsio.CreateBuffers(mAsioBuffSize);
                // this is our buffer fill event we need to respond to
                mAsio.BufferUpdate += new EventHandler(asio_BufferUpdateHandler);
                mAsioOutputLeft     = mAsio.OutputChannels[0];  // Use only 1x stereo out
                mAsioOutputRight    = mAsio.OutputChannels[1];

                mAsioInputBuffers = new AudioBufferInfo(2, mAsioBuffSize);
                mAsioInputLeft    = mAsio.InputChannels[0];     // Use only 1x stereo in
                mAsioInputRight   = mAsio.InputChannels[1];
#endif
                // todo: test
                //mMixLeft = new float[mAsioBuffSize];
                //mMixRight = new float[mAsioBuffSize];

                // and off we go

                stopWatchTicksForOneAsioBuffer = (long)(Stopwatch.Frequency / (mAsio.SampleRate / mAsioBuffSize));
#if NAUDIO_ASIO
                mAsioLeftInt32LSBBuff  = new byte[mAsioBuffSize * 4];
                mAsioRightInt32LSBBuff = new byte[mAsioBuffSize * 4];
                mAsio.Play();
#else
                mAsio.Start();
#endif
                mAsioStartEvent.Set();

                // Keep running untill stop request!
                mAsioStopEvent.Wait();
                StopAsio();
            }
            else
            {
                mIsAsioRunning = false;
                mAsioStartEvent.Set();
            }
        }