Ejemplo n.º 1
0
        public Testfeed(LSDevice src, int[] chans, VolumeSlider[] vus, int outDev)
        {
            this.src   = src;
            this.chans = chans;
            this.vus   = vus;
            this.ok    = false;

            dummies = new List <DummySink>();

            try
            {
                cap = null;
                if (src.isPlay)
                {
                    cap = new WasapiLoopbackCapture(src.mm);
                }
                else
                {
                    cap = new WasapiCapture(src.mm);
                }
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                string errmsg = WinapiShit.comEx((uint)ce.ErrorCode);
                if (errmsg == "")
                {
                    errmsg = "(i don't know what this means but please report it)";
                }

                MessageBox.Show("could not access audio device; error code " + ce.ErrorCode.ToString("x") + "\r\n\r\n" + errmsg);
                return;
            }

            cap.DataAvailable += input_DataAvailable;
            wi = new BufferedWaveProvider(cap.WaveFormat);
            var cap_samples   = wi.ToSampleProvider();
            var chan_splitter = new ChannelSplitter(cap_samples, chans);

            for (var a = 0; a < vus.Length; a++)
            {
                vus[a].SetSource(chan_splitter.output[a]);
                dummies.Add(new DummySink(vus[a]));
            }

            if (outDev >= -1)
            {
                wo = new WaveOut();
                wo.DeviceNumber = outDev;
                wo.Init(chan_splitter);
                wo.Play();
            }
            else
            {
                dummies.Add(new DummySink(chan_splitter));
                wo = null;
            }

            try
            {
                cap.StartRecording();
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                MessageBox.Show(WinapiShit.comExMsg((uint)ce.ErrorCode));
                return;
            }
            this.ok = true;
        }
Ejemplo n.º 2
0
        void doMagic()
        {
            Logger.mix.a("doMagic");
            cage = new List <Object>();
            string lq = "";

            recCap = null;
            micCap = null;
            recRe  = micRe = null;
            ISampleProvider recProv;

            format = WaveFormat.CreateIeeeFloatWaveFormat(settings.samplerate, 2);
            mixa   = new NPatch.Mixa(format);

            Logger.mix.a("create rec");
            if (settings.devRec is LSDevice)
            {
                recCap = new WasapiLoopbackCapture(((LSDevice)settings.devRec).mm);
            }
            else
            {
                recCap = new LSWavetailDev((LSWavetail)settings.devRec);
            }

            recCap.DataAvailable += recDev_DataAvailable_03;
            recIn = new BufferedWaveProvider(recCap.WaveFormat);

            //recIn.ReadFully = false;
            if (recCap.WaveFormat.SampleRate != settings.samplerate)
            {
                Logger.mix.a("create rec resampler");
                recRe = new MediaFoundationResampler(recIn, settings.samplerate);
                recRe.ResamplerQuality = 60;
                lq += "Incorrect samplerate on music device, resampling\n";

                if (settings.devRec is LSDevice)
                {
                    lq +=
                        ((LSDevice)settings.devRec).mm.DeviceFriendlyName + "\n" +
                        ((LSDevice)settings.devRec).mm.FriendlyName + "\n";
                }

                lq += settings.devRec.id + "\n" +
                      LSDevice.stringer(settings.devRec.wf) + "\n" +
                      LSDevice.stringer(recCap.WaveFormat) + "\n\n";
            }

            recProv = new WaveToSampleProvider((IWaveProvider)recRe ?? (IWaveProvider)recIn);
            if (recCap.WaveFormat.Channels != settings.chRec.Length)
            {
                cage.Add(recProv);
                Logger.mix.a("rec chanselector");
                recProv = new NPatch.ChannelSelectorIn(recProv, settings.chRec, 2);
            }
            cage.Add(recProv);
            recVol = new NPatch.VolumeSlider();
            recVol.SetSource(recProv);
            mixa.AddMixerInput(recVol);
            Logger.mix.a("rec done");

            killmic          = new System.Windows.Forms.Timer();
            killmic.Interval = 1000;
            killmic.Tick    += killmic_Tick;
            micVol           = new NPatch.VolumeSlider();
            lq += micAdd();

            NPatch.Fork fork = new NPatch.Fork(mixa, 2);
            cage.Add(fork);
            lameOutlet = fork.providers[1];
            outVol     = new NPatch.VolumeSlider();
            outVol.SetSource(fork.providers[0]);

            ISampleProvider outProv = outVol;

            if (settings.devOut.wf.Channels != settings.chOut.Length)
            {
                Logger.mix.a("create ChannelMapperOut " + settings.devOut.wf.Channels);
                outProv = new NPatch.ChannelMapperOut(outVol, settings.chOut, settings.devOut.wf.Channels);
                cage.Add(outProv);
            }
            SampleToWaveProvider muxer = new SampleToWaveProvider(outProv);

            cage.Add(muxer);

            Logger.mix.a("init mixer vol");
            recVol.SetVolume((float)settings.mixer.vRec);
            micVol.SetVolume((float)settings.mixer.vMic);
            outVol.SetVolume((float)settings.mixer.vOut);
            recVol.boostLock = (float)settings.mixer.yRec;
            micVol.boostLock = (float)settings.mixer.yMic;
            recVol.boost     = (float)settings.mixer.xRec;
            micVol.boost     = (float)settings.mixer.xMic;
            recVol.muted     = !settings.mixer.bRec;
            micVol.muted     = !settings.mixer.bMic;
            outVol.muted     = !settings.mixer.bOut;

            Logger.mix.a("create mixOut");
            mixOut = new WasapiOut(((LSDevice)settings.devOut).mm,
                                   AudioClientShareMode.Shared, false, 100);

            Logger.mix.a("init mixOut");
            mixOut.Init(muxer);

            try
            {
                Logger.mix.a("rec.startRec");
                recCap.StartRecording();

                if (micCap != null)
                {
                    Logger.mix.a("mic.startRec");
                    micCap.StartRecording();
                }
                //throw new System.Runtime.InteropServices.COMException("fgsfds", 1234);
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                string msg = WinapiShit.comExMsg((uint)ce.ErrorCode);
                System.Windows.Forms.MessageBox.Show(msg + "\r\n\r\ngonna crash now, bye");
                throw;
            }

            // give wasapicapture some time to fill the buffer
            startReading = new System.Windows.Forms.Timer();
            //startReading_Tick(null, null);
            startReading.Tick    += startReading_Tick;
            startReading.Interval = 300;
            startReading.Start();

            if (settings.vu)
            {
                recVol.enVU = true;
                micVol.enVU = true;
                outVol.enVU = true;
                bars[0].src = recVol;
                bars[1].src = micVol;
                bars[2].src = outVol;
            }

            if (!string.IsNullOrEmpty(lq))
            {
                isLQ = lq;
            }
        }