public AudioPlaybackForm()
        {
            InitializeComponent();

            // Disable ASIO if no drivers are available
            if (!AsioOut.isSupported())
            {
                radioButtonAsio.Enabled    = false;
                buttonControlPanel.Enabled = false;
                comboBoxAsioDriver.Enabled = false;
            }
            else
            {
                // Just fill the comboBox AsioDriver with available driver names
                String[] asioDriverNames = AsioOut.GetDriverNames();
                foreach (string driverName in asioDriverNames)
                {
                    comboBoxAsioDriver.Items.Add(driverName);
                }
                comboBoxAsioDriver.SelectedIndex = 0;
            }

            if (Environment.OSVersion.Version.Major < 6)
            {
                // WASAPI supported only on Windows Vista and above
                radioButtonWasapi.Enabled           = false;
                checkBoxWasapiEventCallback.Enabled = false;
                checkBoxWasapiExclusiveMode.Enabled = false;
            }
        }
Beispiel #2
0
        static Audio()
        {
            var asioDrivers = AsioOut.GetDriverNames();

            if (asioDrivers.Length == 0)
            {
                Console.WriteLine("please install http://www.asio4all.org/");
                Console.WriteLine("press any key to exit");
                Console.ReadKey();
                Environment.Exit(0);
            }
            asioOut = new AsioOut(asioDrivers[0]);
            mixer   = new MixingWaveProvider32();
            hit     = new WaveChannel32(new AudioFileReader("hitsound.wav"))
            {
                Volume = 0.2f,
            };
            miss = new WaveChannel32(new AudioFileReader("miss.wav"))
            {
                Volume = 0.2f,
            };
            var err = new SignalGenerator()
            {
                Type = SignalGeneratorType.SawTooth,
                Gain = 0.2,
            }.Take(TimeSpan.FromSeconds(0.1d)).ToWaveProvider();

            mixer.AddInputStream(hit);
            mixer.AddInputStream(miss);
            asioOut.Init(mixer);
            asioOut.Play();
        }
Beispiel #3
0
    private void frmConfig_Load(object sender, EventArgs e)
    {
        List <float> flist = new List <float>();

        flist.Add(0);
        flist.Add(2);
        flist.Add(4);
        flist.Add(6);
        flist.Add(8);
        flist.Add(10);
        DiscDraw.Draw(pictureBox1, flist);
        DiscDraw.Draw(pictureBox2, flist);

        _config = Config.ReadXML(configFilename);

        lstMIDIEvent.Items.Clear();
        //ASIOドライバー一覧取得
        foreach (string device in AsioOut.GetDriverNames())
        {
            cboAsioDriver.Items.Add(device);
        }
        if (cboAsioDriver.Items.Count > 0)
        {
            cboAsioDriver.SelectedIndex = 0;
        }
        //MIDI入力デバイス一覧取得
        for (int device = 0; device < MidiIn.NumberOfDevices; device++)
        {
            cboMIDIINDEVICE.Items.Add(MidiIn.DeviceInfo(device).ProductName);
        }
        if (cboMIDIINDEVICE.Items.Count > 0)
        {
            cboMIDIINDEVICE.SelectedIndex = 0;
        }
    }
Beispiel #4
0
        private void Setting_Load(object sender, EventArgs e)
        {
            timer1.Stop();
            asioOut = new AsioOut(RMVN_Studio.Properties.Settings.Default.ASIODriverName);
            GetAsioDriverList();
            comboBox1.SelectedIndex = RMVN_Studio.Properties.Settings.Default.AsioDriverIndex;
            //asioOut.InitRecordAndPlayback(null, 1, 44100);
            var lines = File.ReadAllLines(@".\Config\listPath.txt");

            if (lines != null)
            {
                foreach (string line in lines)
                {
                    listPath.Items.Add(new ListViewItem(line));
                }
            }

            var lines1 = File.ReadAllLines(@".\Config\listPathVST.txt");

            if (lines1 != null)
            {
                foreach (string line in lines1)
                {
                    listView1.Items.Add(new ListViewItem(line));
                }
            }
            timer1.Start();
        }
