//string PositionString; public void OnButtonPlayClick_Click(object sender, EventArgs e) { if (outputDevice == null) { outputDevice = new WaveOutEvent(); //WaveOutEvent best option for sending audio to soundcard outputDevice.PlaybackStopped += OnPlaybackStopped; // to add ASIO - github.com/naudio/NAudio/blob/master/Docs/AsioPlayback.md } if (audioFile == null) { audioFile = new AudioFileReader(textBox1.Text); //audioFile = new AudioFileReader(@"c:\aphextwin.mp3"); //hardcoded directory outputDevice.Init(audioFile); } else { } outputDevice.Play(); long GetPosition; GetPosition = outputDevice.GetPosition(); PositionString = GetPosition.ToString(); //converts bytes to string textBox2.Text = PositionString; Task.Factory.StartNew(() => { printPositionString(); }); }
public void InitScene() { GameObject background = new GameObject(new Vector2(SceneManager.ScreenSize.X, 400, SceneManager.ScreenSize.X, 0), "", new Vector2(0, 250)); background.Animator.AddTexture("BACKGROUND", new Bitmap("./Textures/BACKGROUND.png"), 3, 2000); background.Animator.CurrentTexture = "BACKGROUND"; SceneManager.AddObject(background); GameObject sun = new GameObject(new Vector2(230, 300), "Sun", new Vector2(10, -25)); sun.Animator.AddTexture("SUN", new Bitmap("./Textures/SUN.png")); sun.Animator.CurrentTexture = "SUN"; SceneManager.AddObject(sun); menuHUD = new MenuHUD(gl); menuHUD.Init(); SceneManager.HUD = menuHUD; // Play games' song long position; try { position = OutputDevice.GetPosition(); } catch { position = 0; } if (position == 0) { keepPlaying = true; OutputDevice.PlaybackStopped += SongStopped; OutputDevice.Init(audioFile); OutputDevice.Play(); } }
private void BackgroundPlayer_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { object[] arguments = e.Argument as object[]; WaveStream WaveFloat = (WaveStream)arguments[0]; int LeftPos = Conversions.ToInteger(arguments[1]); int RightPos = Conversions.ToInteger(arguments[2]); var bytes = new byte[RightPos - LeftPos + 1]; WaveFloat.Position = LeftPos; WaveFloat.Read(bytes, 0, RightPos - LeftPos); WaveFloat = new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat); // WaveFloat.PadWithZeroes = False using (var output = new WaveOutEvent()) { output.Init(WaveFloat); output.Play(); while (output.PlaybackState == PlaybackState.Playing & !BackgroundPlayer.CancellationPending) { Thread.Sleep(45); BackgroundPlayer.ReportProgress((int)(output.GetPosition() / (WaveFloat.WaveFormat.BitsPerSample / 8d))); } } }
public void UpdatePlayPos() { if (outDevice != null && outDevice.PlaybackState == PlaybackState.Playing) { double ms = outDevice.GetPosition() * 1000.0 / masterMix.WaveFormat.BitsPerSample / masterMix.WaveFormat.Channels * 8 / masterMix.WaveFormat.SampleRate; int tick = DocManager.Inst.Project.MillisecondToTick(ms); DocManager.Inst.ExecuteCmd(new SetPlayPosTickNotification(tick), true); } }
public async Task trackAudioA() { while (outputDevice.PlaybackState == PlaybackState.Playing) { await Task.Delay(3000); long currentPosition = outputDevice.GetPosition(); decimal position = ((decimal)currentPosition / (decimal)audioFile.Length) * 100; } }
private void OnButtonRollBackClick(object sender, EventArgs args) { if (!CheckAudioLoaded()) { return; } long position = (long)outputDevice?.GetPosition(); var rollbackSecondsOffset = outputDevice.OutputWaveFormat.AverageBytesPerSecond * 5; audioFile.Position = position - rollbackSecondsOffset > 0 ? position - rollbackSecondsOffset : 0; }
public void Pause() { IsPlaying = false; if (player != null) { position = player.GetPosition(); player.Stop(); } if (output != null) { output.Close(); } }
private static void updateTrackbar(WaveOutEvent waveOut, WaveFileReader reader, TrackBar trackBar) { do { try { trackBar.Value = (int)((waveOut.GetPosition() / reader.Length) * 1000); } catch (ArgumentOutOfRangeException) { trackBar.Value = trackBar.Maximum; } } while (waveOut.PlaybackState == PlaybackState.Playing); }
private void updatePlaybackStatus(WaveOutEvent wo, int totalTime, int AvgBytesPerSecond, string type) { if (wo.PlaybackState == PlaybackState.Playing) { int currentPos = (int)wo.GetPosition() / AvgBytesPerSecond; playbackStatusLabel.Invoke((Action) delegate { playbackStatusLabel.Text = "Playing " + type + "... (" + currentPos.ToString() + "/" + totalTime.ToString() + ")"; }); } else if (wo.PlaybackState == PlaybackState.Stopped) { playbackStatusLabel.Invoke((Action) delegate { playbackStatusLabel.Text = "Stopped"; }); } }
public int Read(byte[] buffer, int offset, int count) { bytesPlayed = player.GetPosition(); bytesPlayedTs = stopwatch.ElapsedTicks; lock (queue) { short sample = 0; for (int i = 0; i < count; i += 2) { if (queue.TryDequeue(out sample)) { buffer[i + offset] = (byte)(sample & 0xff); buffer[i + offset + 1] = (byte)((sample >> 8) & 0xff); } else { buffer[i + offset] = (byte)(sample & 0xff); buffer[i + offset + 1] = (byte)((sample >> 8) & 0xff); playbackBytesInjected += 2; //Console.WriteLine("INJECT " + stopwatch.ElapsedMilliseconds); } } if (queue.Count < 200) { discardTimeout = RDT; } else if (discardTimeout > 0) { --discardTimeout; } else { short discard; if (queue.TryDequeue(out discard)) { playbackBytesInjected -= 2; playbackBytesDiscarded += 2; //Console.WriteLine("DISCARD " + stopwatch.ElapsedMilliseconds); } } } return(count); }
private void BackgroundPlayer_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { WaveStream WaveFloat = (e.Argument as object[])[0] as WaveStream; int LeftPos = (int)(e.Argument as object[])[1]; int RightPos = (int)(e.Argument as object[])[2]; byte[] bytes = new byte[(RightPos - LeftPos) + 1]; WaveFloat.Position = LeftPos; WaveFloat.Read(bytes, 0, (RightPos - LeftPos)); WaveFloat = new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat); //WaveFloat.PadWithZeroes = False using (var output = new WaveOutEvent()) { output.Init(WaveFloat); output.Play(); while (output.PlaybackState == PlaybackState.Playing & !BackgroundPlayer.CancellationPending) { Thread.Sleep(45); BackgroundPlayer.ReportProgress((int)output.GetPosition() / (WaveFloat.WaveFormat.BitsPerSample / 8)); } } }
// decimal pixelsPerSample() // { // return (decimal)pa_wave.Width / _samples.Length; // } // int samplesPerPixel() // { // return _samples.Length / pa_wave.Width + 1; // } #region handlers paint /// <summary> /// Paints the wave-panel. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void paint_WavePanel(object sender, PaintEventArgs e) { int offsetVert = pa_wave.Height / 2; e.Graphics.DrawLine(Pens.OliveDrab, pa_wave.Left, offsetVert, pa_wave.Right, offsetVert); decimal factorHori = (decimal)pa_wave.Width / _shorts.Length; decimal factorVert = (decimal)pa_wave.Height * _scale / 65536; int pixelGroupCount = _shorts.Length / pa_wave.Width + 1; Pen pen; // draw the wave short hi, hitest; int j, x, y, length = _shorts.Length; for (int i = 0; i < length; ++i) { hi = (short)0; // draw only the highest/lowest amplitude in each pixel-group -> for (j = 0; j != pixelGroupCount && i + j < length; ++j) { hitest = _shorts[i + j]; if (Math.Abs(hitest) > Math.Abs(hi)) { hi = hitest; } } i += j - 1; if (hi != (short)0) { if (Math.Abs(hi) > THRESHOLD) { pen = Pens.Lime; } else { pen = Pens.Firebrick; } x = (int)((decimal)i * factorHori); y = (int)((decimal)hi * factorVert); if (y == 0) // always pip a non-zero amplitude -> { y = (int)hi / Math.Abs(hi); // pos/neg } e.Graphics.DrawLine(pen, x, offsetVert, x, offsetVert + y); } } // draw the ortheme starts and phoneme stops decimal factorHori_dur = (decimal)pa_wave.Width / _dur; for (int i = 0; i != _dt.Rows.Count; ++i) { decimal result; string pos = _dt.Rows[i][0].ToString(); if (Utility.isWordstart(pos)) { // x = (int)((Decimal.Parse(_dt.Rows[i][2].ToString(), CultureInfo.InvariantCulture) + _sapiDelay) * factorHori_dur); // ortheme start-marker if (Decimal.TryParse(_dt.Rows[i][2].ToString(), out result)) { x = (int)((result + _sapiDelay) * factorHori_dur); // ortheme start-marker e.Graphics.DrawLine(Pens.Red, x, 0, x, pa_wave.Height); pos = pos.Substring(0, pos.Length - 2); e.Graphics.DrawString(pos, pa_wave.Font, Brushes.AliceBlue, (float)x + 1f, 1f); } } // x = (int)((Decimal.Parse(_dt.Rows[i][3].ToString(), CultureInfo.InvariantCulture) + _sapiDelay) * factorHori_dur); // phoneme stop-marker if (Decimal.TryParse(_dt.Rows[i][3].ToString(), out result)) { x = (int)((result + _sapiDelay) * factorHori_dur); // phoneme stop-marker e.Graphics.DrawLine(Pens.Blue, x, 16, x, pa_wave.Height - 16); } } // draw the track-caret int h_4 = pa_wave.Height / 4; int top = h_4 - 1; int bot = h_4 * 3 + 1; //logfile.Log(_waveout.GetPosition().ToString()); // NOTE: Get position from '_waveout' NOT '_wavereader' because the // latter is very sluggish here - be aware that the streams are NOT // the same however. x = (int)(((decimal)_waveout.GetPosition() / 2 + PosStart) * factorHori); e.Graphics.DrawLine(Pens.White, x, top, x, bot); // draw the start-caret as an I-bar x = (int)((decimal)PosStart * factorHori); e.Graphics.DrawLine(Pens.Wheat, x, top, x, bot); e.Graphics.DrawLine(Pens.Wheat, x - 3, top, x + 3, top); e.Graphics.DrawLine(Pens.Wheat, x - 3, bot, x + 3, bot); }
public void InitScene() { background = new GameObject(new Vector2(SceneManager.ScreenSize.X * 0.825f, 2000 / 3000f * SceneManager.ScreenSize.X * 0.825f, SceneManager.ScreenSize.X, SceneManager.ScreenSize.Y)); background.Animator.AddTexture("MAP", new Bitmap("./Textures/MAP.png")); background.Animator.CurrentTexture = "MAP"; background.IsHidden = true; SceneManager.AddObject(background); label = new Label(quotes[LEVEL], 32, Color.White, SceneManager.ScreenSize.WithRef(SceneManager.ScreenSize), Label.Alignment.CENTER, 25); SceneManager.AddObject(label); indexesBackground = new GameObject(new Vector2((displaySize.X + SPACE) * 2 + SPACE, displaySize.Y * 4 + SPACE * 5), "", new Vector2(SceneManager.ScreenSize.X - (displaySize.X + SPACE) * 2 - SPACE, 0, SceneManager.ScreenSize.X, 0, (displaySize.X + SPACE) * 2 + SPACE)); indexesBackground.Animator.Color = Color.FromArgb(113, 10, 10, 10); indexesBackground.Animator.CurrentTexture = Animator.SOLID_TEXTURE; indexesBackground.IsHidden = true; SceneManager.AddObject(indexesBackground); indexes = new GameObject[8]; for (int i = 0; i < 8; i++) { indexes[i] = new GameObject(displaySize, "", new Vector2(SceneManager.ScreenSize.X - (displaySize.X + SPACE) * (i % 2 + 1), (displaySize.Y + SPACE) * (i / 2) + SPACE, SceneManager.ScreenSize.X, 0, (displaySize.X + SPACE) * (i % 2 + 1))); indexes[i].Animator.AddTexture("DISPLAY", GetTexture(i)); indexes[i].Animator.CurrentTexture = "DISPLAY"; indexes[i].IsHidden = true; SceneManager.AddObject(indexes[i]); } backgroundBottom = new GameObject(new Vector2(SceneManager.ScreenSize.X, 200, SceneManager.ScreenSize.X, 0), "", new Vector2(0, SceneManager.ScreenSize.Y - 200, 0, SceneManager.ScreenSize.Y, 0, 200)); backgroundBottom.Animator.Color = Color.FromArgb(113, 10, 10, 10); backgroundBottom.Animator.CurrentTexture = Animator.SOLID_TEXTURE; backgroundBottom.IsHidden = true; SceneManager.AddObject(backgroundBottom); currentSpeech = 0; character = new GameObject(new Vector2(150, 150), "", new Vector2(25, SceneManager.ScreenSize.Y - 175, 0, SceneManager.ScreenSize.Y, 0, 175)); character.IsHidden = true; for (int i = 0; i < CHARACTERS_TEXTURES_IDS.Length; i++) { character.Animator.AddTexture("CHARACTER_" + i, CHARACTERS_TEXTURES_IDS[i]); } SceneManager.AddObject(character); speech = new Label("", 22, Color.White, new Vector2(SceneManager.ScreenSize.X - 200, 200, SceneManager.ScreenSize.X, 0, 200)); speech.Transform.Position = new Vector2(200, SceneManager.ScreenSize.Y - 175, 0, SceneManager.ScreenSize.Y, 0, 175); speech.IsHidden = true; SceneManager.AddObject(speech); start = SceneManager.Now; // Play games' song long position; try { position = OutputDevice.GetPosition(); } catch { position = 0; } if (position == 0) { keepPlaying = true; OutputDevice.PlaybackStopped += SongStopped; OutputDevice.Init(audioFile); OutputDevice.Play(); } }
public void InitScene() { IsDisposed = false; GameEnded = false; gameHUD = new GameHUD(gl); gameHUD.Init(); SceneManager.HUD = gameHUD; // Create scene's background CreateBackground(); // Create player PlayerObject player = new PlayerObject(new Vector2(34, 71), "Player", new Vector2(SceneManager.ScreenSize.X / 2f, 5)); player.Animator.AddTexture("HOOK", new Bitmap("./Textures/HOOK.png")); player.Animator.CurrentTexture = "HOOK"; SceneManager.AddObject(player); SceneManager.Player = player; // Create fishes Fish.RegisterTextures(); Fish3.RegisterTextures(); new Thread(new ThreadStart(CreateFishes)).Start(); // Create bombs Bombs.RegisterTextures(); new Thread(new ThreadStart(CreateBombs)).Start(); // Create bubbles float bubblePos = 500; while (bubblePos < 17000) { CreateBubbles(new Vector2((float)this.random.NextDouble() * SceneManager.ScreenSize.X, bubblePos, SceneManager.ScreenSize.X, 0)); bubblePos += 50 + (float)this.random.NextDouble() * 475; } // Create player's aim GameObject aim = new GameObject(new Vector2(40, 40), "Aim"); aim.Animator.AddTexture("AIM", AIM_TEXTURE_ID); aim.Animator.CurrentTexture = "AIM"; aim.Transform.SetPositionFn(() => { aim.Transform.Position = SceneManager.MousePositionInScene() - aim.Transform.Size / 2f; }); SceneManager.Aim = aim; // Play games' song long position; try { position = OutputDevice.GetPosition(); } catch { position = 0; } if (position == 0) { keepPlaying = true; OutputDevice.PlaybackStopped += SongStopped; OutputDevice.Init(audioFile); OutputDevice.Play(); } }
static void Main(string[] args) { Console.WriteLine("Animação ASCII : Bad Apple"); List <String> frames = new List <String>(); int quantFrames = Directory.GetFiles(@"BadApple\frames").Length; int frameIndex = 1; int width = Console.WindowWidth - 1; int height = Console.WindowHeight - 1; Console.Write("Loading the animation frames, please wait : "); while (true) { string frame = @"BadApple\frames\" + frameIndex.ToString() + ".png"; if (!File.Exists(frame)) { break; } using (Bitmap image = new Bitmap(frame)) { Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(image, 0, 0, width, height); StringBuilder sb = new StringBuilder(); String chars = " .*#%@"; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { int index = (int)(bmp.GetPixel(x, y).GetBrightness() * chars.Length); if (index < 0) { index = 0; } else if (index >= chars.Length) { index = chars.Length - 1; } sb.Append(chars[index]); } sb.Append("\n"); } frames.Add(sb.ToString()); frameIndex++; int percentage = (int)((frames.Count / (float)(quantFrames)) * 100); Console.SetCursorPosition(43, Console.CursorTop); Console.Write("|" + percentage.ToString() + "%" + " | processed frames : " + frames.Count.ToString() + " "); } } AudioFileReader reader = new AudioFileReader(@"BadApple\audio.wav"); WaveOutEvent woe = new WaveOutEvent(); woe.Init(reader); Console.WriteLine("\n\n press ENTER to start!"); Console.ReadLine(); woe.Play(); while (true) { float percentage = woe.GetPosition() / (float)reader.Length; int frame = (int)(frames.Count * percentage); if (frame >= frames.Count) { break; } Console.SetCursorPosition(0, 0); Console.WriteLine(frames[frame].ToString()); } Console.WriteLine("The END, bye:)"); Console.ReadLine(); }
public long GetPlayerPos() { return(wo.GetPosition()); }
static void Main(string[] args) { string inputFilename; if (args.Length == 0) /* Ask user manually if no parameters specified */ { Console.Write("Input File: "); inputFilename = Console.ReadLine().Replace("\"", ""); } else /* Otherwise use first argument */ { inputFilename = args[0]; } Console.WriteLine("------------------------------\n" + " Controls \n" + " Space - Play / Pause \n" + " Esc - Exit \n" + "------------------------------\n"); ConsoleColor originalForegroundColor = Console.ForegroundColor; /* Preserve the old colours to print warning message */ ConsoleColor originalBackgroundColor = Console.BackgroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Black; /* Contrast: Red on black */ Console.WriteLine("NOTE: Do not resize the window starting from now! (Resize before program init)"); Console.ForegroundColor = originalForegroundColor; /* Reset old colours */ Console.BackgroundColor = originalBackgroundColor; Console.WriteLine("[INFO] Please wait.. Processing.."); Console.WriteLine("[INFO] Step 1 / 4: Cleaning up..."); if (Directory.Exists("tmp")) { if (Directory.Exists("tmp\\frames\\")) { Directory.Delete("tmp\\frames\\", true); } Directory.CreateDirectory("tmp\\frames\\"); if (File.Exists("tmp\\audio.wav")) { File.Delete("tmp\\audio.wav"); } } else { Directory.CreateDirectory("tmp\\"); Directory.CreateDirectory("tmp\\frames\\"); } int targetFrameWidth = Console.WindowWidth - 1; int targetFrameHeight = Console.WindowHeight - 2; Console.WriteLine("[INFO] Step 2 / 4: Extracting frames..."); Process ffmpegProcess = new Process(); /* Launch ffmpeg process to extract the frames */ ffmpegProcess.StartInfo.FileName = "ffmpeg.exe"; ffmpegProcess.StartInfo.Arguments = "-i \"" + inputFilename + "\" -vf scale=" + targetFrameWidth + ":" + targetFrameHeight + " tmp\\frames\\%0d.bmp"; ffmpegProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; ffmpegProcess.Start(); Console.WriteLine("[INFO] Waiting for ffmpeg.exe to finish..."); ffmpegProcess.WaitForExit(); Console.WriteLine("[INFO] Step 3 / 4: Extracting audio..."); ffmpegProcess = new Process(); ffmpegProcess.StartInfo.FileName = "ffmpeg.exe"; ffmpegProcess.StartInfo.Arguments = "-i \"" + inputFilename + "\" tmp\\audio.wav"; ffmpegProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; ffmpegProcess.Start(); Console.WriteLine("[INFO] Waiting for ffmpeg.exe to finish..."); ffmpegProcess.WaitForExit(); Console.WriteLine("[INFO] Step 4 / 4: Converting to ascii... (This can take some time!)"); Console.Write("-> [PROGRESS] [0 %] [ ]"); int currentCursorHeight = Console.CursorTop; List <string> frames = new List <string>(); int frameCount = Directory.GetFiles("tmp\\frames", "*.bmp").Length; int frameIndex = 1; while (true) { string filename = "tmp\\frames\\" + frameIndex.ToString() + ".bmp"; if (!File.Exists(filename)) { break; } StringBuilder frameBuilder = new StringBuilder(); using (Bitmap b = new Bitmap(filename)) { for (int y = 0; y < b.Height; y++) { for (int x = 0; x < b.Width; x++) { int dIndex = (int)(b.GetPixel(x, y).GetBrightness() * brightnessLevels.Length); if (dIndex < 0) { dIndex = 0; } else if (dIndex >= brightnessLevels.Length) { dIndex = brightnessLevels.Length - 1; } frameBuilder.Append(brightnessLevels[dIndex]); } frameBuilder.Append("\n"); } } frames.Add(frameBuilder.ToString()); frameIndex++; int percentage = (int)(frameIndex / (float)frameCount * 100); Console.SetCursorPosition(15, currentCursorHeight); Console.Write(percentage.ToString()); Console.SetCursorPosition(22, currentCursorHeight); for (int i = 0; i < percentage / 5; i++) { Console.Write("#"); } } AudioFileReader reader = new AudioFileReader("tmp\\audio.wav"); WaveOutEvent woe = new WaveOutEvent(); woe.Init(reader); Console.WriteLine("\n\nPress return to play!"); Console.ReadLine(); woe.Play(); while (true) { float percentage = woe.GetPosition() / (float)reader.Length; int frame = (int)(percentage * frameCount); if (frame >= frames.Count) { break; } Console.SetCursorPosition(0, 0); Console.WriteLine(frames[frame]); if (Console.KeyAvailable) { ConsoleKey pressed = Console.ReadKey().Key; switch (pressed) { case ConsoleKey.Spacebar: { if (woe.PlaybackState == PlaybackState.Playing) { woe.Pause(); } else { woe.Play(); } break; } case ConsoleKey.Escape: { Console.WriteLine("Done. Press any key to close"); Console.ReadKey(); return; } } } } Console.WriteLine("Done. Press any key to close"); Console.ReadKey(); }
public long GetPosition() { lock (lockObj) { return(waveOutEvent == null ? 0 : waveOutEvent.GetPosition()); } }