Ejemplo n.º 1
0
        protected override SinkSourceMode driverConnect()
        {
            if (selectedDevice <= 0)
            {
                return(SinkSourceMode.Offline);
            }

            owner.logText(String.Format("Opening Audio Device {0}", devices[selectedDevice]));
            try
            {
                if (waveProvider == null)
                {
                    waveProvider = new NAudioShortWaveProvider(this);
                }
                waveProvider.SetWaveFormat(owner.sampleRate, 2);

                List <NAudio.CoreAudioApi.MMDevice> MMdevices;
                MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator();
                MMdevices = deviceEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToList();
                int found = -1;
                for (int i = 0; i < MMdevices.Count; i++)
                {
                    if (MMdevices[i].DeviceFriendlyName.Equals(devices[selectedDevice]))
                    {
                        found = i;
                    }
                }
                if (found < 0)
                {
                    selectedDevice = 0;
                    return(SinkSourceMode.Offline);
                }

                waveOut = new WasapiOut(MMdevices[found], AudioClientShareMode.Shared, false, 10);
                // waveOut.DeviceNumber = devindex[selectedDevice];
                // waveOut.DesiredLatency = 100; // 100 ms = 4800 Samples;

                setChannels(null, new RTIO[] { ioL, ioR });

                // ioRefToDriver[0] = 0;
                // ioRefToDriver[1] = 1;


                waveOut.Init(waveProvider);
                waveOut.Play();
                owner.logText(String.Format("Audio Device {0} open", devices[selectedDevice]));
                processingType = ProcessingType.SynchronousSink;
                return(SinkSourceMode.Online);
            }
            catch (Exception e)
            {
                owner.showLogWin();
                owner.logText(e.Message);
                return(SinkSourceMode.Error);
            }
        }
Ejemplo n.º 2
0
        protected override SinkSourceMode driverConnect()
        {
            if (selectedDevice <= 0)
            {
                return(SinkSourceMode.Offline);
            }

            owner.logText(String.Format("Opening Audio Device {0}", devices[selectedDevice]));
            try
            {
                if (waveProvider == null)
                {
                    waveProvider = new NAudioShortWaveProvider(this);
                }
                waveProvider.SetWaveFormat(owner.sampleRate, 2);
                waveOut = new WaveOut();
                waveOut.DeviceNumber   = devindex[selectedDevice];
                waveOut.DesiredLatency = 100; // 100 ms = 4800 Samples;

                setChannels(null, new RTIO[] { ioL, ioR });

                // ioRefToDriver[0] = 0;
                // ioRefToDriver[1] = 1;


                waveOut.Init(waveProvider);
                waveOut.Play();
                owner.logText(String.Format("Audio Device {0} open", devices[selectedDevice]));
                processingType = ProcessingType.SynchronousSink;
                return(SinkSourceMode.Online);
            }
            catch (Exception e)
            {
                owner.showLogWin();
                owner.logText(e.Message);
                return(SinkSourceMode.Error);
            }
        }
Ejemplo n.º 3
0
        protected override SinkSourceMode driverConnect()
        {
            if (selectedDriver <= 0)
            {
                return(SinkSourceMode.Offline);
            }

            owner.logText(String.Format("Opening ASIO Device {0}", driverNames[selectedDriver]));
            try
            {
                waveDev = new AsioOut(driverNames[selectedDriver]);
                waveDev.ChannelOffset      = 0;
                waveDev.InputChannelOffset = 0;

                if ((waveDev.DriverInputChannelCount == 0) && (waveDev.DriverOutputChannelCount == 0))
                {
                    throw new Exception(String.Format("ASIO Driver {0} proveides no Input or output channels", driverNames[selectedDriver]));
                }

                RTIO[] ins  = new RTIO[min(waveDev.DriverInputChannelCount, maxChannels)];
                RTIO[] outs = new RTIO[min(waveDev.DriverOutputChannelCount, maxChannels)];
                if ((waveDev.DriverInputChannelCount > 0) && (maxChannels > 0))
                {
                    ins[0] = ioI1;
                }
                if ((waveDev.DriverInputChannelCount > 1) && (maxChannels > 1))
                {
                    ins[1] = ioI2;
                }
                if ((waveDev.DriverInputChannelCount > 2) && (maxChannels > 2))
                {
                    ins[2] = ioI3;
                }
                if ((waveDev.DriverInputChannelCount > 3) && (maxChannels > 3))
                {
                    ins[3] = ioI4;
                }
                if ((waveDev.DriverInputChannelCount > 4) && (maxChannels > 4))
                {
                    ins[4] = ioI5;
                }
                if ((waveDev.DriverInputChannelCount > 5) && (maxChannels > 5))
                {
                    ins[5] = ioI6;
                }
                if ((waveDev.DriverInputChannelCount > 6) && (maxChannels > 6))
                {
                    ins[6] = ioI7;
                }
                if ((waveDev.DriverInputChannelCount > 7) && (maxChannels > 7))
                {
                    ins[7] = ioI8;
                }
                if ((waveDev.DriverOutputChannelCount > 0) && (maxChannels > 0))
                {
                    outs[0] = ioO1;
                }
                if ((waveDev.DriverOutputChannelCount > 1) && (maxChannels > 1))
                {
                    outs[1] = ioO2;
                }
                if ((waveDev.DriverOutputChannelCount > 2) && (maxChannels > 2))
                {
                    outs[2] = ioO3;
                }
                if ((waveDev.DriverOutputChannelCount > 3) && (maxChannels > 3))
                {
                    outs[3] = ioO4;
                }
                if ((waveDev.DriverOutputChannelCount > 4) && (maxChannels > 4))
                {
                    outs[4] = ioO5;
                }
                if ((waveDev.DriverOutputChannelCount > 5) && (maxChannels > 5))
                {
                    outs[5] = ioO6;
                }
                if ((waveDev.DriverOutputChannelCount > 6) && (maxChannels > 6))
                {
                    outs[6] = ioO7;
                }
                if ((waveDev.DriverOutputChannelCount > 7) && (maxChannels > 7))
                {
                    outs[7] = ioO8;
                }

                setChannels(outs, ins);

                if (waveProvider == null)
                {
                    waveProvider = new NAudioShortWaveProvider(this);
                }
                waveProvider.SetWaveFormat(owner.sampleRate, toDriverChannels);

                if (fromDriverChannels == 0)
                {
                    waveDev.InitRecordAndPlayback(waveProvider, 0, owner.sampleRate);
                }
                else if (toDriverChannels == 0)
                {
                    waveDev.InitRecordAndPlayback(null, fromDriverChannels, owner.sampleRate);
                }
                else
                {
                    waveDev.InitRecordAndPlayback(waveProvider, fromDriverChannels, owner.sampleRate);
                }

                if (fromDriverChannels > 0)
                {
                    waveDev.AudioAvailable += ASIO_AudioAvailable;
                }

                waveDev.Play();

                if (fromDriverChannels == 0)
                {
                    processingType = ProcessingType.SynchronousSource;
                }
                else
                {
                    processingType = ProcessingType.SynchronousSink;
                }
                owner.logText(String.Format("ASIO Device {0} open", driverNames[selectedDriver]));
                return(SinkSourceMode.Online);
            }
            catch (Exception e)
            {
                owner.showLogWin();
                owner.logText(e.Message);
                return(SinkSourceMode.Error);
            }
        }