private void btnTest_CheckedChanged(object sender, EventArgs e) { if (btnTest.Checked) { try { WaveFileReader reader = new WaveFileReader(inputPath.Text); LoopStream loop = new LoopStream(reader); waveOut = new WaveOut(); waveOut.Init(loop); waveOut.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } else { try { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } }
protected SoundPlayer(string filePath, bool enableLooping) { var reader = new WaveFileReader(this.startupPath + filePath); this.stream = new LoopStream(reader, enableLooping); this.Init(); }
public override void LoadContent() { input = new Input(); dfp20 = ScreenManager.Content.Load <SpriteFont>("Font/dfp20"); donIdleSheet = ScreenManager.Content.Load <Texture2D>("Texture/Don/Anim/SongSelect/idle"); bgMask = ScreenManager.Content.Load <Texture2D>("Texture/SongSelect/bgMask"); timerBg = ScreenManager.Content.Load <Texture2D>("Texture/SongSelect/timer"); selectSongText = ScreenManager.Content.Load <Texture2D>("Texture/SongSelect/selectText"); menu = new Menu(ScreenManager.Content, ScreenManager.SpriteBatch); menu.LoadContent(); animator = new SpriteAnimator(ScreenManager.SpriteBatch); donIdle = new SpriteAnimation(donIdleSheet, new Vector2(291, 291), new Vector2(10, 3), 30, 1000f / ((30 * 116) / 60), true); animator.Add("idle", donIdle); animator.Switch("idle"); idleLoop = new WaveFileReader("Content/Music/SongSelect/idle.wav"); idleLoopStream = new LoopStream(idleLoop, 254437); music = new Jukebox(); music.Play(idleLoopStream); sfx = new Jukebox(); kat = ScreenManager.Content.Load <SoundEffect>("kat"); base.LoadContent(); }
public void ChangeMusic(int musicIDIntro, int musicIDLoop) { //Fade for (int i = 0; i < 4; i++) { waveOutIntro.Volume -= (float)0.05; waveOutLoop.Volume -= (float)0.05; Thread.Sleep(100); } waveOutIntro.Pause(); waveOutLoop.Pause(); waveOutIntro.Dispose(); waveOutLoop.Dispose(); LoopStream loopStream = new LoopStream(musics[musicIDLoop]); loopStream.EnableLooping = true; waveOutIntro.Init(musics[musicIDIntro]); waveOutLoop.Init(loopStream); waveOutIntro.Volume = (float)0.5; waveOutLoop.Volume = (float)0.5; waveOutIntro.Play(); while (waveOutIntro.PlaybackState != PlaybackState.Stopped) { ; } waveOutLoop.Play(); }
public PlayingSound PlaySound(string fileName, float volume = 1f, bool loop = false) { if (isDisposed) { return(null); } if (!File.Exists(fileName)) { return(null); } var input = new AudioFileReader(fileName) { Volume = volume }; if (loop) { var looper = new LoopStream(input); var sample = looper.ToSampleProvider(); AddMixerInput(sample); return(new PlayingSound(input, looper, sample)); } else { var autoDispose = new AutoDisposeFileReader(input); AddMixerInput(autoDispose); return(new PlayingSound(input)); } }
private void button1_Click(object sender, EventArgs e) { var ofn = new OpenFileDialog(); ofn.Filter = CodecFactory.SupportedFilesFilterEN; if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Stop(); if (WasapiOut.IsSupportedOnCurrentPlatform) { _soundOut = new WasapiOut(); } else { _soundOut = new DirectSoundOut(); } var source = CodecFactory.Instance.GetCodec(ofn.FileName); source = new LoopStream(source) { EnableLoop = false }; (source as LoopStream).StreamFinished += (s, args) => Stop(); _eq = Equalizer.Create10BandEqualizer(source); _soundOut.Initialize(_eq.ToWaveSource(16)); _soundOut.Play(); } }
public void play(string music, bool fromBegin) { if (isPlaying != music) { if (isPlaying != "") { stop(); } isPlaying = music; var imageReplace = luastate["musicReplace"] as LuaFunction; var res = (string)imageReplace?.Call(music.ToLower())?.First(); audioFile = new LoopStream(new AudioFileReader(res ?? @"documents\hot\audio\" + music)); if (!fromBegin && timeRecord.ContainsKey(music)) { audioFile.Position = timeRecord[music]; } waveOutDevice = new WaveOut(); waveOutDevice.Init(audioFile); waveOutDevice.Play(); } else { if (fromBegin) { audioFile.Position = 0; } } }
/// <summary> /// Replaces current audio data with another /// </summary> /// <param name="audio">New audio data</param> public void SetAudio(Audio audio) { this.Stop(); Audio = audio; loopStream = new LoopStream(Audio.GetWaveFile()); waveOut = new WaveOut(); waveOut.Init(loopStream); }
/// <summary> /// Creates new <see cref="AudioChannel"/> instance with <paramref name="name"/> and assigned <paramref name="audio"/> /// </summary> /// <param name="name">Audio channel name</param> /// <param name="audio">Assigned <see cref="Audio"/></param> public AudioChannel(string name, Audio audio) { ChannelName = name; AssignedAudio = audio; waveOut = new WaveOut(); loopStream = new LoopStream(AssignedAudio.GetWaveFile()); waveOut.Init(loopStream); }
public void Play() { var reader = new WaveFileReader(SongToPlay); var MediaPlayer = new DirectSoundOut(); var loop = new LoopStream(reader); MediaPlayer.Init(new WaveChannel32(loop)); MediaPlayer.Play(); }
public void startMusic(int musicID) { LoopStream loopStream = new LoopStream(musics[musicID]); loopStream.EnableLooping = true; waveOutLoop.Init(loopStream); waveOutLoop.Play(); }
private void Play(byte[] buffer) { var source = new LoopStream( new RawSourceWaveStream( new MemoryStream(buffer), new WaveFormat() )); we.Init(source); we.Play(); }
public async Task LoadFileAsync(Stream stream) { await using var wav = new RawSourceWaveStream(stream, new WaveFormat()); await using var provider = new LoopStream(wav) { LoopPosition = PlayInfo.Loop - PlayInfo.Start }; provider.Seek(0, SeekOrigin.Begin); _woEvent.Init(provider); }
public static async void PlaySound(string sound, bool loop) { Logger.WriteLine($"attempting to play sound: {sound}"); try { // gc isn't happy rn // create wave out event and initialize it with the vorbis wave reader using (WaveOutEvent waveOut = new WaveOutEvent()) { // create vorbis wave reader using (VorbisWaveReader v = new VorbisWaveReader($"{Static.audioPath}\\{sound}.ogg")) { // also create a loop stream and initialize the wave out event with the loop stream instead of loop is true using (LoopStream loopStream = new LoopStream(v)) { if (loop) { waveOut.Init(loopStream); } else { waveOut.Init(v); } // flush and dispose the streams after playback stops void Dispose(object sender, StoppedEventArgs e) { v.Flush(); v.Dispose(); waveOut.Dispose(); loopStream.Flush(); loopStream.Dispose(); } waveOut.PlaybackStopped += Dispose; // play waveOut.Play(); // add the wave out event to the active audio list so it can be stopped manually activeAudio.Add(waveOut); // wait the duration of the sound await Task.Delay(v.TotalTime); } } } } catch (Exception ex) { ExceptionMessage.New(ex, true); } }
private void Start() { this.Stream.Position = 0; var reader = new WaveFileReader(this.Stream); var loop = new LoopStream(reader); this.SoundPlayer = new WaveOut { DeviceNumber = this.DeviceId }; this.SoundPlayer.PlaybackStopped += this.SoundPlayer_PlaybackStopped; this.SoundPlayer.Init(loop); this.SoundPlayer.Play(); }
public IPlayback Play(Stream stream, int loop = 0) { lock (lockObject) { var reader = new WaveFileReader(stream); var loopStream = new LoopStream(Logger, reader, loop); waveOut.Init(loopStream); waveOut.Play(); return(loopStream); } }
/// <summary> /// Creates the looping stream using earlier set looping values. /// </summary> /// <returns>The looping music stream.</returns> public WaveStream CreateStream() { var stream = new LoopStream(TrackLoader.LoadStream(Track.GetFullPath())); stream.SetStreamPoints( TrackStart, StreamLoopStart != -1 ? StreamLoopStart : TrackStart, StreamLoopEnd != -1 ? StreamLoopEnd : TrackEnd, TrackEnd ); stream.TotalLoops = Loops; return(stream); }
public void SetAudioData(byte[] wavData) { ClearAudioData(); var wavStream = new MemoryStream(wavData); _waveProvider = new WaveFileReader(wavStream); _waveOut = new WaveOut(); _loopStream = new LoopStream(_waveProvider); _waveOut.Init(_loopStream); _waveOut.Volume = _volume; HasData = true; }
public static void Grita() { if (waveOut == null) { AumentarVolume(); var grito = Path.Combine(Directory.GetCurrentDirectory(), "Grito.mp3"); Mp3FileReader reader = new Mp3FileReader(grito); LoopStream loop = new LoopStream(reader); waveOut = new WaveOut(); waveOut.Init(loop); waveOut.Play(); } }
public Audio GetMusicLooping(string fileName) { var audioFile = new AudioFileReader(_appSettingsProvider.SoundFilesLocation + $"\\{fileName}"); var loop = new LoopStream(audioFile); var outputDevice = new WaveOutEvent(); outputDevice.Init(loop); outputDevice.Play(); var audio = new Audio() { Reader = audioFile, Output = outputDevice }; return(audio); }
public void startMusic(int musicIDIntro, int musicIDLoop) { LoopStream loopStream = new LoopStream(musics[musicIDLoop]); loopStream.EnableLooping = true; waveOutIntro.Init(musics[musicIDIntro]); waveOutLoop.Init(loopStream); waveOutIntro.Play(); while (waveOutIntro.PlaybackState != PlaybackState.Stopped) { ; } waveOutLoop.Play(); }
public bool OpenFile(string filename, Func <IWaveSource, IWaveSource> oninitcallback) { if (String.IsNullOrWhiteSpace(filename)) { throw new ArgumentException("filename"); } try { var source = CodecFactory.Instance.GetCodec(filename); source = new LoopStream(source); (source as LoopStream).EnableLoop = false; if (source.WaveFormat.Channels == 1) { source = new MonoToStereoSource(source).ToWaveSource(16); } _panSource = new PanSource(source) { Pan = this.Pan }; var _notification = new SimpleNotificationSource(_panSource); _notification.DataRead += OnNotification; source = _notification.ToWaveSource(16); //source = new BufferSource(source, source.WaveFormat.BytesPerSecond * 2); _source = source; if (oninitcallback != null) { SoundOutManager.Initialize(oninitcallback(source)); } else { SoundOutManager.Initialize(source); } } catch (Exception) { return(false); } RaiseUpdated(); return(true); }
private void playMusic(Stream music) { if (AudioSettings.VOL == 0 || AudioSettings.MUSIC == 0) { return; } wave = new WaveFileReader(music); var reduce = new BlockAlignReductionStream(wave); LoopStream loop = new LoopStream(reduce); var provider = new Wave16ToFloatProvider(loop); provider.Volume = AudioSettings.VOL / 200F; outputMusic = new DirectSoundOut(); outputMusic.PlaybackStopped += new EventHandler <StoppedEventArgs>(playBackStoppedMusic); outputMusic.Init(provider); outputMusic.Play(); }
static public void StartStop() { if (waveOut == null) { WaveFileReader reader = new WaveFileReader(file); LoopStream loop = new LoopStream(reader); waveOut = new WaveOut(); waveOut.Init(loop); waveOut.Volume = volume; waveOut.Play(); } else { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } }
private ISampleProvider CreateInputStream(string fileName, float _volume = 1.0f) { //using () //{ AudioFileReader audioFileReader = new AudioFileReader(fileName); LoopStream loop = new LoopStream(audioFileReader); SampleChannel sampleChannel = new SampleChannel(loop, true); sampleChannel.Volume = _volume; var postVolumeMeter = new MeteringSampleProvider(sampleChannel); return(postVolumeMeter); // }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); WaveFileReader reader = new WaveFileReader(@"C:\Users\Asus\Documents\PLUS.wav"); LoopStream loop = new LoopStream(reader); AudioController.Instance.AudioPlayer = new WaveOut(); AudioController.Instance.AudioPlayer.Init(loop); AudioController.Instance.AudioPlayer.Play(); GameController.Instance.Initialize(); GL.ClearColor(0.2f, 0.22f, 0.2f, 0); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); }
public void SetAudioData(byte[] wavData) { ClearAudioData(); HasData = false; if (wavData?.Length == 0) { return; } var wavStream = new MemoryStream(wavData); _waveProvider = new WaveFileReader(wavStream); _waveOut = new WaveOut(); _loopStream = new LoopStream(_waveProvider); _waveOut.Init(_loopStream); _waveOut.Volume = _volume; HasData = true; }
/// <summary> /// Запустить воспроизведение звука (поддерживается wav формат) /// </summary> private void StartAlarm() { try { if (waveOut == null) { WaveFileReader reader = new WaveFileReader(config.SoundFileName); LoopStream loop = new LoopStream(reader); waveOut = new WaveOut(); waveOut.Init(loop); waveOut.Play(); } } catch (Exception ex) { log.WriteAction(string.Format(Localization.UseRussian ? "Ошибка при воспроизведении аудиофайла {0}: {1}" : "Error playing audio file {0}: {1}", config.SoundFileName, ex.Message)); } }
public void ClearAudioData() { if (_waveOut != null) { _waveOut.Stop(); _waveOut.Dispose(); _waveOut = null; } if (_waveProvider != null) { _waveProvider.Dispose(); _waveProvider = null; } if (_loopStream != null) { _loopStream.Dispose(); _loopStream = null; } HasData = false; }
private void Form1_Load(object sender, EventArgs e) { this.ActiveControl = label1; this.FormBorderStyle = FormBorderStyle.None; Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 15, 15)); MaterialSkinManager materialSkinManager = MaterialSkinManager.Instance; materialSkinManager.Theme = MaterialSkinManager.Themes.DARK; materialSkinManager.ColorScheme = new ColorScheme( Primary.Grey700, Primary.Grey700, Primary.Grey500, Accent.Amber200, TextShade.WHITE); WaveFileReader reader = new WaveFileReader(@"Music\launcher.wav"); LoopStream loop = new LoopStream(reader); waveOut = new WaveOut(); waveOut.Init(loop); waveOut.Play(); var pakLanguages = new DirectoryInfo("local").GetFiles("*.pak"); for (int i = 0; i < pakLanguages.Length; i++) { String l = pakLanguages[i].Name.Split('.')[0]; language.Items.Add(FirstCharToUpper(l)); } IniParser parser = new IniParser(@"Settings.ini"); String languageDefault = (parser.GetSetting("Language", "Default")).ToUpper(); language.SelectedIndex = language.FindStringExact(languageDefault); language.DropDownStyle = ComboBoxStyle.DropDownList; String resolutionDefault = (parser.GetSetting("Options", "Resolution")); listResolution(); loadLanguageLauncher(); loadFolderMods(); resolution.Refresh(); this.Refresh(); }
public void Init() { if (!File.Exists(filePath)) { throw new FileNotFoundException("The specified audio file not found: \n" + filePath); } mp3Reader = new Mp3FileReader(filePath); waveOut = new WaveOut(); if (EnableLooping) { loopStream = new LoopStream(mp3Reader); waveOut.Init(loopStream); } else { waveOut.Init(mp3Reader); } waveOut.PlaybackStopped += (sender, e) => Playing = false; }
public WavePlayer(string FileName) { this.FileName = FileName; Reader = new WaveFileReader(FileName); var loop = new LoopStream(Reader); loop.EnableLooping = false; // Desativa o loop aki Channel = new WaveChannel32(loop) { PadWithZeroes = false }; }