/// <summary> /// Destroys the audio renderer. /// Makes it useless. /// </summary> private void Destroy() { try { // Remove the event handler if (Application.Current != null) { MediaElement.InvokeOnUI(() => { Application.Current.Exit -= OnApplicationExit; }); } } catch { } if (AudioDevice != null) { AudioDevice.Stop(); AudioDevice.Dispose(); AudioDevice = null; } if (AudioBuffer != null) { AudioBuffer.Dispose(); AudioBuffer = null; } }
/// <summary> /// Initializes the audio renderer. /// Call the Play Method to start reading samples /// </summary> private void Initialize() { Destroy(); if (SoundTouch.IsAvailable) { AudioProcessor = new SoundTouch { Channels = (uint)WaveFormat.Channels, SampleRate = (uint)WaveFormat.SampleRate }; } AudioDevice = new WavePlayer(this) { DesiredLatency = 200, NumberOfBuffers = 2, }; SyncThesholdMilliseconds = 0.05 * DesiredLatency.TotalMilliseconds; // ~5% sync threshold for audio samples BytesPerSample = WaveFormat.BitsPerSample / 8; SampleBlockSize = BytesPerSample * WaveFormat.Channels; var bufferLength = WaveFormat.ConvertLatencyToByteSize(AudioDevice.DesiredLatency) * MediaElement.Blocks[MediaType.Audio].Capacity / 2; AudioBuffer = new CircularBuffer(bufferLength); AudioDevice.Init(this); AudioDevice.Play(); }
private void Play() { if (WavePlayer != null && AudioFileReader != null) { WavePlayer.Pause(); } }
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); blLoop = new BeatLoop(); this.Controls.Add(blLoop); blLoop.Left = 0; blLoop.Top = 0; blLoop.SetLoopState(new byte[16] { 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0 }); this.testSlider = new ThinSlider(); this.Controls.Add(this.testSlider); this.testSlider.Left = 5; this.testSlider.Top = 30; this.testSlider.Size = new Size(10, 100); this.testSlider.BackColor = Color.White; this.testSlider.ForeColor = Color.Navy; this._Player = new SoundPlayer(); this.Refresh(); }
/// <summary> /// Destroys the audio renderer. /// Makes it useless. /// </summary> private void Destroy() { try { if (Application.Current != null) { Runner.UIInvoke(DispatcherPriority.Send, () => { Application.Current.Exit -= OnApplicationExit; }); } } catch { } if (AudioDevice != null) { AudioDevice.Pause(); AudioDevice.Dispose(); AudioDevice = null; } if (AudioBuffer != null) { AudioBuffer.Dispose(); AudioBuffer = null; } if (AudioProcessor != null) { AudioProcessor.Dispose(); AudioProcessor = null; } }
/// <summary> /// Initializes the audio renderer. /// Call the Play Method to start reading samples /// </summary> private void Initialize() { Destroy(); if (SoundTouch.IsAvailable) { AudioProcessor = new SoundTouch { Channels = Convert.ToUInt32(WaveFormat.Channels), SampleRate = Convert.ToUInt32(WaveFormat.SampleRate) }; } AudioDevice = new WavePlayer(this) { DesiredLatency = 200, NumberOfBuffers = 2, }; SampleBlockSize = Constants.Audio.BytesPerSample * Constants.Audio.ChannelCount; var bufferLength = WaveFormat.ConvertLatencyToByteSize(AudioDevice.DesiredLatency) * MediaCore.Blocks[MediaType.Audio].Capacity / 2; AudioBuffer = new CircularBuffer(bufferLength); AudioDevice.Init(this); AudioDevice.Play(); }
private void button1_Click(object sender, System.EventArgs e) { ErnstTech.SoundCore.WaveForm form = new ErnstTech.SoundCore.WaveForm(new ErnstTech.SoundCore.WaveFormat(2, 44100, 16)); form.BaseFrequency = 200; Point[] points = new Point[this.beatBox1.Points.Count]; for (int i = 0, length = points.Length; i < length; ++i) { PointF pt = this.beatBox1.Points[i]; points[i] = new Point(Convert.ToInt32(pt.X), Convert.ToInt32(pt.Y)); } form.Points.AddRange(points); System.IO.Stream s = form.GenerateWave(); #if ERNST_DX_AUDIO System.Diagnostics.Debug.Assert(false); WavePlayer player = new WavePlayer( this, s ); player.Play(); #else this._Player.Stop(); this._Player.Stream = s; this._Player.Play(); #endif }
/// <summary> /// Destroys the audio renderer. /// Makes it useless. /// </summary> private void Destroy() { try { // Remove the event handler if (Application.Current != null) { Utils.UIInvoke(DispatcherPriority.Normal, () => { Application.Current.Exit -= OnApplicationExit; }); } } catch { } if (AudioDevice != null) { AudioDevice.Stop(); AudioDevice.Dispose(); AudioDevice = null; } if (AudioBuffer != null) { AudioBuffer.Dispose(); AudioBuffer = null; } }
protected override void Play() { if (string.IsNullOrEmpty(InputPath) || File.Exists(InputPath) == false) { MessageBox.Show("Select a valid input file or URL first"); return; } if (WavePlayer == null) { CreatePlayer(); } if (_lastPlayed != InputPath && _reader != null) { _reader.Dispose(); _reader = null; } if (_reader == null) { _reader = new Mp3FileReader(InputPath); VolumeProvider = new VolumeWaveProvider16(_reader) { Volume = Volume / 100 }; _lastPlayed = InputPath; WavePlayer.Init(VolumeProvider); Duration = _reader.TotalTime; } WavePlayer.Play(); UpdatePlayerState(); PlayerTimer.Start(); TaskbarOverlay = (ImageSource)Application.Current.FindResource("PlayImage"); SetTitle("Playing " + Path.GetFileName(InputPath)); }
private void Pause() { if (WavePlayer != null) { WavePlayer.Pause(); } }
public bool ReadyToPlay(string Path) { if (WavePlayer == null) { return(false); } try { WavePlayer.PlaybackStopped += WavePlayer_PlaybackStopped; if (Path.ToLower().EndsWith(".ogg")) { wave = new VorbisWaveReader(Path); } else { wave = new AudioFileReader(Path); } WavePlayer.Init(wave); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Initializes the audio renderer. /// Call the Play Method to start reading samples /// </summary> private void Initialize() { Destroy(); if (SoundTouch.IsAvailable) { AudioProcessor = new SoundTouch { Channels = (uint)WaveFormat.Channels, SampleRate = (uint)WaveFormat.SampleRate }; } AudioDevice = new WavePlayer(this) { DesiredLatency = 200, NumberOfBuffers = 2, }; BytesPerSample = WaveFormat.BitsPerSample / 8; SampleBlockSize = BytesPerSample * WaveFormat.Channels; var bufferLength = WaveFormat.ConvertLatencyToByteSize(AudioDevice.DesiredLatency) * MediaCore.Blocks[MediaType.Audio].Capacity / 2; AudioBuffer = new CircularBuffer(bufferLength); AudioDevice.Init(this); AudioDevice.Play(); }
public unsafe void Play() { if (this._wavePlayer == null && this._waveDuplex == null) { this._isPlaying = true; try { switch (this._inputType) { case InputType.SoundCard: if (this._inputDevice == this._outputDevice) { this._waveDuplex = new WaveDuplex(this._inputDevice, this._inputSampleRate, this._inputBufferSize, this.DuplexFiller); } else { this._iqCircularBuffer = new ComplexCircularBuffer(this._inputBufferSize, 6); this._audioCircularBuffer = new FloatCircularBuffer(this._outputBufferSize, 2); this._waveRecorder = new WaveRecorder(this._inputDevice, this._inputSampleRate, this._inputBufferSize, this.RecorderFiller); this._wavePlayer = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, this.PlayerFiller); this._dspThread = new Thread(this.DSPProc); this._dspThread.Start(); } break; case InputType.WaveFile: this._iqCircularBuffer = new ComplexCircularBuffer(this._inputBufferSize, 6); this._audioCircularBuffer = new FloatCircularBuffer(this._outputBufferSize, 2); this._wavePlayer = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, this.PlayerFiller); this._waveReadThread = new Thread(this.WaveFileFiller); this._waveReadThread.Start(); this._dspThread = new Thread(this.DSPProc); this._dspThread.Start(); break; case InputType.Plugin: this._iqCircularBuffer = new ComplexCircularBuffer(this._inputBufferSize, 6); this._audioCircularBuffer = new FloatCircularBuffer(this._outputBufferSize, 2); this._wavePlayer = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, this.PlayerFiller); if (this._frontend is IIQStreamController) { ((IIQStreamController)this._frontend).Start(this.FrontendFiller); } this._dspThread = new Thread(this.DSPProc); this._dspThread.Start(); break; } if (this._dspThread != null) { this._dspThread.Name = "DSP Thread"; } } catch { this._isPlaying = false; throw; } } }
protected override void Stop() { WavePlayer?.Stop(); TaskbarOverlay = null; PlayerTimer?.Stop(); Position = 0; SetTitle(Path.GetFileName(InputPath)); }
public void PlayWave(IWave wave) { var player = new WavePlayer(wave); player.Play(); _tracks.AddTrack(player); }
protected override void Pause() { WavePlayer?.Pause(); UpdatePlayerState(); PlayerTimer?.Stop(); TaskbarOverlay = (ImageSource)Application.Current.FindResource("PauseImage"); SetTitle("Pause " + Path.GetFileName(InputPath)); }
public void PlayFile(FileInfo file) { FileName = file.Name; WavePlayer.Stop(); AudioFile?.Dispose(); AudioFile = new AudioFileReader(file.FullName); WavePlayer.Init(AudioFile); TotalLength = AudioFile.TotalTime; }
/// <summary> /// In coming call. /// </summary> /// <param name="voipCall">VoIP call.</param> /// <param name="inComingCall">In coming call param.</param> /// <param name="contactsView">The contacts list view.</param> /// <param name="callsView">The calls list view.</param> /// <param name="conferenceView">The conference list view.</param> /// <param name="contacts">The contact list.</param> /// <param name="imageListSmall">The image list.</param> /// <param name="imageListLarge">The image list.</param> /// <param name="contactName">The contact name.</param> /// <param name="ringFilePath">The filename and path of the ringing audio.</param> /// <param name="audioDeviceIndex">The audio device index.</param> /// <param name="autoAnswer">Auto answer enabled.</param> /// <param name="autoAnswerFilePath">Auto answer file path..</param> /// <param name="autoAnswerWait">Auto answer wait time.</param> /// <param name="autoAnswerRecordingPath">Auto answer recording file and path.</param> /// <param name="messageBankWaitTime">The time to record the message.</param> /// <param name="redirectEnabled">The time to record the message.</param> /// <param name="redirectCallNumber">The time to record the message.</param> /// <param name="redirectCallAfter">The time to record the message.</param> public InComingCall(Nequeo.VoIP.PjSip.VoIPCall voipCall, Nequeo.VoIP.PjSip.Param.OnIncomingCallParam inComingCall, ListView contactsView, ListView callsView, ListView conferenceView, Data.contacts contacts, ImageList imageListSmall, ImageList imageListLarge, string contactName, string ringFilePath, int audioDeviceIndex = -1, bool autoAnswer = false, string autoAnswerFilePath = null, int autoAnswerWait = 30, string autoAnswerRecordingPath = null, int messageBankWaitTime = 20, bool redirectEnabled = false, string redirectCallNumber = "", int redirectCallAfter = -1) { InitializeComponent(); _contactName = contactName; _ringFilePath = ringFilePath; _voipCall = voipCall; _inComingCall = inComingCall; _callsView = callsView; _conferenceView = conferenceView; _contactsView = contactsView; _contacts = contacts; _imageListSmall = imageListSmall; _imageListLarge = imageListLarge; // Auto answer. _autoAnswer = autoAnswer; _autoAnswerFilePath = autoAnswerFilePath; _autoAnswerWait = autoAnswerWait; _autoAnswerRecordingPath = autoAnswerRecordingPath; _messageBankWaitTime = messageBankWaitTime; // Assign redirect call. _redirectEnabled = redirectEnabled; _redirectCallNumber = redirectCallNumber; _redirectCallAfter = redirectCallAfter; // If auto answer recording path. if (!String.IsNullOrEmpty(autoAnswerRecordingPath)) { // Create the recording file name and path. DateTime time = DateTime.Now; string audioRecodingExt = System.IO.Path.GetExtension(autoAnswerRecordingPath); string audioRecordingDir = System.IO.Path.GetDirectoryName(autoAnswerRecordingPath).TrimEnd(new char[] { '\\' }) + "\\"; string audioRecordingFile = System.IO.Path.GetFileNameWithoutExtension(autoAnswerRecordingPath) + "_" + contactName.Replace(" ", "").Replace("'", "") + "_" + time.Day.ToString() + "-" + time.Month.ToString() + "-" + time.Year.ToString() + "_" + time.Hour.ToString() + "-" + time.Minute.ToString() + "-" + time.Second.ToString(); // Create the file name. _autoAnswerRecordingPath = audioRecordingDir + audioRecordingFile + audioRecodingExt; } // If a valid audio device has been set. if (audioDeviceIndex >= 0) { // Get the audio device. Nequeo.IO.Audio.Device device = Nequeo.IO.Audio.Devices.GetDevice(audioDeviceIndex); _player = new WavePlayer(device); _player.PlaybackStopped += _player_PlaybackStopped; } }
public void Dettach() { if (WavePlayer != null) { WavePlayer.Stop(); WavePlayer.Dispose(); WavePlayer = null; } DeleteTemp(); }
public void Stop() { if (this._inputType == InputType.Plugin && this._frontend != null) { this._frontend.Stop(); this._frontend = null; } if (this._wavePlayer != null) { this._wavePlayer.Dispose(); this._wavePlayer = null; } if (this._waveRecorder != null) { this._waveRecorder.Dispose(); this._waveRecorder = null; } if (this._waveDuplex != null) { this._waveDuplex.Dispose(); this._waveDuplex = null; } this._inputSampleRate = 0.0; if (this._waveReadThread != null) { this._waveReadThread.Join(); this._waveReadThread = null; } if (this._iqStream != null) { this._iqStream.Close(); } if (this._audioStream != null) { this._audioStream.Close(); } if (this._dspThread != null) { this._dspThread.Join(); this._dspThread = null; } if (this._waveFile != null) { this._waveFile.Dispose(); this._waveFile = null; } if (this._iqStream != null) { this._iqStream.Dispose(); this._iqStream = null; } this._audioStream = null; this._dspOutBuffer = null; this._iqInBuffer = null; }
public static WavePlayer instance = null; //Used to creates an static instance script //Creates a non persistent singleton object private void OnEnable() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
protected override void Pause() { if (_playbackState == StreamingPlaybackState.Playing || _playbackState == StreamingPlaybackState.Buffering) { WavePlayer?.Pause(); _playbackState = StreamingPlaybackState.Paused; UpdatePlayerState(); SetTitle("Pause " + Path.GetFileName(InputPath)); } }
private void Stop() { if (WavePlayer != null) { WavePlayer.Stop(); } if (AudioFileReader != null) { AudioFileReader.Position = 0; } }
private void CloseFile() { AudioFileReader?.Dispose(); AudioFileReader = null; WavePlayer?.Dispose(); WavePlayer = null; Providers?.Dispose(); Providers = null; }
public void Stop() { this._isPlaying = false; if (this._inputType == InputType.Plugin && this._frontend is IIQStreamController) { ((IIQStreamController)this._frontend).Stop(); this._frontend = null; } if (this._iqCircularBuffer != null) { this._iqCircularBuffer.Close(); } if (this._audioCircularBuffer != null) { this._audioCircularBuffer.Close(); } if (this._wavePlayer != null) { this._wavePlayer.Dispose(); this._wavePlayer = null; } if (this._waveRecorder != null) { this._waveRecorder.Dispose(); this._waveRecorder = null; } if (this._waveDuplex != null) { this._waveDuplex.Dispose(); this._waveDuplex = null; } this._inputSampleRate = 0.0; if (this._waveReadThread != null) { this._waveReadThread.Join(); this._waveReadThread = null; } if (this._dspThread != null) { this._dspThread.Join(); this._dspThread = null; } if (this._waveFile != null) { this._waveFile.Dispose(); this._waveFile = null; } this._iqCircularBuffer = null; this._audioCircularBuffer = null; this._dspOutBuffer = null; }
public bool ValidateTrails(string referenceFiles, IList <string> sampleFiles) { using (var wavePlayer = new WavePlayer()) { if (wavePlayer.CompareSampleRates(referenceFiles, sampleFiles)) { return(true); } else { return(false); } } }
/// <summary> /// Initializes the audio renderer. /// Call the Play Method to start reading samples /// </summary> private void Initialize() { Destroy(); AudioDevice = new WavePlayer() { DesiredLatency = 200, NumberOfBuffers = 2, }; var bufferLength = WaveFormat.ConvertLatencyToByteSize(AudioDevice.DesiredLatency) * MediaElement.Blocks[MediaType.Audio].Capacity / 2; AudioBuffer = new CircularBuffer(bufferLength); AudioDevice.Init(this); }
protected override void OnTick(object sender, EventArgs eventArgs) { try { if (_playbackState != StreamingPlaybackState.Stopped) { UpdatePosition(); if (WavePlayer == null && _bufferedWaveProvider != null) { Debug.WriteLine("Creating WaveOut Device"); CreatePlayer(); VolumeProvider = new VolumeWaveProvider16(_bufferedWaveProvider) { Volume = Volume / 100 }; WavePlayer.Init(VolumeProvider); } else if (_bufferedWaveProvider != null) { var bufferedSeconds = _bufferedWaveProvider.BufferedDuration.TotalSeconds; ShowBufferState(bufferedSeconds); // make it stutter less if we buffer up a decent amount before playing if (bufferedSeconds < 0.5 && _playbackState == StreamingPlaybackState.Playing && !_fullyDownloaded) { _playbackState = StreamingPlaybackState.Buffering; WavePlayer.Pause(); } else if (bufferedSeconds >= 1 && _playbackState == StreamingPlaybackState.Buffering) { WavePlayer.Play(); _playbackState = StreamingPlaybackState.Playing; } else if (_fullyDownloaded && bufferedSeconds == 0) { Debug.WriteLine("Reached end of stream"); Stop(); } } UpdatePlayerState(); } } finally { PositionChanging = false; } }
public void EndPlugin() { if (!this.isLoaded) { return; } try { this.Logger.Trace("start DeInitPlugin"); // 設定ファイルを保存する Settings.Instance.Save(); FFXIV.Framework.Config.Save(); FFXIV.Framework.Config.Free(); EnvironmentHelper.GarbageLogs(); // ターゲット情報ワーカを終了する MainWorker.Instance.End(); // FFXIVプラグインへのアクセスを終了する XIVPluginHelper.Instance.End(); XIVPluginHelper.Free(); // 参照を開放する WavePlayer.Free(); MainWorker.Free(); Settings.Free(); if (this.PluginStatusLabel != null) { this.PluginStatusLabel.Text = "Plugin exited."; } this.Logger.Trace("end DeInitPlugin. succeeded."); } catch (Exception ex) { this.Logger.Fatal(ex, "DeInitPlugin error."); this.ShowMessage("DeInitPlugin error.", ex); } finally { AppLog.FlushAll(); } }
/// <summary> /// Load a sound by name from the working directory of the program /// </summary> /// <param name="soundName"></param> private void SoundLoad(string soundName, ref WavePlayer loadedSound, bool looping = false) { string absolutePath = AppDomain.CurrentDomain.BaseDirectory + "\\TornadoScript\\sounds\\" + soundName; if (File.Exists(absolutePath)) { loadedSound = new WavePlayer(absolutePath); loadedSound.SetLoopAudio(looping); } else { Logger.Log("Could not load audio file '{0}'. Expected path: '{1}'", soundName, absolutePath); } }
private void PreviewById(uint id) { PackResource Res = m_Pack.GetFileByIndex(id); Status.Text = Properties.Resources.Str_LoadingPreview; this.Update(); if (Res != null) { PicturePanel.Hide(); hexBox.ResetText(); TextView.Hide(); pPlay.Hide(); String InternalName = Res.GetName(); string Ext = System.IO.Path.GetExtension(@InternalName); // loading file content. byte[] buffer = new byte[Res.GetSize()]; Res.GetData(buffer); Res.Close(); switch (Ext) { case ".dds": case ".jpg": case ".gif": case ".png": case ".bmp": string Info = ""; if (Ext == ".dds") { Bitmap bmp = DDSDataToBMP(buffer); Info = "DDS (Direct Draw Surfice)"; PictureView.Image = bmp; } else { switch (Ext){ case ".jpg": Info = "JPEG"; break; case ".gif": Info = "GIF"; break; case ".bmp": Info = "Bitmap"; break; case ".png": Info = "PNG (Portable Network Graphic)"; break; } var ms = new MemoryStream(buffer); PictureView.Image = Image.FromStream(ms); ms.Dispose(); } PictureView.Update(); Status.Text = String.Format("{0} Image file. ({1} x {2})", Info, PictureView.Width, PictureView.Height); PictureView.SizeMode = PictureBoxSizeMode.AutoSize; PicturePanel.AutoScroll = true; PicturePanel.Update(); PicturePanel.Show(); break; case ".xml": case ".html": case ".txt": case ".trn": string text = Encoding.Unicode.GetString(buffer); TextView.Clear(); TextView.Text = text; TextView.Update(); TextView.Show(); Status.Text = String.Format("Ascii file."); break; case ".wav": case ".mp3": pPlay.Show(); // http://msdn.microsoft.com/en-us/library/ms143770%28v=VS.100%29.aspx this.wave = new WavePlayer(buffer); this.wave.Play(); Status.Text = "Sound file."; break; default: if (InternalName == "vf.dat") { TextView.Clear(); TextView.Text = Encoding.ASCII.GetString(buffer); TextView.Update(); TextView.Show(); Status.Text = "Version infomation."; } else { DynamicByteProvider d = new DynamicByteProvider(buffer); hexBox.ByteProvider = d; Status.Text = "Unknown file."; } break; } } this.Update(); }