private void button1_Click(object sender, EventArgs e)
        {
            //   Thread.CurrentThread.Priority = ThreadPriority.Highest;

            // popup the driver's control panel for configuration
            driver.ShowControlPanel();
            // get our driver wrapper to create its buffers

            driver.CreateBuffers(false);


            // create a an array of standard sized buffers with a size of 100

            Program._delayBuffer = new float[driver.BufferSizex.PreferredSize, Program.MaxBuffers];


            listBox1.Items.Add("buffer size " + Program._delayBuffer.Length + driver.BufferSizex.MinSize);



            // this is our buffer fill event we need to respond to
            driver.BufferUpdate += new EventHandler(AsioDriver_BufferUpdate);


            // and off we go
            driver.Start();
        }
Exemple #2
0
        /// <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();
        }
Exemple #3
0
        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);
        }
        // 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();

        }
Exemple #5
0
        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();
        }
        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;
        }