Beispiel #5
0
        protected override IWavePlayer GetWavePlayer()
        {
            string driverName;

            string[] driverNames = AsioOut.GetDriverNames();

            if (driverNames.Length == 0)
            {
                throw new InvalidOperationException("No ASIO driver found.");
            }
            else if (driverNames.Length == 1)
            {
                driverName = driverNames[0];
            }
            else
            {
                driverName = _driverSelector(driverNames);
            }

            if (string.IsNullOrWhiteSpace(driverName))
            {
                throw new InvalidOperationException("A driverName was not selected.");
            }

            return(new AsioOut(driverName));
        }
Beispiel #6
0
        static NAudioSettings()
        {
            if (WaveOut.DeviceCount > 0)
            {
                AvailableTechnologies.Add(new WaveOutTechnology());
            }

            Contract.Assume(DirectSoundOut.Devices != null);
            if (DirectSoundOut.Devices.Any())
            {
                AvailableTechnologies.Add(new DirectSoundTechnology());
            }

            if (AsioOut.isSupported())
            {
                AvailableTechnologies.Add(new AsioTechnology());
            }

            Contract.Assume(Environment.OSVersion != null);
            Contract.Assume(Environment.OSVersion.Version != null);
            if (Environment.OSVersion.Version.Major >= 6)
            {
                AvailableTechnologies.Add(new WasapiTechnology());
            }
        }
        public ViewModel(int rows, int cols)
        {
            Maze        = new Maze(rows, cols);
            _generators = new List <IMazeGenerator>()
            {
                new DepthFirstSearchGenerator(Maze),
                new BinaryTreeGenerator(Maze),
                new KruskalsRandomizedGenerator(Maze),
                new SidewinderGenerator(Maze),
                new HuntAndKillGenerator(Maze),
                new PrimsRandomizedGenerator(Maze),
                new EllersGenerator(Maze),
            };

            _asio = new AsioOut("Focusrite USB ASIO");
            _asio.Init(_sineWaveProvider);
            //waveOut = new WaveOut();
            //waveOut.Init(_sineWaveProvider);

            GenerateCommand = new RelayCommand(o =>
            {
                _sineWaveProvider.Frequency = 0;
                _asio.Play();
                //waveOut.Play();

                RunGenerator();
            });
        }
    public AsioSampleProvider(string driverName, int sampleRate = 44100, int numChannels = 2)
    {
        this.sampleRate  = sampleRate;
        this.numChannels = numChannels;

        //For now assuming ASIO in is PCM 16 (H6 input is PCM 16bit and not planning to use another interface)
        //In future may need some sort of data conversion
        this.WaveFormat = new WaveFormat(sampleRate, numChannels);
        waveProvider    = new BufferedWaveProvider(this.WaveFormat);

        sampleProvider = waveProvider.ToSampleProvider();

        try
        {
            asio = new AsioOut(driverName);
            asio.InitRecordAndPlayback(null, numChannels, sampleRate);
            asio.AudioAvailable += OnAudioAvailable;
            asio.Play();
            Debug.Log(string.Format("Asio Playing: {0}", asio.PlaybackState));
        }
        catch (System.ArgumentException e)
        {
            Debug.Log(string.Format("Invalid ASIO Driver Name: {0}", e));
        }
        catch (System.Exception e)
        {
            Debug.Log(string.Format("Unknown ASIO Error: {0}", e));
        }
    }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please select an ASIO driver to use: ");

            int asioDriverCount = AsioOut.GetDriverNames().Length;

            for (int i = 0; i < asioDriverCount; i++)
            {
                Console.WriteLine(i + ": " + AsioOut.GetDriverNames()[i]);
            }

            string input     = Console.ReadLine();
            int    selection = Int32.Parse(input);

            SineWaveTable.Instance.GenerateWaveTable();
            SawWaveTable.Instance.GenerateWaveTable();

            MIDIHandler io = new MIDIHandler(selection);

            Console.WriteLine("To stop audio playback, type \'stop\'");
            input = Console.ReadLine();
            while (input != "stop")
            {
                Console.WriteLine(String.Format("\'{0}\' is not a recognised command.", input));
                input = Console.ReadLine();
            }

            Console.WriteLine("Exiting program...");
            io.Dispose();
        }
