/// <summary> /// Called when a buffer update is required /// </summary> private static void AsioDriver_BufferUpdate(object sender, EventArgs e) { // the driver is the sender AsioDriver driver = sender as AsioDriver; // increment the delay buffer counter _counter++; // and wrap if nede be if (_counter >= 100) { _counter = 0; } // get the input channel and the stereo output channels Channel input = driver.InputChannels[0]; Channel leftOutput = driver.OutputChannels[0]; Channel rightOutput = driver.OutputChannels[1]; for (int index = 0; index < leftOutput.BufferSize; index++) { // copy the input buffer to our delay array _delayBuffer[index, _counter] = input[index]; // and copy from the delay array to the output buffers (wrapping as needed) leftOutput[index] = _delayBuffer[index, (_counter - _leftDelay) >= 0 ? _counter - _leftDelay : _counter - _leftDelay + MaxBuffers]; rightOutput[index] = _delayBuffer[index, (_counter - _rightDelay) >= 0 ? _counter - _rightDelay : _counter - _rightDelay + MaxBuffers]; } }
public ASIO(InstalledDriver instdriver, int[] InputChannels, int[] OutputChannels, int QueueDepth = DefaultQueueDepth) { System.Diagnostics.Debug.WriteLine("ASIO driver: {0}", instdriver); driver = AsioDriver.SelectDriver(instdriver); driver.BufferUpdate += new EventHandler(AsioDriver_BufferUpdate); System.Diagnostics.Debug.WriteLine("Version: {0}", driver.Version); System.Diagnostics.Debug.WriteLine("In: {0}; Out: {1}", driver.NumberInputChannels, driver.NumberOutputChannels); Init(); foreach(int ch_ind in InputChannels){ if (ch_ind < driver.NumberInputChannels && ch_ind >= 0) { inputChannels.Add(driver.InputChannels[ch_ind]); sampleBuffersIn.Add(new CircularBuffer<double>(QueueDepth, true)); } } foreach (int ch_ind in OutputChannels) { if (ch_ind < driver.NumberOutputChannels && ch_ind >= 0) { outputChannels.Add(driver.OutputChannels[ch_ind]); sampleBuffersOut.Add(new CircularBuffer<double>(QueueDepth, true)); } } }
public static void DSP_process(object sender, EventArgs e) { // System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest; AsioDriver driver = (AsioDriver)sender; Channel input = driver.InputChannels[0]; Channel leftOutput = driver.OutputChannels[0]; Channel rightOutput = driver.OutputChannels[1]; // temporary Effect stack // Effect[] tem_Effects1 = new Effect[sys.MaxEffectStackSize]; //sys.mainGUI.listBox1.Items.CopyTo(tem_Effects1,0); for (int i = 0; i < sys.no_of_effects; i++) { ((Effect)sys.mainGUI.listBox1.Items[i]).process(input, leftOutput, rightOutput); } for (int i = 0; i < input.BufferSize; i++) { leftOutput[i] = input[i]; rightOutput[i] = input[i]; } }
/// <summary> /// デバイス情報を列挙する /// </summary> /// <returns></returns> public static List <AsioDeviceInfo> EnumerateDevices() => ThreadManager.DeviceDispatcher.Invoke(() => { return(AsioDriver.GetAsioDriverNames() .Select(d => new AsioDeviceInfo(d)) .ToList()); });
private static void Raise_DriverLoaded(AsioDriver driver) { EventHandler<DriverLoadedEventArgs> h = DriverLoaded; if (h == null) return; h(null, new DriverLoadedEventArgs(driver)); }
/// <summary> /// Called when a buffer update is required /// </summary> private static void AsioDriver_BufferUpdate(object sender, EventArgs e) { // every time called, update the entire output buffer. // each buffer is going to be 2.902 ms long (for 128 sample buffer size) // the driver is the sender AsioDriver driver = sender as AsioDriver; // get the input channel and the stereo output channels Channel input = driver.InputChannels[1]; Channel leftOutput = driver.OutputChannels[0]; Channel rightOutput = driver.OutputChannels[1]; // call the appropriate effect function if (effectType == effect.none) noEffect(input, leftOutput, rightOutput); else if (effectType == effect.delay) delayEffect(input, leftOutput, rightOutput); else if (effectType == effect.flanger) flangeEffect(input, leftOutput, rightOutput); else if (effectType == effect.phaser) phaserEffect(input, leftOutput, rightOutput); else if (effectType == effect.reverb) reverbEffect(input, leftOutput, rightOutput); // write the output of the effect to a wav file for (int index = 0; index < leftOutput.BufferSize; index++) { wav.AddSample_16bit((short)(65535 * leftOutput[index])); wav.AddSample_16bit((short)(65535 * rightOutput[index])); } }
private void DeviceCombo_SelectedIndexChanged(object sender, EventArgs e) { if (Driver != null) { Driver.ReleaseComAsioDriver(); Driver = null; } //First item is "None" with 0 index if (deviceCombo.SelectedIndex > 0) { var currGuid = DevGuids[deviceCombo.SelectedIndex - 1]; Driver = AsioDriver.GetAsioDriverByGuid(currGuid); //Limiting channel numeric by real channel number Driver.GetChannels(out int inputCh, out _); channelNumeric.Maximum = inputCh - 1; UpdateDriverInfo(); InfoUpdTimer.Start(); } else { DriverInfoLabel.Text = "None"; InfoUpdTimer.Stop(); } }
void GetAsioDriverList() { string[] asioDriverList = AsioDriver.GetAsioDriverNames(); foreach (string asioName in asioDriverList) { comboBox1.Items.Add(asioName); } }
/// <summary> /// Inits the driver from the asio driver name. /// </summary> /// <param name="driverName">Name of the driver.</param> private void InitFromName(String driverName) { // Get the basic driver AsioDriver basicDriver = AsioDriver.GetAsioDriverByName(driverName); // Instantiate the extended driver driver = new AsioDriverExt(basicDriver); this.ChannelOffset = 0; }
private void MainApp_Load(object sender, EventArgs e) { timer2.Stop(); timer1.Stop(); this.Hide(); loadApp = new LoadApp(); loadApp.Show(); mixer = new Mixer(); plugins = new Plugins(); PluginsList.Controls.Add(plugins); BPM = 128; plugins.Dock = DockStyle.Fill; if (RMVN_Studio.Properties.Settings.Default.ASIODriverName == string.Empty) { string[] asioList = AsioDriver.GetAsioDriverNames(); RMVN_Studio.Properties.Settings.Default.ASIODriverName = asioList[0]; RMVN_Studio.Properties.Settings.Default.AsioDriverIndex = 0; } BackupColor = CloseBtn.BackColor; minImg = new Bitmap(RMVN_Studio.Properties.Resources.Min2); maxImg = new Bitmap(RMVN_Studio.Properties.Resources.max); OnImg = new Bitmap(RMVN_Studio.Properties.Resources.On); OffImg = new Bitmap(RMVN_Studio.Properties.Resources.off); this.Location = Screen.AllScreens[0].WorkingArea.Location; Process thisApp = Process.GetCurrentProcess(); cpuCounter = new PerformanceCounter("Process", "% Processor Time", thisApp.ProcessName, true); settingForm = new Setting(); var lines = File.ReadAllLines(@".\Config\listPath.txt"); if (lines != null) { foreach (string line in lines) { LoadDirectory(line); } } var lines1 = File.ReadAllLines(@".\Config\listPathVST.txt"); if (lines1 != null) { foreach (string line in lines1) { SearchPlugin64bit(line); } } fileBefore = this.FileToBytes(@".\Config\listPath.txt"); fileBefore1 = this.FileToBytes(@".\Config\listPathVST.txt"); loadApp.Hide(); this.Show(); timer1.Start(); timer2.Start(); }
/// <summary> /// Inits the driver from the asio driver name. /// </summary> /// <param name="driverName">Name of the driver.</param> private void InitFromName(string driverName) { this.driverName = driverName; // Get the basic driver AsioDriver basicDriver = AsioDriver.GetAsioDriverByName(driverName); // Instantiate the extended driver driver = new AsioDriverExt(basicDriver); driver.ResetRequestCallback = OnDriverResetRequest; this.ChannelOffset = 0; }
private static void AsioDriver_BufferUpdate(object sender, EventArgs e) { // the driver is the sender AsioDriver driver = sender as AsioDriver; // increment the delay buffer counter Program._counter++; // and wrap if nede be if (Program._counter >= 100) { Program._counter = 0; } // get the input channel and the stereo output channels Channel input = driver.InputChannels[0]; Channel leftOutput = driver.OutputChannels[0]; Channel rightOutput = driver.OutputChannels[1]; for (int indx = 0; indx < leftOutput.BufferSize; indx++) { //copy input in given buffer // Program._delayBuffer[index, Program._counter] = input[index]; if (indx < (leftOutput.BufferSize / 2)) { leftOutput[indx] = input[indx]; rightOutput[indx] = input[leftOutput.BufferSize - indx]; } else { rightOutput[indx] = input[leftOutput.BufferSize - indx]; leftOutput[indx] = input[indx]; } } //for (int index = 0; index < leftOutput.BufferSize; index++) //{ // // copy the input buffer to our delay array // Program._delayBuffer[index, Program._counter] = input[index]; // // and copy from the delay array to the output buffers (wrapping as needed) // leftOutput[index] = Program._delayBuffer[index, (Program._counter - Program._leftDelay) >= 0 ? Program._counter - Program._leftDelay : Program._counter - Program._leftDelay + Program.MAX_BUFFERS]; // rightOutput[index] = Program._delayBuffer[index, (Program._counter - Program._rightDelay) >= 0 ? Program._counter - Program._rightDelay : Program._counter - Program._rightDelay + Program.MAX_BUFFERS]; //} }
/// <summary> /// Starts sampling audio from a specific device. /// </summary> public void Start(AsioSamplingServiceArgs args) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) throw new Exception("Thread must run in STA for ASIO sampling to work"); _currentDriver = args.Driver; if (!args.Driver.InputChannels.Contains(args.Channel)) throw new Exception("Input channel must be in driver.InputChannels"); // The order here is key // Create buffers before selecting the channel _currentDriver.CreateBuffers(false); _currentInputChannel = args.Driver.InputChannels.Where(x => x.Name == args.Channel.Name).Single(); args.Driver.BufferUpdate += new EventHandler(driver_BufferUpdate); _currentDriver.Start(); }
public Asio(InstalledDriver drv) { ProcessAudio = null; // make sure we have at least one ASIO driver installed if (AsioDriver.InstalledDrivers.Length == 0) { return; } // load and activate the desited driver driver = AsioDriver.SelectDriver(drv); // driver.ShowControlPanel(); driver.CreateBuffers(false); // this is our buffer fill event we need to respond to driver.BufferUpdate += new EventHandler(AsioDriver_BufferUpdate); }
private void refresh_sources() { String[] sources = AsioDriver.GetAsioDriverNames(); sourceList.Items.Clear(); var activateDeviceCount = 0; for (int i = 0; i < sources.Length; i++) { var item = new ListViewItem(sources[i]); try { var driverCapability = (new MyAsioDriverExt(MyAsioDriver.GetAsioDriverByName(sources[i]))).Capabilities; item.SubItems.Add(new ListViewItem.ListViewSubItem(item, driverCapability.NbInputChannels.ToString())); item.SubItems.Add(new ListViewItem.ListViewSubItem(item, driverCapability.NbOutputChannels.ToString())); } catch (Exception ex) { //ignore the exception and try the next source continue; } activateDeviceCount += 1; sourceList.Items.Add(item); } if (sourceList.Items.Count > 0) { //always select the first device as default var deviceName = sourceList.Items[0].Name.ToString(); foreach (ListViewItem item in sourceList.Items) { item.Selected = item.Name.ToString() == deviceName; } sourceList.Items[0].Selected = true; } if (activateDeviceCount == 0) { MessageBox.Show("Device not found, please insert a device.", "Error"); } }
/// <summary> /// Gets the names of the installed ASIO Driver. /// </summary> /// <returns>an array of driver names</returns> public static string[] GetDriverNames() { return(AsioDriver.GetAsioDriverNames()); }
// STAThread is ESSENTIAL to make this work [STAThread] public static void Main(string[] args) { // no messing, this is high priority stuff Thread.CurrentThread.Priority = ThreadPriority.Highest; Process myP = Process.GetCurrentProcess(); myP.ProcessorAffinity = (IntPtr)1; // make sure we have at least one ASIO driver installed if (AsioDriver.InstalledDrivers.Length == 0) { Console.WriteLine("There appears to be no ASIO drivers installed on your system."); Console.WriteLine("If your soundcard supports ASIO natively, install the driver"); Console.WriteLine("from the support disc. If your soundcard has no native ASIO support"); Console.WriteLine("you can probably use the generic ASIO4ALL driver."); Console.WriteLine("You can download this from: http://www.asio4all.com/"); Console.WriteLine("It's very good!"); Console.WriteLine(); Console.WriteLine("Hit Enter to exit..."); Console.ReadLine(); return; } // bingo, we've got at least one Console.WriteLine("Your system has the following ASIO drivers installed:"); Console.WriteLine(); // so iterate through them for (int index = 0; index < AsioDriver.InstalledDrivers.Length; index++) { // and display them Console.WriteLine(string.Format(" {0}. {1}", index + 1, AsioDriver.InstalledDrivers[index])); } Console.WriteLine(); int driverNumber = 0; // get them to choose one while (driverNumber < 1 || driverNumber > AsioDriver.InstalledDrivers.Length) { // we'll keep telling them this until they make a valid selection Console.Write("Select which driver you wish to use (x for exit): "); ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); // deal with exit condition if (key.KeyChar == 'x') return; // convert from ASCII to int driverNumber = key.KeyChar - 48; } Console.WriteLine(); Console.WriteLine("Using: " + AsioDriver.InstalledDrivers[driverNumber - 1]); Console.WriteLine(); // load and activate the desited driver AsioDriver driver = AsioDriver.SelectDriver(AsioDriver.InstalledDrivers[driverNumber - 1]); // popup the driver's control panel for configuration driver.ShowControlPanel(); // now dump some details Console.WriteLine(" Driver name = " + driver.DriverName); Console.WriteLine(" Driver version = " + driver.Version); Console.WriteLine(" Input channels = " + driver.NumberInputChannels); Console.WriteLine(" Output channels = " + driver.NumberOutputChannels); Console.WriteLine(" Min buffer size = " + driver.BufferSizex.MinSize); Console.WriteLine(" Max buffer size = " + driver.BufferSizex.MaxSize); Console.WriteLine(" Preferred buffer size = " + driver.BufferSizex.PreferredSize); Console.WriteLine(" Granularity = " + driver.BufferSizex.Granularity); Console.WriteLine(" Sample rate = " + driver.SampleRate); // get our driver wrapper to create its buffers driver.CreateBuffers(false); // write out the input channels Console.WriteLine(" Input channels found = " + driver.InputChannels.Length); Console.WriteLine(" ----"); foreach (Channel channel in driver.InputChannels) { Console.WriteLine(channel.Name); } // and the output channels Console.WriteLine(" Output channels found = " + driver.OutputChannels.Length); Console.WriteLine("----"); foreach (Channel channel in driver.OutputChannels) { Console.WriteLine(channel.Name); } Console.Write("Select which effect you wish to use (1 = delay, 2 = flanger, 3 = phaser, 4 = reverb): "); ConsoleKeyInfo useEffect = Console.ReadKey(); if (useEffect.KeyChar == '1') effectType = effect.delay; else if (useEffect.KeyChar == '2') effectType = effect.flanger; else if (useEffect.KeyChar == '3') effectType = effect.phaser; else if (useEffect.KeyChar == '4') effectType = effect.reverb; else effectType = effect.none; // create standard sized buffers with a size of PreferredSize x MaxBuffers _delayBuffer = new float[driver.BufferSizex.PreferredSize, MaxBuffers]; // create a feedback buffer for the delay effect _delayFBbuffer = new float[driver.BufferSizex.PreferredSize, MaxBuffers]; // create a input buffer for reverb effect _delayINbuffer = new float[driver.BufferSizex.PreferredSize, MaxBuffers]; // create a output buffer for reverb effect _delayOUTbuffer = new float[driver.BufferSizex.PreferredSize, MaxBuffers]; // this is our buffer fill event we need to respond to driver.BufferUpdate += new EventHandler(AsioDriver_BufferUpdate); // and off we go driver.Start(); // create a wav file for recording wav.Create("test.wav", true, 44100, 16); // wait for enter key Console.WriteLine(); Console.WriteLine("Press Enter to end"); Console.ReadLine(); // and all done driver.Stop(); // close the wav file wav.Close(); }
public void StartSampling(AsioDriver driver, uint sampleRate) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) throw new Exception("Thread must run in STA for ASIO sampling to work"); }
//static double t = 0; //static ulong frameCount = 0; //static bool high = false; /// <summary> /// Called when a buffer update is required /// </summary> private static void AsioDriver_BufferUpdate(object sender, EventArgs e) { // the driver is the sender AsioDriver driver = sender as AsioDriver; // get the stereo output channels Channel xOutput = driver.OutputChannels[2]; Channel yOutput = driver.OutputChannels[3]; Channel zOutput = driver.OutputChannels[0]; FeedAsioBuffers(xOutput, yOutput, zOutput, 0); if (DebugSaveThisFrame) { DebugSaveBuffersToFile(xOutput, yOutput, zOutput, "ASIO Frame Snapshot.csv"); } ApplyBlankingChannelDelay(zOutput); if (DebugSaveThisFrame) { DebugSaveBuffersToFile(xOutput, yOutput, zOutput, "ASIO Frame Snapshot (Blanking Delay Applied).csv"); DebugSaveThisFrame = false; } // Copy x output into the last of the four channels to give a demo of what the audio sounds like Channel audioDemo = driver.OutputChannels[1]; for (int i = 0; i < xOutput.BufferSize; i++) { audioDemo[i] = xOutput[i]; } ////Disable brightness modulation(z - input on scope) //for (int i = 0; i < zOutput.BufferSize; i++) //{ // zOutput[i] = 0; //} #region Debugging code // checking for delays between channels //for (int i = 0; i < xOutput.BufferSize; i++) //{ // yOutput[i] = xOutput[i]; // zOutput[i] = xOutput[i]; //} // Code for a test tone to make sure ASIO device is working well: //for (int index = 0; index < xOutput.BufferSize; index++) //{ // t += 0.03; // xOutput[index] = (float)Math.Sin(t); // yOutput[index] = (float)Math.Sin(t); // zOutput[index] = (float)Math.Sin(t); //} // Code for testing blanking: //for (int index = 0; index < xOutput.BufferSize; index++) //{ // t = Microsoft.Xna.Framework.MathHelper.Lerp(0, (float)Math.PI, (float)index / xOutput.BufferSize); // xOutput[index] = (float)Math.Sin(t); // yOutput[index] = (float)Math.Cos(t); // if (yOutput[index] > 0.5f || yOutput[index] < -0.5f) // { // zOutput[index] = 1f;// (float)Math.Sin(t); // } // else // { // zOutput[index] = 0f;// (float)Math.Sin(t); // } //} // Code for debugging flicker to 0,0: //for (int i = 0; i < xOutput.BufferSize; i++) //{ // double threshold = 0.01; // if (Math.Abs((double)xOutput[i]) < threshold && Math.Abs((double)yOutput[i]) < threshold) // { // Console.WriteLine("output is 0"); // } //} //// Code for debugging oscilloscope faulty(?) X input that looks like it's not properly DC Coupled //frameCount++; //if (frameCount % 300 == 0) //{ // high = !high; //} //for (int i = 0; i < xOutput.BufferSize; i++) //{ // float value; // if (i < xOutput.BufferSize / 2) // { // value = high ? 0.65f : -0.65f; // } // else // { // value = high ? 0.1f : -0.1f; // } // xOutput[i] = value; // yOutput[i] = value; // zOutput[i] = 0f; //} //// Alternative code for debugging oscilloscope faulty(?) X input that looks like it's not properly DC Coupled //frameCount++; //if (frameCount % 50 == 0) //{ // high = !high; //} //for (int i = 0; i < xOutput.BufferSize; i++) //{ // float value; // value = high ? 0.1f : -0.1f; // xOutput[i] = value; // yOutput[i] = value; // zOutput[i] = 0f; //} //// Alternative code for debugging oscilloscope faulty(?) X input that looks like it's not properly DC Coupled //frameCount++; //if (frameCount % 50 == 0) //{ // high = !high; //} //for (int i = 0; i < xOutput.BufferSize; i++) //{ // float value = -0.5f; // if (high && i > xOutput.BufferSize / 3 && i < (xOutput.BufferSize / 3) * 2) // { // value = 0.5f; // } // xOutput[i] = value; // zOutput[i] = 0f; //} //for (int i = 0; i < yOutput.BufferSize; i++) //{ // yOutput[i] = (float)i / (yOutput.BufferSize - 1); // yOutput[i] = yOutput[i] * 2f - 1f; // zOutput[i] = 0f; //} #endregion }
/// <summary> /// Starts sampling audio from a specific device. /// </summary> /// <param name="driver">The ASIO driver to use</param> /// <param name="inputChannel">The input channel to use (if the driver has multiple channels)</param> /// <param name="sampleRate">How fast to sample (samples/sec)</param private void StartSampling(AsioDriver driver, Channel inputChannel, uint sampleRate) { driver.BufferUpdate += new EventHandler(driver_BufferUpdate); }
void AsioDeviceService_DriverLoaded(object sender, DriverLoadedEventArgs e) { LoadedDriver = e.Driver; }
/// <summary> /// Release driver /// </summary> private void ReleaseDriver(AsioDriver driver) { driver.DisposeBuffers(); driver.ReleaseComAsioDriver(); }
protected virtual void Dispose(bool disposing) { if (_disposed) return; if (disposing) { // free other managed objects that implement // IDisposable only } // release any unmanaged objects // set the object references to null try { driver.Stop(); driver.Release(); } catch(Exception e){ System.Diagnostics.Debug.WriteLine("Dispose Ex: {0}",e.Message); } driver = null; _disposed = true; }
private void InternalReleaseDriver() { if (_Driver != null) { _Driver.Stop(); _Driver.DisposeBuffers(); _Driver.Release(); _Driver = null; _FirstChannel = 0; _ChannelCount = 0; } return; }
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(); } }
public DriverLoadedEventArgs(AsioDriver driver) { Driver = driver; }
private bool InternalInitDriver(int asioDriver, IntPtr sysHandle, bool useMaxBuffer) { InternalReleaseDriver(); InstalledDriver driver = AsioDriver.InstalledDrivers[asioDriver]; _Driver = AsioDriver.SelectDriver(driver, sysHandle); bool result = (_Driver != null); if (result) { result = _Driver.CreateBuffers(useMaxBuffer); } if (result) { _Driver.BufferUpdate += new EventHandler(_Driver_BufferUpdate); _FirstChannel = 0; _ChannelCount = _Driver.OutputChannels.Length; } return result; }
public static void StartDriver() { // This apartment state is required for the ASIOOutput.StartDriver method // If an execption is thrown here that's because you need [STAThread] attribute on your static void Main(string[] args) method // or you need to set this thread's ApartmentState to STA before starting the thread. Thread.CurrentThread.SetApartmentState(ApartmentState.STA); // make sure we have at least one ASIO driver installed if (AsioDriver.InstalledDrivers.Length == 0) { Console.WriteLine("There appears to be no ASIO drivers installed on your system."); Console.WriteLine("If your soundcard supports ASIO natively, install the driver"); Console.WriteLine("from the support disc. If your soundcard has no native ASIO support"); Console.WriteLine("you can probably use the generic ASIO4ALL driver."); Console.WriteLine("You can download this from: http://www.asio4all.com/"); Console.WriteLine("It's very good!"); Console.WriteLine(); Console.WriteLine("Hit Enter to exit..."); Console.ReadLine(); return; } // bingo, we've go at least one Console.WriteLine("Your system has the following ASIO drivers installed:"); Console.WriteLine(); // so iterate through them for (int index = 0; index < AsioDriver.InstalledDrivers.Length; index++) { // and display them Console.WriteLine($" {index + 1}. {AsioDriver.InstalledDrivers[index]}"); } Console.WriteLine(); // Currently hardcoded: todo: make it not. int driverNumber = 2; Console.WriteLine(); Console.WriteLine("Using: " + AsioDriver.InstalledDrivers[driverNumber - 1]); Console.WriteLine(); // load and activate the desited driver AsioDriver driver = AsioDriver.SelectDriver(AsioDriver.InstalledDrivers[driverNumber - 1]); // popup the driver's control panel for configuration //driver.ShowControlPanel(); // now dump some details Console.WriteLine(" Driver name = " + driver.DriverName); Console.WriteLine(" Driver version = " + driver.Version); Console.WriteLine(" Input channels = " + driver.NumberInputChannels); Console.WriteLine(" Output channels = " + driver.NumberOutputChannels); Console.WriteLine(" Min buffer size = " + driver.BufferSizex.MinSize); Console.WriteLine(" Max buffer size = " + driver.BufferSizex.MaxSize); Console.WriteLine(" Preferred buffer size = " + driver.BufferSizex.PreferredSize); Console.WriteLine(" Granularity = " + driver.BufferSizex.Granularity); Console.WriteLine(" Sample rate = " + driver.SampleRate); if (driver.SampleRate != FrameOutput.SAMPLES_PER_SECOND) { throw new Exception("Driver sample rate is different than what the game expects. Please adjust driver settings to have a " + FrameOutput.SAMPLES_PER_SECOND + " sample rate."); } // get our driver wrapper to create its buffers driver.CreateBuffers(false); // write out the input channels Console.WriteLine(" Input channels found = " + driver.InputChannels.Length); Console.WriteLine(" ----"); foreach (Channel channel in driver.InputChannels) { Console.WriteLine(channel.Name); } // and the output channels Console.WriteLine(" Output channels found = " + driver.OutputChannels.Length); Console.WriteLine("----"); foreach (Channel channel in driver.OutputChannels) { Console.WriteLine(channel.Name); } // this is our buffer fill event we need to respond to driver.BufferUpdate += new EventHandler(AsioDriver_BufferUpdate); // and off we go driver.Start(); //while(true) //{ // Thread.Sleep(100); //} //// and all donw //driver.Stop(); }