/// <summary> /// Shutdown the emulation. This will set the EmulationON to false as well. /// </summary> public static void ShutDown() { if (!INITIALIZED) { return; } EmulationON = false; MEMShutdown(); if (videoOut != null) { videoOut.ShutDown(); } // videoOut = null; if (AudioOut != null) { AudioOut.Shutdown(); } // AudioOut = null; System.GC.Collect(); CPUShutdown(); PPUShutdown(); APUShutdown(); if (EMUShutdown != null) { EMUShutdown(null, new EventArgs()); } INITIALIZED = false; }
private void CloseAudioOut(AudioOut audioOut) { if (audioOut == null) { return; } var endTime = (exit ? DateTime.UtcNow : nextStart) + TimeSpan.FromSeconds(1); try { float secondsRemaining() => Math.Max(0, Math.Min((float)audioOut.TimeBuffered.TotalSeconds, (float)(endTime - DateTime.UtcNow).TotalSeconds)); while (secondsRemaining() > 1) { Thread.Sleep(1); } this.LogDebug("Volume slide down start."); float volume = audioOut.Volume; while (audioOut.Volume > 0) { audioOut.Volume = Math.Max(0, secondsRemaining() * volume); Thread.Sleep(1); } } catch { } this.LogDebug("Volume slide down completed."); try { lock (audioOut) audioOut.Dispose(); } catch { } }
protected virtual void Dispose(bool disposing) { if (disposing) { System.Dispose(); AudioOut.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (disposing) { System.Dispose(); Host1x.Dispose(); AudioOut.Dispose(); FileSystem.Unload(); Memory.Dispose(); } }
private void SetAdvanced(bool showAdvanced) { Network.SetValue(NetworkWPF.ShowAdvancedControlsProperty, showAdvanced); if (AudioIn != null) { AudioIn.SetValue(AudioInWPF.ShowAdvancedControlsProperty, showAdvanced); } if (AudioOut != null) { AudioOut.SetValue(AudioOutWPF.ShowAdvancedControlsProperty, showAdvanced); } }
protected virtual void Dispose(bool disposing) { if (disposing) { ConfigurationState.Instance.Hid.InputConfig.Event -= Hid.RefreshInputConfigEvent; System.Dispose(); Host1x.Dispose(); AudioOut.Dispose(); FileSystem.Unload(); Memory.Dispose(); } }
void Window_Closed(object sender, EventArgs e) { Settings.InvokeAppClosing(this); Settings.Container.Save(); if (AudioIn != null) { AudioIn.Dispose(); } if (AudioOut != null) { AudioOut.Dispose(); } }
private static void OnFinishFrame() { InputFinishFrame(); ImmediateFrameTime = CurrentFrameTime = GetTime() - LastFrameTime; DeadTime = FramePeriod - CurrentFrameTime; // Sound if (SoundEnabled) { if (!AudioOut.IsPlaying) { AudioOut.Play(); } // Blip buffer //audio_playback_blipbuffer.EndFrame(audio_playback_blipbuffer_timer); audio_playback_blipbuffer.EndFrame((uint)audio_playback_blipbuffer_timer); audio_playback_blipbuffer_timer = 0; // Submit call // byte[] returnBuffer = new byte[audio_playback_blipbuffer.SamplesAvailable() * 2]; // audio_playback_blipbuffer.ReadSamples(returnBuffer, 0, audio_playback_blipbuffer.SamplesAvailable()); short[] returnBuffer = new short[audio_playback_blipbuffer.SamplesAvailable()]; audio_playback_blipbuffer.ReadSamples(returnBuffer, audio_playback_blipbuffer.SamplesAvailable(), false); AudioOut.Update(ref returnBuffer); } // Speed if (SpeedLimitterON) { while (ImmediateFrameTime < FramePeriod) { ImmediateFrameTime = GetTime() - LastFrameTime; } } LastFrameTime = GetTime(); // FPS FPSDone++; // Reset if (FPSDone > 1000) { FPSDone = 0; } if (request_pauseAtFrameFinish) { request_pauseAtFrameFinish = false; EmulationPaused = true; } }
/// <summary> /// This method is called when this form is closed. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event data.</param> private void wfrm_Main_FormClosed(object sender, FormClosedEventArgs e) { m_IsRunning = false; if (m_pRtpSession != null) { m_pRtpSession.Close(null); m_pRtpSession = null; } if (m_pWaveOut != null) { m_pWaveOut.Dispose(); m_pWaveOut = null; } if (m_pRecordStream != null) { m_pRecordStream.Dispose(); m_pRecordStream = null; } }
IAudioDevice SelectDevice() { IAudioAPI[] apis = AudioAPI.GetAvailableAudioAPIs(); List <IAudioDevice> devices = GetDevices(apis); foreach (var device in devices) { try { this.LogDebug("Trying Audio API <cyan>{0}<default> Device <cyan>{1}", device.API, device); using (AudioOut check = device.CreateAudioOut(new AudioConfiguration(44100, AudioSampleFormat.Int16, 2))) { this.LogInfo("Selecting Audio API <cyan>{0}<default> Device <cyan>{1}", device.API, device); return(device); } } catch (Exception ex) { this.LogWarning(ex, "Cannot startup audio device <red>{0}", device); } } return(null); }
private void btnRestartConnection_Click_1(object sender, RoutedEventArgs e) { if (cbLocalIp.SelectedIndex < 0) { MessageBox.Show("Choose local IP"); return; } IsConnected = true; InitializeClient(); InitializeServer(); /*InitializeSoundSender(); * InitializeSoundReceiver();*/ if (m_IsRunning) { m_IsRunning = false; m_IsSendingTest = false; m_pRtpSession.Dispose(); m_pRtpSession = null; m_pWaveOut.Dispose(); m_pWaveOut = null; } else { m_IsRunning = true; switch (_selectedCodec) { case "PCMU": m_pActiveCodec = new PCMU(); break; case "PCMA": default: m_pActiveCodec = new PCMA(); break; } var selectedOutDevice = cbAudioOutDevices.SelectedItem as AudioOutDevice; m_pWaveOut = new AudioOut(selectedOutDevice, _samplesPerSecond, _bitsPerSample, 1); // 1 - one channel (mono) m_pRtpSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME()); string localIp = cbLocalIp.SelectedItem.ToString(); string partnerIp = tbxPartnerIp.Text; int k = string.Compare(localIp, partnerIp); m_pRtpSession.CreateSession(new RTP_Address(IPAddress.Parse(cbLocalIp.SelectedItem.ToString()), (int)10000 + k * 500 /*m_pLocalPort.Value*/, (int)/*m_pLocalPort.Value*/ 10000 + k * 500 + 1), new RTP_Clock(0, _samplesPerSecond)); m_pRtpSession.Sessions[0].AddTarget(new RTP_Address(IPAddress.Parse(tbxPartnerIp.Text), (int)/*m_pRemotePort.Value*/ 10000 - k * 500, (int)/*m_pRemotePort.Value*/ 10000 - k * 500 + 1)); m_pRtpSession.Sessions[0].NewSendStream += new EventHandler <RTP_SendStreamEventArgs>(m_pRtpSession_NewSendStream); m_pRtpSession.Sessions[0].NewReceiveStream += new EventHandler <RTP_ReceiveStreamEventArgs>(m_pRtpSession_NewReceiveStream); m_pRtpSession.Sessions[0].Payload = 0; m_pRtpSession.Sessions[0].Start(); m_pAudioCodecs = new Dictionary <int, AudioCodec>(); m_pAudioCodecs.Add(0, new PCMU()); m_pAudioCodecs.Add(8, new PCMA()); } }
private void m_pToggleRun_Click(object sender, EventArgs e) { if (m_IsRunning) { m_IsRunning = false; m_IsSendingTest = false; m_pRtpSession.Dispose(); m_pRtpSession = null; m_pWaveOut.Dispose(); m_pWaveOut = null; if (m_pRecordStream != null) { m_pRecordStream.Dispose(); m_pRecordStream = null; } m_pOutDevices.Enabled = true; m_pToggleRun.Text = "Start"; m_pRecord.Enabled = true; m_pRecordFile.Enabled = true; m_pRecordFileBrowse.Enabled = true; m_pRemoteIP.Enabled = false; m_pRemotePort.Enabled = false; m_pCodec.Enabled = false; m_pToggleMic.Text = "Send"; m_pToggleMic.Enabled = false; m_pSendTestSound.Enabled = false; m_pSendTestSound.Text = "Send"; m_pPlayTestSound.Enabled = false; m_pPlayTestSound.Text = "Play"; } else { if (m_pOutDevices.SelectedIndex == -1) { MessageBox.Show(this, "Please select output device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (m_pRecord.Checked && m_pRecordFile.Text == "") { MessageBox.Show(this, "Please specify record file !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (m_pRecord.Checked) { m_pRecordStream = File.Create(m_pRecordFile.Text); } m_IsRunning = true; m_pWaveOut = new AudioOut(AudioOut.Devices[m_pOutDevices.SelectedIndex], 8000, 16, 1); m_pRtpSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME()); // --- Debug ----- wfrm_RTP_Debug frmRtpDebug = new wfrm_RTP_Debug(m_pRtpSession); frmRtpDebug.Show(); //----------------- // m_pRtpSession.CreateSession(new RTP_Address(IPAddress.Parse(m_pLocalIP.Text),(int)m_pLocalPort.Value,(int)m_pLocalPort.Value + 1),new RTP_Clock(0,8000)); string ip = "127.0.0.1"; int port = 1100; int remote_port = 20700; //RTP_Session session = m_pRtpSession.CreateSession(new RTP_Address(IPAddress.Parse(ip), port, port + 1), new RTP_Clock(0, 8000)); //session.AddTarget(new RTP_Address(IPAddress.Parse("127.0.0.1"), remote_port, remote_port + 1)); RTP_Session session = m_pRtpSession.CreateMulticastSession(new RTP_Address(IPAddress.Parse(ip), port, port + 1), new RTP_Clock(0, 8000), null); session.AddTarget(new RTP_Address(IPAddress.Parse("224.0.0.1"), remote_port, remote_port + 1)); session.Payload = 0; session.Start(); m_pOutDevices.Enabled = false; m_pToggleRun.Text = "Stop"; m_pRecord.Enabled = false; m_pRecordFile.Enabled = false; m_pRecordFileBrowse.Enabled = false; m_pRemoteIP.Enabled = true; m_pRemotePort.Enabled = true; m_pCodec.Enabled = true; m_pToggleMic.Enabled = true; m_pSendTestSound.Enabled = true; m_pSendTestSound.Text = "Send"; m_pPlayTestSound.Enabled = true; m_pPlayTestSound.Text = "Play"; } wfrm_SendAudio frm = new wfrm_SendAudio(this, m_pRtpSession.Sessions[0], @"D:\_d\_PROJECTS\CisteraDesktopNotificationService\Lumisoft.Net.Rtp\Rtp Audio Demo\Rtp Audio Demo\bin\Debug\audio\futurama.raw"); frm.Show(); }
private void CloseAudioOutAsync(AudioOut audioOut) { Task.Factory.StartNew((a) => { CloseAudioOut(a as AudioOut); }, audioOut); }
/// <summary> /// Run the emulation loop while EmulationON is true. /// </summary> public static void EMUClock() { while (EmulationON) { if (!EmulationPaused) { CPUClock(); } else { EmuStatus = EmulationStatus.PAUSED; if (AudioOut != null) { AudioOut.Pause(); } if (request_save_sram) { EmuStatus = EmulationStatus.SAVINGSRAM; request_save_sram = false; SaveSRAM(); EmulationPaused = false; } if (request_hardReset) { EmuStatus = EmulationStatus.HARDRESET; request_hardReset = false; hardReset(); EmulationPaused = false; } if (request_softReset) { EmuStatus = EmulationStatus.SOFTRESET; request_softReset = false; softReset(); EmulationPaused = false; } if (request_state_save) { EmuStatus = EmulationStatus.SAVINGSTATE; request_state_save = false; SaveStateAs(STATEFileName); EmulationPaused = false; } if (request_state_load) { EmuStatus = EmulationStatus.LOADINGSTATE; request_state_load = false; LoadStateAs(STATEFileName); EmulationPaused = false; } if (request_snapshot) { EmuStatus = EmulationStatus.SAVINGSNAP; request_snapshot = false; videoOut.TakeSnapshot(SNAPSFolder, SNAPSFileName, SNAPSFormat, SNAPSReplace); EmulationPaused = false; } Thread.Sleep(100); } } // Shutdown ShutDown(); }
public static void CreateOutput() { _client = new Processor("testNaudioOut", 0, 2); _jackOut = new AudioOut(_client); }