Exemple #1
0
        public void FadeVolume(Slider slider, float vol, double seconds)
        {
            Logger.mix.a("fadeVol " + slider + " to " + vol + " over " + seconds);
            bool micOn  = slider == Slider.Mic && micVol.GetVolume() < 0.1 && vol > 0.1;
            bool micOff = slider == Slider.Mic && micVol.GetVolume() > 0.1 && vol < 0.1;

            if (micOn || micOff)
            {
                if (micOn)
                {
                    killmic.Stop();
                    if (!micVol.OK())
                    {
                        micAdd();
                        if (micVol.OK())
                        {
                            Logger.mix.a("mic.startRec");
                            micCap.StartRecording();
                        }
                    }
                }
                else if (settings.killmic)
                {
                    killmic.Stop();
                    killmic.Interval = (int)(seconds * 1000) + 250;
                    killmic.Start();
                }
                try
                {
                    LSSettings.LSParams[] encs = { settings.mp3, settings.ogg };
                    foreach (LSSettings.LSParams enc in encs)
                    {
                        if (enc.enabled && !string.IsNullOrWhiteSpace(enc.i.filename))
                        {
                            System.IO.File.AppendAllText(
                                enc.i.filename + ".txt",
                                enc.i.timestamp() + " " + (micOn ? "@" : "-") + "\r\n",
                                Encoding.UTF8);
                        }
                    }
                }
                catch { }
            }
            if (slider == Slider.Music)
            {
                recVol.SetVolume(vol, seconds);
            }
            if (slider == Slider.Mic)
            {
                micVol.SetVolume(vol, seconds);
            }
            if (slider == Slider.Out)
            {
                outVol.SetVolume(vol, seconds);
            }
            //Console.WriteLine("VOLFADE " + vol);
        }
Exemple #2
0
        void doMagic()
        {
            Logger.mix.a("doMagic");
            string lq = "";

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

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

            Logger.mix.a("create rec");
            recCap = new WasapiLoopbackCapture(settings.devRec.mm);
            recCap.DataAvailable += recDev_DataAvailable_03;
            recIn = new BufferedWaveProvider(recCap.WaveFormat);
            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" +
                      settings.devRec.mm.DeviceFriendlyName + "\n" +
                      settings.devRec.mm.FriendlyName + "\n" +
                      settings.devRec.id + "\n" +
                      LSDevice.stringer(settings.devRec.wf) + "\n" +
                      LSDevice.stringer(recCap.WaveFormat) + "\n\n";
            }
            recProv = new WaveToSampleProvider((IWaveProvider)recRe ?? (IWaveProvider)recIn);
            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();

            //mixer.ReadFully = true;
            fork       = new NPatch.Fork(mixa, 2);
            lameOutlet = fork.providers[1];
            outVol     = new NPatch.VolumeSlider();
            outVol.SetSource(fork.providers[0]);
            muxer = new SampleToWaveProvider(outVol);

            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(settings.devOut.mm,
                                   AudioClientShareMode.Shared, false, 100);



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

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

            //System.Threading.Thread.Sleep(100);
            if (micCap != null)
            {
                Logger.mix.a("mic.startRec");
                micCap.StartRecording();
            }
            Logger.mix.a("mixOut.play (ready)");
            mixOut.Play();

            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;
            }

            /*byte[] buffer = new byte[outVol.WaveFormat.AverageBytesPerSecond * 10];
             * while (true)
             * {
             *  int i = wp16.Read(buffer, 0, fork.providers[1].avail());
             *  waver.Write(buffer, 0, i);
             *  System.Threading.Thread.Sleep(10);
             *  System.Windows.Forms.Application.DoEvents();
             * }*/
        }
Exemple #3
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;
            }
        }