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); }
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(); } }
void makeSerializationData() { serializationData = LSDevice.stringer(wf); }
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(); * }*/ }
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; } }