Beispiel #10
0
        public static void ShowControlPanel(string asioDriverName)
        {
            if (asioOut != null)
            {
                asioOut.Dispose();
            }

            int i = 0;

            foreach (string s in AsioOut.GetDriverNames())
            {
                if (asioDriverName == s)
                {
                    break;
                }
                i++;
            }
            int retry = 3;

            do
            {
                try
                {
                    asioOut = new AsioOut(i);
                }
                catch
                {
                    asioOut = null;
                    Thread.Sleep(1000);
                    retry--;
                }
            } while (asioOut == null && retry > 0);

            asioOut.ShowControlPanel();
        }
Beispiel #11
0
        private void Start()
        {
            // allow change device
            if (this.asioOut != null &&
                (this.asioOut.DriverName != comboBoxAsioDevice.Text ||
                 this.asioOut.ChannelOffset != GetUserSpecifiedChannelOffset()))
            {
                this.asioOut.AudioAvailable -= asioOut_AudioAvailable;
                this.asioOut.Dispose();
                this.asioOut = null;
            }

            int recordChannelCount = GetUserSpecifiedChannelCount();

            // create device if necessary
            if (this.asioOut == null)
            {
                this.asioOut = new AsioOut(comboBoxAsioDevice.Text);
                this.asioOut.InputChannelOffset = GetUserSpecifiedChannelOffset();
                this.asioOut.InitRecordAndPlayback(null, recordChannelCount, 44100);
                this.asioOut.AudioAvailable += asioOut_AudioAvailable;
            }

            this.fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
            this.writer   = new WaveFileWriter(fileName, new WaveFormat(44100, recordChannelCount));
            this.asioOut.Play();
            this.timer1.Enabled = true;
            SetButtonStates();
        }
Beispiel #12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            cmbDevice.Items.AddRange(AsioOut.GetDriverNames());

            signalNetworkForm = new SignalNetworkForm();
            signalNetworkForm.Show();
        }
Beispiel #13
0
        protected override IReadOnlyDictionary <string, object> GetEntries()
        {
            Dictionary <string, object> devices = new Dictionary <string, object>();

            for (int i = 0; i < WaveOut.DeviceCount; i++)
            {
                var caps = WaveOut.GetCapabilities(i);
                var name = caps.ProductName;
                devices[$"WaveOut: {name}"] = new WaveOutFactory(i);
            }

            foreach (var device in DirectSoundOut.Devices)
            {
                var name = device.Description;
                devices[$"DS: {name}"] = new DirectSoundOutFactory(device.Guid);
            }

            var enumerator = new MMDeviceEnumerator();

            foreach (var wasapi in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active))
            {
                var name = wasapi.FriendlyName;
                devices[$"Wasapi: {name}"] = new WasapiOutFactory(wasapi.ID);
            }

            foreach (var asio in AsioOut.GetDriverNames())
            {
                devices[$"ASIO: {asio}"] = new AsioOutFactory(asio);
            }

            return(devices);
        }
Beispiel #14
0
        public AsioCard(
            WaveFormat format,
            AsioOut driver,
            AsioInputMapper inputMapper,
            AsioOutputMapper outputMapper)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format", "Must specify an audio format");
            }

            if (driver == null)
            {
                throw new ArgumentNullException("driver", "Asio driver cannot be null");
            }

            if (inputMapper == null)
            {
                throw new ArgumentNullException("inputMapper", "Asio input mapper cannot be null");
            }

            if (outputMapper == null)
            {
                throw new ArgumentNullException("outputMapper", "Asio output mapper cannot be null");
            }

            this.format       = format;
            this.driver       = driver;
            this.inputMapper  = inputMapper;
            this.outputMapper = outputMapper;
        }
