コード例 #1
0
ファイル: LSMixer.cs プロジェクト: Wessie/Loopstream
        string micAdd()
        {
            string          ret = "";
            ISampleProvider micProv;

            if (micVol != null && micVol.OK())
            {
                return("");
            }

            if (settings.devMic != null && settings.devMic.mm != null)
            {
                Logger.mix.a("create mic");
                micCap = new WasapiCapture(settings.devMic.mm);
                micCap.DataAvailable += micDev_DataAvailable_03;
                micIn = new BufferedWaveProvider(micCap.WaveFormat);
                if (micCap.WaveFormat.SampleRate != settings.samplerate)
                {
                    Logger.mix.a("create mic resampler");
                    micRe = new MediaFoundationResampler(micIn, settings.samplerate);
                    micRe.ResamplerQuality = 60;
                    ret += "Incorrect samplerate on microphone device, resampling\n" +
                           settings.devMic.mm.DeviceFriendlyName + "\n" +
                           settings.devMic.mm.FriendlyName + "\n" +
                           settings.devMic.id + "\n" +
                           LSDevice.stringer(settings.devMic.wf) + "\n" +
                           LSDevice.stringer(micCap.WaveFormat) + "\n\n";
                }
                micProv = new WaveToSampleProvider((IWaveProvider)micRe ?? (IWaveProvider)micIn);
                if (micCap.WaveFormat.Channels == 1)
                {
                    Logger.mix.a("mic mono2stereo");
                    micProv = new MonoToStereoSampleProvider(micProv);
                }
                else if (settings.micLeft != settings.micRight)
                {
                    Logger.mix.a("mic chanselector");
                    micProv = new NPatch.ChannelSelector(micProv, settings.micLeft ? 0 : 1);
                }
                if (settings.reverbP > 0)
                {
                    micProv = new NPatch.Reverb(micProv);
                }

                micVol.SetSource(micProv);
                mixa.AddMixerInput(micVol);
                Logger.mix.a("mic done");
            }
            else
            {
                Logger.mix.a("mic skipped");
            }
            return(ret);
        }
コード例 #2
0
 public void runTests(Progress splesh, bool forceTest)
 {
     Program.DBGLOG = "";
     if (testDevs || forceTest)
     {
         StringBuilder sw = new StringBuilder();
         for (int a = 0; a < devs.Length; a++)
         {
             if (splesh != null)
             {
                 splesh.prog(a + 1, devs.Length);
             }
             //devs[a].test();
             try
             {
                 devs[a].test();
                 sw.AppendLine(devs[a].mm.ID);
                 sw.AppendLine(devs[a].mm.DeviceFriendlyName);
                 sw.AppendLine(devs[a].mm.FriendlyName);
                 try
                 {
                     sw.AppendLine(LSDevice.stringer(devs[a].wf));
                 }
                 catch
                 {
                     sw.AppendLine("*** bad wf ***");
                 }
             }
             catch
             {
                 sw.AppendLine("*!* bad dev *!*");
             }
             sw.AppendLine();
             sw.AppendLine("---");
             sw.AppendLine();
         }
         Program.DBGLOG += sw.ToString();
     }
 }
コード例 #3
0
ファイル: LSDevice.cs プロジェクト: bakape/Loopstream
 void makeSerializationData()
 {
     serializationData = LSDevice.stringer(wf);
 }
