public static void PlayFile(String url) { if (url != "" && url != null) { url = @System.IO.Directory.GetCurrentDirectory() + url; if (NAudio.audioFileReader == null) { audioFileReader = new AudioFileReader(url); //waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(Loop); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); } else if (url != NAudio.audioFileReader.FileName) { waveOutDevice.Stop(); NAudio.audioFileReader.Dispose(); audioFileReader = new AudioFileReader(url); //waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(Loop); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); } } else if (NAudio.audioFileReader != null) { waveOutDevice.Stop(); NAudio.audioFileReader = null; } }
public soundplayer(string Path = "", bool playloop = false) { soundpath = Path; if (wavePlayer == null) { wavePlayer = new WaveOutEvent(); } playLoopBool = playloop; reader?.Dispose(); speedControl?.Dispose(); reader = null; speedControl = null; var file = soundpath; if (file != null && file != "") { reader = new AudioFileReader(file); speedControl = new VarispeedSampleProvider(reader, 100, new SoundTouchProfile(false, false)); wavePlayer.Init(speedControl); Play(); Script.Wait(1); Stop(); } }
/// <summary> /// Initialize a local audio player with given type /// </summary> /// <param name="fileName">the file name to play</param> /// <param name="waveOutType">the wave out type to use</param> public LocalAudioPlayer(string fileName, WaveOutType waveOutType) { this.fileName = fileName; PlaybackStopType = PlaybackStopTypes.PlaybackStoppedReachingEndOfFile; Debug.Assert(this.wavePlayer == null); this.wavePlayer = CreateWavePlayer(waveOutType); wavePlayer.PlaybackStopped += wavePlayer_PlaybackStopped; try { if (fileName.ToLowerInvariant().EndsWith(".ogg")) { vorbisReader = new VorbisWaveReader(fileName); wavePlayer.Init(vorbisReader); } else if (fileName.ToLowerInvariant().EndsWith(".flac")) { flacReader = new FlacReader(fileName); wavePlayer.Init(flacReader); } else { this.file = new AudioFileReader(fileName); this.wavePlayer.Init(file); } //this.wavePlayer.PlaybackStopped += wavePlayer_PlaybackStopped; } catch (Exception) { //throw; } //Play(); }
public void Play(string file) { if (File.Exists(file)) { getExtension(file); currentFile = file; if (isMp3 == true) { mp3FileReader = new Mp3FileReader(file); mp3FileReader.CurrentTime = TimeSpan.FromSeconds(currentPositon); MusicPlayer.Dispose(); MusicPlayer.Init(mp3FileReader); MusicPlayer.Play(); } else { audioFileReader = new AudioFileReader(file); audioFileReader.CurrentTime = TimeSpan.FromSeconds(currentPositon); MusicPlayer.Dispose(); MusicPlayer.Init(audioFileReader); MusicPlayer.Play(); } } }
private void pictureBox2_Click(object sender, EventArgs e) { using (StreamReader sr = new StreamReader(setting_path)) { Music = sr.ReadLine(); } if (Music == "0") { using (StreamWriter sw = new StreamWriter(setting_path)) { sw.WriteLine("1"); } pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + "\\Resources\\on.png"); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); } else { using (StreamWriter sw = new StreamWriter(setting_path)) { sw.WriteLine("0"); } pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + "\\Resources\\off.png"); waveOutDevice.Stop(); } }
public VoiceThroughNetAudio(string FileName, Guid outputDevice) { if (!System.IO.File.Exists(FileName)) { return; } // Creating the interface class //_waveOutDevice = new WaveOut(); if (outputDevice == Guid.Empty) { _waveOutDevice = new DirectSoundOut(100); } else { LastAudioDevice = outputDevice; _waveOutDevice = new DirectSoundOut(outputDevice, 100); } try { // creation of Stream input from the given file _mainOutputStream = CreateInputStream(FileName); if (_mainOutputStream == null) { throw new InvalidOperationException("Unsupported file extension"); } } catch (Exception createException) { if (Error != null) { Error("Audio - Play - CreateInputStream", createException.Message, createException.StackTrace); } return; } try { //Initialization _waveOutDevice.Init(_mainOutputStream); } catch (Exception initException) { if (Error != null) { Error("Audio - Play - Init", initException.Message, initException.StackTrace); } return; } // The event will stop execution -- hooked to that of class NAudio _waveOutDevice.PlaybackStopped += new EventHandler <StoppedEventArgs>(_waveOutDevice_PlaybackStopped); return; }
public MusicPlayer(string filePath) { FileInfo fi = new FileInfo(filePath); if (!fi.Exists) { //throw new FileNotFoundException("找不到音乐文件…", fi.FullName); filePath = Path.Combine(Domain.DefaultPath, "blank.wav"); } _reader = new MyAudioFileReader(filePath); //if (UseSoundTouch) _device = new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, Latency); //else // _device = new WaveOutEvent { DesiredLatency = App.Config.Play.DesiredLatency }; //_device = new WaveOutEvent { DesiredLatency = 70 }; _device.PlaybackStopped += (sender, args) => { PlayerStatus = PlayerStatus.Finished; }; if (UseSoundTouch) { // init provider _blockAlignReductionStream = new BlockAlignReductionStream(_reader); _waveChannel = new WaveChannel32(_blockAlignReductionStream); _provider = new CusBufferedWaveProvider(_waveChannel.WaveFormat); InitSoundTouch(); _device.Init(_provider); SetPlayMod(App.Config.Play.PlayMod); _playThread = new Thread(ProcessWave) { Name = "PlayThread" }; _playThread.Start(); } else { _device.Init(_reader); } PlayerStatus = PlayerStatus.Ready; Task.Run(() => { while (!_cts.IsCancellationRequested) { if (PlayerStatus != PlayerStatus.NotInitialized && _reader != null) { _reader.Volume = 1f * App.Config.Volume.Music * App.Config.Volume.Main; PlayTime = (int)_reader?.CurrentTime.TotalMilliseconds; if (PlayTime >= (int)_reader?.TotalTime.TotalMilliseconds) { PlayerStatus = PlayerStatus.Finished; } } Thread.Sleep(10); } }); }
public void Play(string name) { waveOutDevice.Volume = (float)mainWindow.VolumeSlider.Value; TimeSpan duration = new TimeSpan(); if (!firstTime) { Stop(); mainWindow.fileProgress.Value = 0; } if (name.Contains(".mp3")) { mp3Reader = new Mp3FileReader(name); waveOutDevice.Init(mp3Reader); waveOutDevice.Play(); firstTime = false; duration = mp3Reader.TotalTime; ismp3 = true; } if (name.Contains(".wav")) { waveReader = new WaveFileReader(name); waveOutDevice.Init(waveReader); waveOutDevice.Play(); firstTime = false; duration = waveReader.TotalTime; ismp3 = false; } InitTimer(); filepath = name; mainWindow.fileProgress.Maximum = Math.Round(duration.TotalSeconds, 0); double sec; double min = 0; sec = duration.TotalSeconds; if (sec / 60 > 1) { min = Math.Round(sec / 60, 0); sec -= min * 60; if (sec < 0) { sec = 60 + sec; min -= 1; } } string text = min + ":" + Math.Round(sec, 0); mainWindow.maxLabel.Content = text; }
/// <summary> /// 播放音频数据 /// </summary> /// <param name="playDatas">数据源</param> public void Play(byte[] playDatas) { BufferedWaveProvider bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(SimapleRate, Channel)); bufferedWaveProvider.BufferLength = playDatas.Length; bufferedWaveProvider.AddSamples(playDatas, 0, playDatas.Length); audioPlayer.Init(bufferedWaveProvider); audioPlayer.Play(); //bufferedWaveProvider.ClearBuffer(); //bufferedWaveProvider = null; }
public static void AudioPlay(string localFileName) { if (localFileName.EndsWith(".mp3")) { playerDevice.Init(mp3Reader); playerDevice.Play(); } else if (localFileName.EndsWith(".wav")) { playerDevice.Init(waveReader); playerDevice.Play(); } }
/// <summary> /// Play the music /// </summary> private void Play() { //Initialize Player if (Player == null) { Player = new WaveOut(); } if (SelectedItem == null) { return; } //if(SelectedItem.FullPath == Reader != null ? Reader. ) switch (Player.PlaybackState) { case PlaybackState.Playing: Player.Pause(); if (!Reader.Equals(new AudioFileReader(SelectedItem.FullPath))) { try { Reader.Dispose(); } catch { } Reader = new AudioFileReader(SelectedItem.FullPath); Player.Init(Reader); Player.Play(); } break; case PlaybackState.Paused: Player.Play(); break; case PlaybackState.Stopped: { try { Reader.Dispose(); } catch { } Reader = new AudioFileReader(SelectedItem.FullPath); Player.Init(Reader); Player.Play(); } break; } }
public override async Task InitializeAsync() { FileInfo fi = new FileInfo(_filePath); if (!fi.Exists) { //throw new FileNotFoundException("找不到音乐文件…", fi.FullName); _filePath = Path.Combine(Domain.DefaultPath, "blank.wav"); } _reader = new MyAudioFileReader(_filePath); //if (UseSoundTouch) _device = new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, Latency); //else // _device = new WaveOutEvent { DesiredLatency = App.Config.Play.DesiredLatency }; //_device = new WaveOutEvent { DesiredLatency = 70 }; _device.PlaybackStopped += (sender, args) => { PlayerStatus = PlayerStatus.Finished; RaisePlayerFinishedEvent(this, new EventArgs()); }; if (UseSoundTouch) { // init provider _blockAlignReductionStream = new BlockAlignReductionStream(_reader); _waveChannel = new WaveChannel32(_blockAlignReductionStream); _provider = new CusBufferedWaveProvider(_waveChannel.WaveFormat); InitSoundTouch(); _device.Init(_provider); SetPlayMod(PlayerConfig.Current.Play.PlayMod); _playThread = new Thread(ProcessWave) { Name = "PlayThread" }; _playThread.Start(); } else { _device.Init(_reader); } PlayerConfig.Current.Volume.PropertyChanged += Volume_PropertyChanged; Task.Factory.StartNew(UpdateProgress, TaskCreationOptions.LongRunning); PlayerStatus = PlayerStatus.Ready; RaisePlayerLoadedEvent(this, new EventArgs()); }
private void SelectInputFile() { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() == true) { if (TryOpenInputFile(ofd.OpenFile())) { InputPath = ofd.FileName; lastPlayed = InputPath; CreatePlayer(); wavePlayer.Init(reader); } } }
public void Play(Model.Song song) { if (song == null) { return; } if (audioFileReader != null) { audioFileReader.Dispose(); audioFileReader = null; } var t = Mp3Frame.LoadFromStream(null); NAudio.Wave.AcmMp3FrameDecompressor dec = new AcmMp3FrameDecompressor(new Mp3WaveFormat(t.SampleRate, 2, t.FrameLength, t.BitRate)); audioFileReader = new AudioFileReader(song.mp3Url); if (waveOutDevice != null) { waveOutDevice.Stop(); waveOutDevice.Dispose(); waveOutDevice = null; } waveOutDevice = new WaveOut(); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); }
void createPlayer(SongEntry entry) { tryStop(); source = new AudioFileReader(entry.Path); SpectrumSampler = new SampleAggregator(source, 512); meter = new BetterMeteringSampleProvider(SpectrumSampler); meter.StreamVolume += Meter_StreamVolume; SpectrumSampler.FftCalculated += ((sender, earg) => { }); SpectrumSampler.PerformFFT = true; output = new WaveOut() { DesiredLatency = 1, NumberOfBuffers = meter.WaveFormat.SampleRate / 256 }; output.Init(meter); output.PlaybackStopped += Output_PlaybackStopped; totalPosition = source.TotalTime; output.Volume = volume / 100f; onPlayPauseChanged?.Invoke(this, EventArgs.Empty); clearSongInfo(entry); onInfoLoaded?.Invoke(null, new SongCallbackEventArgs(entry)); Task getTask = new Task <SongEntry>(() => readAsync(entry)); getTask.Start(); getTask.ContinueWith(t => { onInfoLoaded?.Invoke(null, new SongCallbackEventArgs(entry)); }); onNewSong?.Invoke(null, EventArgs.Empty); }
public WasapiLoopbackCaptureProvider(MMDevice device) : base(new WasapiLoopbackCapture(device)) { _wasapiOut = new WasapiOut(device, AudioClientShareMode.Shared, true, 200); _wasapiOut.Init(new SilenceProvider(Wf.CreateIeeeFloatWaveFormat(44100, 2))); }
/// <summary> /// Lejátszik egy .mp3 fájlt /// </summary> /// <param name="audioFile">.mp3 fájl</param> public static void playWave(string audioFile) { thread = new WaveOut(); stream = CreateInputStream(audioFile); thread.Init(stream); thread.Play(); }
/// <summary> /// 连接到对方设备端 /// </summary> /// <param name="endPoint"></param> /// <param name="inputDeviceNumber"></param> /// <param name="codec"></param> private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec) { waveIn = new WaveIn(); waveIn.BufferMilliseconds = 50; waveIn.DeviceNumber = inputDeviceNumber; waveIn.WaveFormat = codec.RecordFormat; waveIn.DataAvailable += waveIn_DataAvailable; waveIn.StartRecording(); udpSender = new UdpClient(); udpListener = new UdpClient(); // To allow us to talk to ourselves for test purposes: // http://stackoverflow.com/questions/687868/sending-and-receiving-udp-packets-between-two-programs-on-the-same-computer udpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); udpListener.Client.Bind(endPoint); udpSender.Connect(endPoint); waveOut = new WaveOut(); waveProvider = new BufferedWaveProvider(codec.RecordFormat); waveOut.Init(waveProvider); waveOut.Play(); connected = true; var state = new ListenerThreadState { Codec = codec, EndPoint = endPoint }; ThreadPool.QueueUserWorkItem(ListenerThread, state); }
private void play_Click(object sender, EventArgs e) { if (playlist.SelectedItems.Count>0) { id = fn.IndexOf(playlist.SelectedItem.ToString()); if (waveOutDevice.PlaybackState.ToString() != "Paused") { t.Stop(); stp(); audioFileReader = new AudioFileReader(fp[id]); waveOutDevice = new WaveOut(); waveOutDevice.Init(audioFileReader); trackbar.Maximum = (int)audioFileReader.TotalTime.TotalSeconds + 1; //deb.Items.Add(audioFileReader.TotalTime.Seconds.ToString()); audioFileReader.Volume = (float)vol.Value / 100; waveOutDevice.Play(); t.Start(); } else { waveOutDevice.Play(); t.Start(); } } }
private void listViewBreakMusic_SelectedIndexChanged(object sender, EventArgs e) { if (listViewBreakMusic.SelectedItems.Count == 1) { try { createWaveOutBreak(); audioFileReaderBreak = new AudioFileReader(listViewBreakMusic.SelectedItems[0].SubItems[1].Text); var sampleChannel = new SampleChannel(audioFileReaderBreak, true); this.setVolumeDelegateBreak = (vol) => sampleChannel.Volume = vol; var postVolumeMeter = new MeteringSampleProvider(sampleChannel); postVolumeMeter.StreamVolume += onPostVolumeMeter; //waveOutDevice.Init(postVolumeMeter); waveOutDeviceBreak.Init(postVolumeMeter); volumeSlider1.Volume = 1.0f; } catch (Exception) { //Do nothing! } listViewBreakMusic.SelectedItems[0].EnsureVisible(); enableButtons(); } }
private static void Command_playmusic(string[] parameters) { if (parameters == null || parameters.Length != 1) { ConsoleManager.WriteLine("HELP: playmusic <trackname>.mp3"); } else { string MP3FileName = @"Music\" + parameters[0] + ".mp3"; if (File.Exists(MP3FileName)) { if (waveOutDevice.PlaybackState == PlaybackState.Playing || waveOutDevice.PlaybackState == PlaybackState.Paused) { waveOutDevice.Stop(); } audioFileReader = new AudioFileReader(@"Music\" + parameters[0] + ".mp3"); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); } else { ConsoleManager.WriteLine("Error! The specified music track not found!"); } } }
private void OnButtonPlayClick(object sender, EventArgs e) { if (waveOut == null) { try { waveOut = new WaveOutEvent(); waveOut.PlaybackStopped += OnPlaybackStopped; waveOut.Init(CreateInputStream()); } catch (Exception driverCreateException) { MessageBox.Show(driverCreateException.Message); return; } } if (waveOut.PlaybackState == PlaybackState.Playing) { return; } setVolumeDelegate(volumeSlider1.Volume); waveOut.Play(); playbackTimer.Enabled = true; UpdateTime(); }
public async Task PlayEpisodeAsync() { if (PlayingEpisode == SelectedEpisode && waveOutDevice.PlaybackState == PlaybackState.Playing) { return; } await podcastService.DownloadEpisodeAsync(SelectedEpisode); if (waveOutDevice.PlaybackState == PlaybackState.Playing || waveOutDevice.PlaybackState == PlaybackState.Paused) { waveOutDevice.Stop(); } audioFileReader = new AudioFileReader(selectedEpisode.LocalPath); waveOutDevice.Init(audioFileReader); audioFileReader.CurrentTime = TimeSpan.FromSeconds(SelectedEpisode.Timestamp); EpisodeLength = audioFileReader.TotalTime.TotalSeconds; audioFileReader.Volume = Volume; waveOutDevice.Play(); episodeIsPlayingTimer.Start(); PlayingEpisode = SelectedEpisode; this.OnPropertyChanged(nameof(PlayOrPauseButtonContent)); }
public void Play() { if (wavePlayer == null) { wavePlayer = new WaveOutEvent(); wavePlayer.PlaybackStopped += WavePlayerOnPlaybackStopped; } if (speedControl == null) { if (speedControl == null) { return; } } try { wavePlayer.Init(speedControl); play = true; } catch { } wavePlayer.Play(); }
//Voorkomt het voorkomen van audio-artifacts bij snel afspelen van dingen. public static void Cleanup() { outputDevice.Dispose(); outputDevice = null; outputDevice = new WaveOutEvent(); outputDevice.Init(mixingWaveProvider); }
internal NAudioSoundOutput() { _waveProvider = new BufferedWaveProvider(new WaveFormat(AudioFrequency, 8, Channels)); _wavePlayer = new WaveOutEvent(); _wavePlayer.Init(_waveProvider); _wavePlayer.Play(); }
/// <summary> /// 加载歌曲 /// </summary> /// <param name="itemm">要加载的歌曲</param> private static void Load(SongItem itemm) { if (Config.ControlOtherPlayer) { API.SendKey(System.Windows.Input.Key.MediaStop); } DanmukuReceiver.VoteUids.Clear(); waveout = Create(); FileReader = new Mp3FileReader(itemm._FilePath); var sampleChannel = new SampleChannel(FileReader, true); setVolumeDelegate = vol => sampleChannel.Volume = vol; var postVolumeMeter = new MeteringSampleProvider(sampleChannel); waveout.Init(postVolumeMeter); waveout.PlaybackStopped += Waveout_PlaybackStopped; SetVol(); lrc = itemm._FLyric ?? itemm.getFLyric(); }
private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec) { waveIn = new WaveIn(); waveIn.BufferMilliseconds = 50; waveIn.DeviceNumber = inputDeviceNumber; waveIn.WaveFormat = codec.RecordFormat; waveIn.DataAvailable += waveIn_DataAvailable; waveIn.StartRecording(); udpSender = new UdpClient(); udpListener = new UdpClient(); // To allow us to talk to ourselves for test purposes: // http://stackoverflow.com/questions/687868/sending-and-receiving-udp-packets-between-two-programs-on-the-same-computer udpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); udpListener.Client.Bind(endPoint); udpSender.Connect(endPoint); waveOut = new WaveOut(); waveProvider = new BufferedWaveProvider(codec.RecordFormat); waveOut.Init(waveProvider); waveOut.Play(); connected = true; var state = new ListenerThreadState { Codec = codec, EndPoint = endPoint }; ThreadPool.QueueUserWorkItem(ListenerThread, state); }
private void timer1_Tick(object sender, EventArgs e) { if (playbackState != StreamingPlaybackState.Stopped) { if (waveOut == null && bufferedWaveProvider != null) { Console.WriteLine("waveOut Created"); waveOut = CreateWaveOut(); waveOut.PlaybackStopped += OnPlaybackStopped; volumeProvider = new VolumeWaveProvider16(bufferedWaveProvider); volumeProvider.Volume = _volume; waveOut.Init(volumeProvider); } else if (bufferedWaveProvider != null) { var bufferedSeconds = bufferedWaveProvider.BufferedDuration.TotalSeconds; UpdateTimer(stopwatch.Elapsed.TotalMilliseconds); if (bufferedSeconds < 0.5 && playbackState == StreamingPlaybackState.Playing && !fullyDownloaded) { pause(); } else if (bufferedSeconds > 4 && playbackState == StreamingPlaybackState.Buffering) { play(); } else if (fullyDownloaded && bufferedSeconds == 0) { Console.WriteLine("Reached end of stream"); Stop(); } } } }
//============================================= public static bool OpenAudio(AudioLibrary AL, int sampleRate, int channels) { if (UsedLibrary != AudioLibrary.Null || (playbackDevice != null && playbackDevice.PlaybackState == PlaybackState.Playing)) { return(false); } UsedLibrary = AL; if (UsedLibrary == AudioLibrary.NAudio) { //NAUDIO Mixer32 = new RecordableMixerStream32(sampleRate, channels); Mixer32.AutoStop = false; // try asio playbackDevice = new AsioOut(0); // if failed, try normal wave out if (playbackDevice == null) { playbackDevice = new WaveOut(); } if (playbackDevice == null) { return(false); } playbackDevice.Init(Mixer32); //============================================= } return(true); }
private void OnButtonPlayClick(object sender, EventArgs e) { timer1.Enabled = true; if (reader == null) { OnButtonLoadFileClick(sender, e); if (reader == null) { return; } } if (wavePlayer == null) { if (radioButtonWasapi.Checked) { wavePlayer = new WasapiOutGuiThread(); } else { wavePlayer = new WaveOut(); } wavePlayer.PlaybackStopped += WavePlayerOnPlaybackStopped; wavePlayer.Init(reader); } wavePlayer.Play(); }
public override async Task InitializeAsync() { var fi = new FileInfo(_filePath); if (!fi.Exists) { _filePath = Path.Combine(Domain.DefaultPath, "blank.wav"); } _reader = new MyAudioFileReader(_filePath) { Volume = 1f * PlayerConfig.Current.Volume.Music * PlayerConfig.Current.Volume.Main }; _device = new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, Latency); _device.PlaybackStopped += (sender, args) => { PlayerStatus = PlayerStatus.Finished; RaisePlayerFinishedEvent(this, new EventArgs()); }; _device.Init(_reader); PlayerConfig.Current.Volume.PropertyChanged += Volume_PropertyChanged; Task.Factory.StartNew(UpdateProgress, TaskCreationOptions.LongRunning); PlayerStatus = PlayerStatus.Ready; RaisePlayerLoadedEvent(this, new EventArgs()); await Task.CompletedTask; }
void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec) { source = new WaveIn(); source.BufferMilliseconds = 50; source.DeviceNumber = inputDeviceNumber; source.WaveFormat = codec.RecordFormat; source.DataAvailable += waveIn_DataAvailable; source.StartRecording(); sendVoice = new UdpClient(); sendVoice.EnableBroadcast = true; receiveVoice = new UdpClient(); receiveVoice.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); receiveVoice.Client.Bind(endPoint); sendVoice.Connect(endPoint); waveOut = new WaveOut(); waveProvider = new BufferedWaveProvider(codec.RecordFormat); waveOut.Init(waveProvider); waveOut.Play(); connected = true; var state = new ListenerThreadState { Codec = codec, EndPoint = endPoint }; ThreadPool.QueueUserWorkItem(ListenerThread, state); }
public bool Load(string path, Guid device) { var cext = path.GetExt(); _myWaveOut = new DirectSoundOut(device); try { _myWaveStream = _codecs.First(v => v.Extensions.Contains(cext)).CreateWaveStream(path); } catch { return false; } if (_myWaveStream == null) return false; if (_myWaveStream.WaveFormat.Channels == 2) { _myBalanceSampleProvider = new BalanceSampleProvider(_myWaveStream.ToSampleProvider()); _myVolumeSampleProvider = new VolumeSampleProvider(_myBalanceSampleProvider); _myBalanceSampleProvider.Pan = (float)Balance; } else _myVolumeSampleProvider = new VolumeSampleProvider(_myWaveStream.ToSampleProvider()); _myEqualizer = new Equalizer(_myVolumeSampleProvider, _equalizerBands) { Enabled = _enableEqualizer }; _myWaveOut.Init(_myEqualizer); _myWaveOut.PlaybackStopped += MyWaveOutOnPlaybackStopped; _myVolumeSampleProvider.Volume = (float)Volume; return true; }
public PianoSynth() { mixer = new WaveMixerStream32(); mixer.AutoStop = false; int i = 0; foreach (var note in noteFiles) { reader[i] = new WaveFileReader(note); offsetStream[i] = new WaveOffsetStream(reader[i]); channelSteam[i] = new WaveChannel32(offsetStream[i]); channelSteam[i].Position = channelSteam[i].Length; mixer.AddInputStream(channelSteam[i]); i++; } if (waveOutDevice == null) { waveOutDevice = new WaveOut {DeviceNumber = 0}; waveOutDevice.Init(mixer); waveOutDevice.Volume = 0; waveOutDevice.Play(); waveOutDevice.Volume = 100; } }
public Audio(string filename) { this.fileName = filename; waveOutDevice = new DirectSoundOut(50); mainOutputStream = CreateInputStream(filename); waveOutDevice.Init(mainOutputStream); isPlaying = false; }
public AudioPlaybackEngine(int sampleRate = 44100, int channelCount = 2) { outputDevice = new WaveOutEvent(); mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount)); mixer.ReadFully = true; outputDevice.Init(mixer); outputDevice.Play(); }
public int PlayFile(string filename) { waveOutDevice = new WaveOut(); mainOutputStream = CreateInputStream(filename); waveOutDevice.Init(mainOutputStream); waveOutDevice.Play(); return 0; }
public AudioPlaya(string filename) { waveOutDevice = new WaveOut(); waveOutDevice.Init(stream = loadFromFile(filename)); waveOutDevice.PlaybackStopped += (object sender, StoppedEventArgs e) => { if (Finished != null) Finished(this); }; }
public void PlaySong() { // Instantiate audio player waveOutDevice = new WaveOut(); // Set MP3 to play audioFileReader = new AudioFileReader(GetSong()); // Init device and call play waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); }
public void Init(string waveFilePath) { // 4410 samples == 100 milliseconds int sampleRate = 44100; int blockSize = (int) (sampleRate * 0.15f); //6615; int channels = 2; vstStream = new VSTStream(sampleRate, channels, blockSize, this.plugins, waveFilePath); //blocksize 4410 samples gave stuttering? 6615 was perfect, 8820 was OK (small glitches)! playbackDevice = new WaveOut(WaveCallbackInfo.FunctionCallback()); playbackDevice.Init(vstStream); }
private void BeginPlayback(string filename) { Debug.Assert(wavePlayer == null); wavePlayer = CreateWavePlayer(); audioFileReader = new AudioFileReader(filename); audioFileReader.Volume = volumeSlider1.Volume; wavePlayer.Init(audioFileReader); wavePlayer.PlaybackStopped += OnPlaybackStopped; wavePlayer.Play(); EnableButtons(true); timer1.Enabled = true; // timer for updating current time label }
private void Play() { if (waveOut != null) { Stop(); } waveOut = new WaveOut(); this.patternSequencer = new DrumPatternSampleProvider(pattern); this.patternSequencer.Tempo = tempo; waveOut.Init(patternSequencer); waveOut.Play(); }
public override void Stage() { wavePlayer = new WaveOutEvent(); file = new AudioFileReader(_fileName); file.Volume = 1; wavePlayer.Init(file); wavePlayer.PlaybackStopped += new EventHandler<StoppedEventArgs>(PlaybackEnded); _currentStatus = Status.Staged; }
//Кнопка "Плей" private void button_play_Click(object sender, EventArgs e) { button_stop.Enabled = true; timer.Start(); ind = 2; waveOutDevice = new WaveOut(); mainOutputStream = CreateInputStream(outputFilename); waveOutDevice.Init(mainOutputStream); waveOutDevice.Play(); button_play.Enabled = false; button_rec.Enabled = false; numeric.Enabled = false; }
/// <summary> /// Joue le morceau /// </summary> public void play() { if (this.data != null) { terminated = false; outer = new WaveOut(); outer.Init(this.data); outer.Play(); outer.PlaybackStopped += outer_PlaybackStopped; } else this.load(true); }
public IWavePlayer PlayKillStreak(string sfxName, string ext = "wav") { KillStreakDevice = KillStreakDevice ?? new WaveOutEvent(); var path = SFXPath + sfxName + "." + ext; Wait(250); AudioFileReader audioFileReader = new AudioFileReader(path); audioFileReader.Volume = 0.6f * Volume; KillStreakDevice.Stop(); KillStreakDevice.Init(audioFileReader); KillStreakDevice.Play(); return KillStreakDevice; }
public void Start() { _audioSource.Listening = true; if (_audioSource.WaveOutProvider != null) { _waveOut = new DirectSoundOut(100); _waveOut.Init(_audioSource.WaveOutProvider); _waveOut.Play(); _audioSource.DataAvailable -= AudioSourceDataAvailable; _audioSource.DataAvailable += AudioSourceDataAvailable; _bTalking = true; } }
/// <summary> /// Joue le morceau /// </summary> public void play() { if (data != null || this.lastPlayed.AddMinutes(13) < DateTime.Now) { terminated = false; Console.WriteLine("Playing " + link); outer = new WaveOut(); outer.Init(this.data); outer.Play(); outer.PlaybackStopped += outer_PlaybackStopped; } else this.load(true); }
private void button_play_Click(object sender, EventArgs e) { if (!System.IO.File.Exists(textBox_filename.Text)) { MessageBox.Show("Please select a valid file to play."); return; } waveOutDevice = new WaveOut(); mainOutputStream = CreateInputStream(textBox_filename.Text); waveOutDevice.Init(mainOutputStream); waveOutDevice.Play(); }
public frmMain() { InitializeComponent(); device = new DirectSoundOut(); audio = new AudioFileReader("doowackadoo.mp3"); ; device.Init(GetAggregator(audio)); numSpectrumDetail_ValueChanged(null, null); var timer = new Timer(); timer.Interval = 1000 / 30; // second number = desired FPS timer.Tick += (sender, args) => Render(); timer.Start(); }
/// <summary> /// Setup Audio via NAudio. Defaults to using Asio for Audio Output. /// </summary> public void SetupAudio() { //Setup the Mixer mixer = new WaveMixerStream32(); mixer.AutoStop = false; if (waveOutDevice == null) { //waveOutDevice = new AsioOut(); waveOutDevice = new WaveOut(0, 300, false); waveOutDevice.Init(mixer); waveOutDevice.Play(); } }
public static bool PlayAudio(string fileName) { if (!System.IO.File.Exists(fileName)) return false; _wavePlayer = new WaveOut(); try { _waveStream = CreateInputStream(fileName); _wavePlayer.Init(_waveStream); } catch { return false; } return true; }
public AudioOut(FIFOStream stream) { mStream = stream; mStream.DataAvailable += mStream_DataAvailable; WaveFormat fmt = new WaveFormat(16000, 16, 1); mBuffOut = new BufferedWaveProvider(fmt); mBuffOut.DiscardOnBufferOverflow = true; mWaveOut = new WaveOutEvent(); mWaveOut.Init(mBuffOut); mPlaying = false; //start player thread mPlayEvent = new ManualResetEvent(false); mPlayer = new Thread(new ThreadStart(ThreadProc)); mPlayer.Priority = ThreadPriority.AboveNormal; mPlayer.Start(); }
private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < 4; i++) { sampleLoaded[i] = ""; } if (waveOutDevice == null) { waveOutDevice = new AsioOut(); waveOutDevice.Init(mixer); waveOutDevice.Play(); } }
public GeneratorPanel() { // Const log10FmaxFMin = Math.Log10(FMax/FMin); // Panel Init InitializeComponent(); Disposed += OnGeneratorPanelDisposed; // Init Audio driverOut = new WaveOutEvent(); //driverOut = new AsioOut(0); wg = new SignalGenerator(); // Par Default Frq 1200Hz cmbFrq.SelectedIndex = 0; cmbPrecisionFrq.SelectedIndex = 2; tbFrq.Value = 12; // 1200Hz CalculateTrackBarFrequency(); // Par Default Frq End 2000Hz cmbFrqEnd.SelectedIndex = 0; cmbPrecisionFrqEnd.SelectedIndex = 2; tbFrqEnd.Value = tbFrqEnd.Maximum; CalculateTrackBarEndFrequency(); // comboBox Type cmbType.DataSource = Enum.GetValues(typeof (SignalGeneratorType)); cmbType.SelectedIndex = 0; // Par Default Gain -20dB tbGain.Value = -20; CalculateTrackBarToGain(); // Par Default SweepSeconds tbSweepLength.Value = 10; CalculateTrackBarToSweepLength(); // Init Driver Audio driverOut.Init(wg); StartStopEnabled(); }
private void StartRecording(int deviceNumber) { // Setup Incoming m_WaveIn = new WaveIn(); m_WaveIn.BufferMilliseconds = 50; // This is very very important. m_WaveIn.DeviceNumber = deviceNumber; m_WaveIn.DataAvailable += WaveIn_DataAvailable; m_WaveIn.WaveFormat = m_waveFormat; m_WaveIn.StartRecording(); // Setup Output waveOut = new WaveOut(); waveProvider = new BufferedWaveProvider(m_waveFormat); waveOut.Init(waveProvider); waveOut.Play(); }
private async void Play() { if (player == null) { // Exclusive mode - fails with a weird buffer alignment error player = new WasapiOutRT(AudioClientShareMode.Shared, 200); player.Init(CreateReader); player.PlaybackStopped += PlayerOnPlaybackStopped; } if (player.PlaybackState != PlaybackState.Playing) { //reader.Seek(0, SeekOrigin.Begin); player.Play(); StopCommand.IsEnabled = true; PauseCommand.IsEnabled = true; LoadCommand.IsEnabled = false; } }
public AudioPlayer() { //Setup the Mixer mixer = new WaveMixerStream32Custom(); mixer.AutoStop = false; //initialize keys for (int i = 0; i < keyArray.Length; i++) { keyArray[i] = new Key(fileNames[i], audioSourcePath + fileNames[i] + ".wav"); mixer.AddInputStream(keyArray[i].channelStream); } if (waveOutDevice == null) { waveOutDevice = new WaveOut(); waveOutDevice.Init(mixer); mixer.Position = mixer.Length; waveOutDevice.Play(); } }
private async void Play() { if (reader == null) { return; } if (player == null) { // Exclusive mode - fails with a weird buffer alignment error //player = new MediaElementOut(MediaElement); player = new WasapiOutRT(AudioClientShareMode.Shared, 200); player.PlaybackStopped += PlayerOnPlaybackStopped; await player.Init(reader); } if (player.PlaybackState != PlaybackState.Playing) { player.Play(); StopCommand.IsEnabled = true; PauseCommand.IsEnabled = true; } }