Beispiel #15
0
 private void comboBoxAsioDriver_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         using (var asio = new AsioOut(SelectedDeviceName))
         {
             //asio.ShowControlPanel();
             int nrOfChannelOUTDevices = asio.DriverOutputChannelCount;
             int nrOfChannelINDevices = asio.DriverInputChannelCount;
             listBoxInputs.Items.Clear();
             listBoxOutputs.Items.Clear();
             for (int i = 0; i < nrOfChannelOUTDevices; i++)
             {
                 string name = asio.AsioInputChannelName(i);
                 listBoxInputs.Items.Add(name);
             }
             for (int i = 0; i < nrOfChannelINDevices; i++)
             {
                 string name = asio.AsioOutputChannelName(i);
                 listBoxOutputs.Items.Add(name);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #16
0
        internal static void updateAudioDevices()
        {
            var deviceEnum = new MMDeviceEnumerator();

            String[] devices = AsioOut.GetDriverNames();
            deviceMap.Add(new Device(new AsioOut("UMC ASIO Driver")));
            int deviceCount = devices.Count();

            deviceCount = 0;
            // try adding all devices to a device list to be displayed as a selection of drivers
            for (byte i = 0; i < deviceCount; i++)
            {
                try
                {
                    deviceMap.Add(new Device(new AsioOut(devices[i])));
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(i + ": " + devices[i] + " failed with error:");
                    Console.WriteLine(e);
                }
            }
            configureInputForm.clearItems();
            configureInputForm.addItems(deviceMap);
        }
Beispiel #17
0
 /// <summary>
 /// インスタンスを破棄する
 /// </summary>
 protected override void Dispose()
 {
     if (this._audioRender is not null)
     {
         this._audioRender?.Dispose();
         this._audioRender = null;
     }
 }
Beispiel #18
0
    /// <summary>
    /// IeeeFloat,44100Hz,2ch(固定)でミキサーの初期化
    /// </summary>
    public static void Init(string drivername, int channeloffset)
    {
        AsioOut asioOut = new AsioOut(drivername);

        asioOut.ChannelOffset = channeloffset;

        InitCommon(asioOut);
    }
 //close ASIO
 private void Cleanup()
 {
     if (this.FAsioOut != null)
     {
         this.FAsioOut.Dispose();
         this.FAsioOut = null;
     }
 }
Beispiel #20
0
        public IWavePlayer CreateDevice(AudioOutput output)
        {
            IWavePlayer player = null;

            switch (output.DeviceType)
            {
            case AudioOutputs.AudioDeviceType.Asio:
            {
                try
                {
                    player = new AsioOut(output.DeviceName);
                }
                catch (InvalidOperationException e)
                {
                    throw new InvalidOutputDeviceException(e.Message, output);
                }
                break;
            }

            case AudioOutputs.AudioDeviceType.WaveOut:
            {
                try
                {
                    WaveOutEvent waveOutput = new WaveOutEvent();
                    waveOutput.DeviceNumber    = output.DeviceNumber;
                    waveOutput.NumberOfBuffers = 2;
                    waveOutput.DesiredLatency  = output.ChosenLatency;
                    player = waveOutput;
                }
                catch (Exception e)
                {
                    throw new InvalidOutputDeviceException(e.Message, output);
                }
                break;
            }

            case AudioOutputs.AudioDeviceType.Wasapi:
            {
                try
                {
                    var device = output.MMDevice;
                    // unfortunately, exclusive mode causes repeating buffer on pause, but shared mode sounds awful.
                    NAJAudio.CoreAudioApi.AudioClientShareMode shareMode = NAJAudio.CoreAudioApi.AudioClientShareMode.Exclusive;
                    int       latency      = output.ChosenLatency;
                    bool      useEventSync = false;
                    WasapiOut wasapiOut    = new WasapiOut(device, shareMode, useEventSync, latency);
                    player = wasapiOut;
                }
                catch (Exception e)
                {
                    throw new InvalidOutputDeviceException(e.Message, output);
                }
                break;
            }
            }

            return(player);
        }
 public MainWindow()
 {
     String[] drivernames = AsioOut.GetDriverNames();
     ASIODriver = new AsioOut(drivernames[0]);
     buffer     = new BufferedWaveProvider(new WaveFormat());
     ASIODriver.AudioAvailable += new EventHandler <AsioAudioAvailableEventArgs>(ASIODriver_AudioAvailable);
     ASIODriver.InitRecordAndPlayback(buffer, 2, 44100);
     ASIODriver.Play();
 }
Beispiel #22
0
        private void buttonControlPanel_Click(object sender, EventArgs e)
        {
            AsioOut asio = waveOut as AsioOut;

            if (asio != null)
            {
                asio.ShowControlPanel();
            }
        }
Beispiel #23
0
 void fillDeviceList()
 {
     string[] drvn = AsioOut.GetDriverNames();
     driverNames = new List <string>();
     driverNames.Add("None");
     for (int i = 0; i < drvn.Length; i++)
     {
         driverNames.Add(drvn[i]);
     }
 }
        public void Setup()
        {
            var drives = AsioOut.GetDriverNames();

            asioOut = new AsioOut("ASIO4ALL v2");

            //asioOut.InputChannelOffset = inputNumber;
            asioOut.InitRecordAndPlayback(null, 1, sampleRate);
            asioOut.AudioAvailable += OnAsioAudioAvailable;
        }
Beispiel #25
0
 private void InitialiseAsioControls()
 {
     // Just fill the comboBox AsioDriver with available driver names
     var asioDriverNames = AsioOut.GetDriverNames();
     foreach (string driverName in asioDriverNames)
     {
         comboBoxAsioDriver.Items.Add(driverName);
     }
     //comboBoxAsioDriver.SelectedIndex = 0;
 }
Beispiel #26
0
    /// <summary>
    /// オーディオレンダラを更新する
    /// </summary>
    /// <returns>新しいオーディオレンダラ</returns>
    private AsioOut UpdateAudioRender()
    {
        this.ReleaseRender();

        var newRender = this._audioRender = new AsioOut(this.Info.Id);

        newRender.PlaybackStopped += this.RaisePlaybackStopped;

        return(newRender);
    }
Beispiel #27
0
 //close ASIO
 private void Cleanup()
 {
     if (this.AsioOut != null)
     {
         this.AsioOut.DriverResetRequest -= AsioOut_DriverResetRequest;
         this.AsioOut.AudioAvailable     -= AudioEngine_AudioAvailable;
         this.AsioOut.Dispose();
         this.AsioOut = null;
     }
 }
Beispiel #28
0
    public static void Init(string drivername)
    {
        mixer = new MixingWaveProvider32();

        waveOut = new AsioOut(drivername);//NAudio.CoreAudioApi.AudioClientShareMode.Exclusive,100);
        //waveOut = new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, 100);
        waveOut.Init(mixer);
        waveformat = new WaveFormat(44100, 2);

        DctWaveProvider = new Dictionary <string, IWaveProvider>();
    }
Beispiel #29
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     RMVN_Studio.Properties.Settings.Default.ASIODriverName  = comboBox1.GetItemText(comboBox1.SelectedItem);
     RMVN_Studio.Properties.Settings.Default.AsioDriverIndex = comboBox1.SelectedIndex;
     if (asioOut != null)
     {
         asioOut = null;
     }
     asioOut = new AsioOut(RMVN_Studio.Properties.Settings.Default.ASIODriverName);
     //asioOut.InitRecordAndPlayback(null, 1, 44100);
 }
Beispiel #30
0
    public static void Init(string drivername, int channeloffset)
    {
        mixer = new MixingWaveProvider32();

        waveOut = new AsioOut(drivername);
        waveOut.ChannelOffset = channeloffset;
        waveOut.Init(mixer);
        waveformat = new WaveFormat(44100, 2);

        DctWaveProvider = new Dictionary <string, IWaveProvider>();
    }