コード例 #4
0
ファイル: UI_Exception.cs プロジェクト: bakape/Loopstream
        void genExceptionData()
        {
            this.gRestart = null;
            try
            {
                Int32 nix = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                serPath = Program.tools + "loopstream-crash-" + nix + ".";

                var           se = new SerializableException(ex);
                StringBuilder sb = new StringBuilder();
                gi = new GeneralInfo(se, ex);

                LSSettings s = LSSettings.singleton;
                try
                {
                    if (s == null)
                    {
                        LSSettings.singleton = new LSSettings();
                        s      = LSSettings.singleton;
                        s.host = "nullsettings";
                    }
                    s.serverPresets = new List <LSSettings.LSServerPreset>();
                    s.metas         = new List <LSSettings.LSMeta>();
                    s.host          = "(redacted)";
                    s.pass          = "******";
                    sb.Append("\r\n// cfg\r\n" + GeneralInfo.ser(s));
                }
                catch (Exception exx) { }

                try
                {
                    var devs = new LSDevice[s.devs.Length];
                    for (var a = 0; a < devs.Length; a++)
                    {
                        devs[a] = s.devs[a] as LSDevice;
                    }

                    sb.Append("\r\n// devs\r\n" + GeneralInfo.ser(devs));
                }
                catch (Exception exx) { }

                sb.AppendLine();
                try
                {
                    sb.AppendLine("\n\n\n\n\nCache for opus"); sb.AppendLine(Logger.opus.compile());
                    sb.AppendLine("\n\n\n\n\nCache for ogg"); sb.AppendLine(Logger.ogg.compile());
                    sb.AppendLine("\n\n\n\n\nCache for mp3"); sb.AppendLine(Logger.mp3.compile());
                    sb.AppendLine("\n\n\n\n\nCache for pcm"); sb.AppendLine(Logger.pcm.compile());
                    sb.AppendLine("\n\n\n\n\nCache for med"); sb.AppendLine(Logger.med.compile());
                    sb.AppendLine("\n\n\n\n\nCache for mix"); sb.AppendLine(Logger.mix.compile());
                    sb.AppendLine("\n\n\n\n\nCache for tag"); sb.AppendLine(Logger.tag.compile());
                    sb.AppendLine("\n\n\n\n\nCache for app"); sb.AppendLine(Logger.app.compile());
                }
                catch { }
                serText = gi.ToString() + "\r\n" + sb.ToString();
                System.IO.File.WriteAllText(serPath + "1.txt", serText, Encoding.UTF8);

                InitializeComponent();
                gDesc.Text      = "L o a d i n g    d e t a i l s . . .";
                linkLabel1.Text = serPath + "1.txt";
                gDesc.Enabled   = gIgnOnce.Enabled = gIgnAlways.Enabled = gRestart.Enabled = false;
            }
            catch (Exception exx)
            {
                serText = null;
                string desc = "";
                try
                {
                    var msg = ex.Message + "\r\n\r\n" + ex.StackTrace;

                    desc = "Shit is properly f****d, can't send error information to devs\r\n" +
                           "This is the best I can do:\r\n\r\n" + msg;

                    System.IO.File.WriteAllText(serPath + "0.txt", msg, Encoding.UTF8);
                    linkLabel1.Text = serPath + "0.txt";
                }
                catch
                {
                    desc = "Shit is properly f****d, can't send error information to devs";
                }

                if (this.gRestart == null)
                {
                    InitializeComponent();
                }

                gDesc.Text    = desc;
                gDesc.Enabled = gIgnOnce.Enabled = gIgnAlways.Enabled = gRestart.Enabled = true;
                gRestart.Focus();
            }
        }
コード例 #5
0
ファイル: UI_Chanvis.cs プロジェクト: bakape/Loopstream
        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;
        }
コード例 #6
0
ファイル: UI_Chanvis.cs プロジェクト: bakape/Loopstream
 public UI_Chanvis(LSDevice src, int[] chans)
 {
     this.src   = src;
     this.chans = chans;
     InitializeComponent();
 }
コード例 #7
0
ファイル: LSMixer.cs プロジェクト: Wessie/Loopstream
        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();
             * }*/
        }
コード例 #8
0
        public void init()
        {
            List <LSDevice> ldev = new List <LSDevice>();

            try
            {
                NAudio.CoreAudioApi.MMDeviceEnumerator mde = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                Logger.app.a("Created MM enumerator");
                try
                {
                    foreach (
                        NAudio.CoreAudioApi.MMDevice device
                        in mde.EnumerateAudioEndPoints(
                            NAudio.CoreAudioApi.DataFlow.All,
                            NAudio.CoreAudioApi.DeviceState.All))
                    {
                        try
                        {
                            LSDevice add = new LSDevice();
                            add.mm     = device;
                            add.isRec  = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture;
                            add.isPlay = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Render;
                            if (device.DataFlow == NAudio.CoreAudioApi.DataFlow.All)
                            {
                                add.isRec = add.isPlay = true;
                            }
                            Logger.app.a("Df " + add.isPlay + " " + add.isRec);

                            add.id = device.ID;
                            Logger.app.a("ID " + add.id);

                            add.name = device.ToString();
                            Logger.app.a("Na " + add.name);

                            ldev.Add(add);
                        }
                        catch { Logger.app.a("Failed !"); }
                    }
                }
                catch { Logger.app.a("Failed !!"); }
            }
            catch { Logger.app.a("Failed !!!"); }

            devs = ldev.ToArray();
            if (string.IsNullOrEmpty(s_devRec))
            {
                s_devRec = "";
            }
            if (string.IsNullOrEmpty(s_devMic))
            {
                s_devMic = "";
            }
            if (string.IsNullOrEmpty(s_devOut))
            {
                s_devOut = "";
            }
            if (!string.IsNullOrEmpty(s_devRec))
            {
                devRec = getDevByID(s_devRec);                                  // ?? devs.First(x => x.isPlay);
            }
            if (!string.IsNullOrEmpty(s_devMic))
            {
                devMic = getDevByID(s_devMic);
            }
            if (!string.IsNullOrEmpty(s_devOut))
            {
                devOut = getDevByID(s_devOut);
            }
        }
コード例 #9
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;
            }
        }