private void txtB_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Return) { clearWave(); SpeechSynthesizer synth = new SpeechSynthesizer(); synth.SelectVoice(cBox.SelectedItem.ToString()); synth.Rate = (int)slider.Value; synth.SetOutputToWaveFile(wFile); synth.Speak(txtB.Text); synth.SetOutputToNull(); File.Copy(wFile, wFile2, true); waveReader = new NAudio.Wave.WaveFileReader(wFile); waveReaderToMe = new NAudio.Wave.WaveFileReader(wFile2); waveOut = new NAudio.Wave.WaveOut(); //for playing to selected device waveToMe = new NAudio.Wave.WaveOut(); //for playback to user through default device waveOut.DeviceNumber = deviceComboBox.SelectedIndex; waveOut.Init(waveReader); waveOut.Play(); waveToMe.Init(waveReaderToMe); waveToMe.Play(); txtB.Text = ""; } }
private static void InitAudio() { _audioProvider = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat(44100, 2)); _audioProvider.BufferDuration = TimeSpan.FromSeconds(300); _audioSink = new NAudio.Wave.WaveOut(); _audioSink.Init(_audioProvider); }
private void clearWave() { if (waveOut != null && waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if (waveToMe != null && waveToMe.PlaybackState == NAudio.Wave.PlaybackState.Playing) { waveToMe.Stop(); waveToMe.Dispose(); waveToMe = null; } if (waveReader != null) { waveReader.Dispose(); waveReader = null; } if (waveReaderToMe != null) { waveReaderToMe.Dispose(); waveReaderToMe = null; } }
public int EnqueueSamples(int channels, int rate, byte[] samples, int frames) { if (buffer == null) { buffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat(rate, channels)); //NAudio.Wave.DirectSoundOut dso = new NAudio.Wave.DirectSoundOut(70); //NAudio.Wave.AsioOut dso = new NAudio.Wave.AsioOut(); NAudio.Wave.WaveOut dso = new NAudio.Wave.WaveOut(); dso.Init(buffer); dso.Play(); player = dso; } int space = buffer.BufferLength - buffer.BufferedBytes; if (space > samples.Length) { if (times == 0) { Console.WriteLine("Enqueue"); } times = (times + 1) % 100; return(frames); } return(0); }
public MainWindow() { InitializeComponent(); player.Channel = "trance"; player.Codec = StreamCodec.MP3; player.MetadataChanged += (metadataChanged = new EventHandler(player_MetadataChanged)); player.StatusChanged += (statusChanged = new EventHandler(player_StatusChanged)); player.SampleReceived += new EventHandler <NAudio.Wave.SampleEventArgs>(player_SampleReceived); var output = new NAudio.Wave.WaveOut(); output.NumberOfBuffers = 3; output.Volume = 1.0f; player.Output = output; soundEngine.IsPlaying = false; spaVisualization.RegisterSoundPlayer(soundEngine); Task.Factory.StartNew(() => getChannels()); //ThemeManager.Instance.Dark(Colors.LightSteelBlue); ThemeManager.Instance.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Instance_PropertyChanged); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { while (!stop) { if (Frames.Count < 8 || AudioBuffer.BufferedBytes < 8192 * 4) { retry: byte[] audio; Bitmap b = Video.GetNextFrame(out audio); if (audio != null) { short[] data = AudioConverter.GetWaveData(audio, 0, audio.Length); byte[] result = new byte[data.Length * 2]; IOUtil.WriteS16sLE(result, 0, data); AudioBuffer.AddSamples(result, 0, result.Length); goto retry; } if (b == null) { stop = true; if ((Video.Header.Flags & 4) == 4) { Player.Stop(); Player.Dispose(); Player = null; AudioBuffer = null; } } else { Frames.Enqueue(b); } } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { while (!stop) { if (Frames.Count < 8 || AudioBuffer.BufferedBytes < 8192 * 4) { retry: byte[] audio; Bitmap b = Video.GetNextFrame(out audio); if (audio != null) { short[] data = AudioConverter.GetWaveData(audio, 0, audio.Length); byte[] result = new byte[data.Length * 2]; IOUtil.WriteS16sLE(result, 0, data); AudioBuffer.AddSamples(result, 0, result.Length); goto retry; } if (b == null) { stop = true; if ((Video.Header.Flags & 4) == 4) { Player.Stop(); Player.Dispose(); Player = null; AudioBuffer = null; } } else Frames.Enqueue(b); } } }
/// <summary> /// Init the audio playback /// </summary> public void Init() { NAudio.Wave.WaveFormat format = new NAudio.Wave.WaveFormat(44100, 16, 1); provider = new NAudio.Wave.BufferedWaveProvider(format); waveOut = new NAudio.Wave.WaveOut(); waveOut.Init(provider); waveOut.Play(); }
/// <summary> /// Dispose and destroy the audio playback object /// </summary> public void Destroy() { waveOut.Stop(); provider.ClearBuffer(); waveOut.Dispose(); waveOut = null; provider = null; }
private static void onPlaybackStopped(object sender, EventArgs e) { waveOut.PlaybackStopped -= onPlaybackStopped; waveOut = null; vorbisReader.Dispose(); vorbisReader = null; }
void CreatePlayer() { if (Player != null) { Player.Stop(); Player.Dispose(); } Player = new NAudio.Wave.WaveOut(); }
public static void playNotificationSound() { vorbisReader = new NVorbis.NAudioSupport.VorbisWaveReader(BDMTConstants.WORKSPACE_PATH + BDMTConstants.NOTIFICATION_SOUND_FILE); waveOut = new NAudio.Wave.WaveOut(); waveOut.PlaybackStopped += onPlaybackStopped; waveOut.Init(vorbisReader); waveOut.Volume = 0.65f; waveOut.Play(); }
private void RunAudioThread(object jobObj) { var job = (AudioOut.Job)jobObj; using (var audioOut = new NAudio.Wave.WaveOut()) { var audioBuffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat()); audioOut.DesiredLatency = 100; audioOut.Init(audioBuffer); audioOut.Play(); var bufferSize = 5000; var sampleBuffer = new float[bufferSize]; var byteBuffer = new byte[bufferSize * 4]; while (true) { while (audioBuffer.BufferedBytes < bufferSize * 2) { for (var i = 0; i < sampleBuffer.Length; i++) { sampleBuffer[i] = 0; } var sampleNum = job.GetNextSamples(sampleBuffer); if (sampleNum == 0) { goto end; } for (var i = 0; i < sampleNum; i++) { var sampleU = unchecked ((ushort)(short)(sampleBuffer[i] * 0x4000)); byteBuffer[i * 4 + 0] = (byte)((sampleU >> 0) & 0xff); byteBuffer[i * 4 + 1] = (byte)((sampleU >> 8) & 0xff); byteBuffer[i * 4 + 2] = (byte)((sampleU >> 0) & 0xff); byteBuffer[i * 4 + 3] = (byte)((sampleU >> 8) & 0xff); } audioBuffer.AddSamples(byteBuffer, 0, sampleNum * 4); } System.Threading.Thread.Sleep(50); } end: audioOut.Stop(); } lock (audioThreads) audioThreads.Remove(System.Threading.Thread.CurrentThread); }
private void sound1_Click(object sender, EventArgs e) { int deviceNumberIn = inputComboBox.SelectedIndex; int deviceNumberOut = outputComboBox.SelectedIndex; if (waveReader == null) { dialog = new OpenFileDialog(); dialog.InitialDirectory = soundFolderTextBox.Text; dialog.Filter = "Audio Files (.wav)|*.wav"; if (dialog.ShowDialog() == DialogResult.OK) { sound1.Text = dialog.FileName; //sourceStream = new NAudio.Wave.WaveIn(); sourceOutStream = new NAudio.Wave.WaveOut(); sourceOutStream.DeviceNumber = deviceNumberOut; //sourceStream.DeviceNumber = deviceNumber; //sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels); //NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream); //output.Init(waveIn); //sourceStream.StartRecording(); //output.Play(); waveReader = new NAudio.Wave.WaveFileReader(dialog.FileName); sourceOutStream.Init(new NAudio.Wave.WaveChannel32(waveReader)); //output.Init(new NAudio.Wave.WaveChannel32(waveReader)); sourceOutStream.Play(); //output.Play(); } } else { //Wenn schon vorhanden //Play sound waveReader = new NAudio.Wave.WaveFileReader(dialog.FileName); output.Init(new NAudio.Wave.WaveChannel32(waveReader)); sourceOutStream.Init(new NAudio.Wave.WaveChannel32(waveReader)); sourceOutStream.Play(); //output.Play(); } }
private void PlaySound(int deviceID, int soundID) { // I don't have the NAudio library so I can't check if it works or no though. disposeWave(); NAudio.Wave.WaveFileReader waveReader = new NAudio.Wave.WaveFileReader(this._soundFilepaths[soundID]); var waveOut = new NAudio.Wave.WaveOut(); waveOut.DeviceNumber = deviceNumber; var output = waveOut; output.Init(waveReader); output.Play(); }
private void FMV_Load(object sender, EventArgs e) { /*double ticks = 10000000.0 / (Video.Header.FrameRate / 256.0); * float exp = (float)(ticks - Math.Floor(ticks)); * if (exp != 0) * { * int i = 0; * float result; * do * { * i++; * result = exp * i; * } * while((float)(result - Math.Floor(result)) != 0); * }*/ //TODO: Calculate timing based on fps if ((Video.Header.Flags & 4) == 4) { AudioConverter = new IMAADPCMDecoder(); AudioBuffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat((int)Video.Header.AudioRate, 16, 1)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 8192 * 16; Player = new NAudio.Wave.WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); } new System.Threading.Thread(new System.Threading.ThreadStart(delegate { int state = 0; while (!stop) { if (Frames.Count != 0) { pictureBox1.Image = Frames.Dequeue(); switch (state) { case 0: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666666)); break; case 1: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666667)); break; case 2: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666667)); break; } state = (state + 1) % 3; } } System.Threading.Thread.CurrentThread.Abort(); })).Start(); backgroundWorker1.RunWorkerAsync(); }
public static async System.Threading.Tasks.Task PlayFileAsync(string fileName) { using (NAudio.Wave.WaveFileReader mic = new NAudio.Wave.WaveFileReader(fileName)) { NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(); waveOut.DesiredLatency = Options.options.audio.NAudio.desiredLatencyMilliseconds; waveOut.Init(mic); waveOut.Play(); while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) { System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(100)).Wait(); } } }
private void FMV_FormClosing(object sender, FormClosingEventArgs e) { if (!stop) { stop = true; if ((Video.Header.Flags & 4) == 4) { Player.Stop(); Player.Dispose(); Player = null; AudioBuffer = null; } } Video.Close(); }
private void btnPlay_Click(object sender, EventArgs e) { if(lbArtists.SelectedIndex == -1 || lbAlbums.SelectedIndex == -1 || lbSongs.SelectedIndex == -1) { MessageBox.Show("Noting selected"); return; } byte[] data = _client.GetSongData(_musicCollection.Artists[lbArtists.SelectedIndex].Albums[lbAlbums.SelectedIndex].Songs[lbSongs.SelectedIndex].ID); MemoryStream ms = new MemoryStream(data); NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(ms); NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(); waveOut.Init(reader); waveOut.Play(); }
/// <summary> /// Load a sound for the animation from a byte array. /// </summary> /// <remarks>If this function fails, no sound will be played for this pet.</remarks> public void Load(byte[] buff) { try { MemoryStream ms = new MemoryStream(buff); AudioReader = new NAudio.Wave.Mp3FileReader(ms); Audio = new NAudio.Wave.WaveOut(); Audio.Init(AudioReader); Audio.PlaybackStopped += Audio_PlaybackStopped; } catch (Exception e) { Program.AddLog("Unable to load MP3: " + e.Message, "Play pet", Program.LOG_TYPE.ERROR); } }
public DemoPlayable() { file = TagLib.File.Create(path); reader = new NAudio.Wave.AudioFileReader(path); waveOut = new NAudio.Wave.WaveOut() { Volume = 0.2F }; waveOut.Init(reader); var tag = file.Tag; Title = tag.Title; Duration = file.Properties.Duration; }
public void Play(string track) { if (o != null) { o.Dispose(); mp3.Dispose(); memstream.Dispose(); } var bytes = ShiftOS.Objects.ShiftFS.Utils.ReadAllBytes(track); memstream = new System.IO.MemoryStream(bytes); mp3 = new NAudio.Wave.Mp3FileReader(memstream); o = new NAudio.Wave.WaveOut(); o.Init(mp3); o.Play(); pgplaytime.Value = 0; pgplaytime.Maximum = (int)mp3.Length; new Thread(() => { while (o.PlaybackState == NAudio.Wave.PlaybackState.Playing || o.PlaybackState == NAudio.Wave.PlaybackState.Paused) { long time = mp3.Position; this.Invoke(new Action(() => { pgplaytime.Value = (int)time; })); Thread.Sleep(50); } if (o.PlaybackState == NAudio.Wave.PlaybackState.Stopped) { this.Invoke(new Action(() => { if (lbtracks.SelectedIndex < lbtracks.Items.Count - 1) { lbtracks.SelectedIndex++; } else if (loopToolStripMenuItem.Checked == true) { lbtracks.SelectedIndex = 0; } })); } }).Start(); }
/// <summary> /// Load a sound for the animation from a byte array. /// </summary> /// <remarks>If this function fails, no sound will be played for this pet.</remarks> public void Load(byte[] buff) { try { MemoryStream ms = new MemoryStream(buff); AudioReader = new NAudio.Wave.Mp3FileReader(ms); Audio = new NAudio.Wave.WaveOut(); Audio.Init(AudioReader); Audio.PlaybackStopped += Audio_PlaybackStopped; } catch (Exception e) { // Failed to create a wave, reset volume Properties.Settings.Default.Volume = 0; Program.Mainthread.ErrorMessages.AudioErrorMessage = e.Message; } }
static void Main(string[] args) { if (args.Count() == 0) { Console.WriteLine("Basic text to speach converter"); Console.WriteLine("Expecting text in the command line parameter"); Environment.Exit(0); } Console.WriteLine("Creating Amazon Polly client"); Amazon.Polly.AmazonPollyClient cl = new Amazon.Polly.AmazonPollyClient(RegionEndpoint.USWest2); Amazon.Polly.Model.SynthesizeSpeechRequest req = new Amazon.Polly.Model.SynthesizeSpeechRequest(); req.Text = String.Join(" ", args); req.VoiceId = Amazon.Polly.VoiceId.Salli; req.OutputFormat = Amazon.Polly.OutputFormat.Mp3; req.SampleRate = "8000"; req.TextType = Amazon.Polly.TextType.Text; Console.WriteLine("Sending Amazon Polly request: " + req.Text); Amazon.Polly.Model.SynthesizeSpeechResponse resp = cl.SynthesizeSpeech(req); MemoryStream local_stream = new MemoryStream(); resp.AudioStream.CopyTo(local_stream); local_stream.Position = 0; Console.WriteLine("Got mp3 stream, lenght: " + local_stream.Length.ToString()); NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(local_stream); NAudio.Wave.WaveStream wave_stream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader); NAudio.Wave.BlockAlignReductionStream ba_stream = new NAudio.Wave.BlockAlignReductionStream(wave_stream); NAudio.Wave.WaveOut wout = new NAudio.Wave.WaveOut(); Console.Write("Playing stream..."); wout.Init(ba_stream); wout.Play(); while (wout.PlaybackState == NAudio.Wave.PlaybackState.Playing) { Thread.Sleep(100); } Console.WriteLine("..Done"); }
private void PreviewForm_Load(object sender, EventArgs e) { lock (renderingLock) { isRendering = true; Monitor.Pulse(renderingLock); } //synthProcessingThread = new Thread(SynthProcessingThreadEntry); //synthProcessingThread.Start(); //waveWriteThread = new Thread(WaveWriteThreadEntry); //waveWriteThread.Start(); naudioWaveOut = new NAudio.Wave.WaveOut(this.Handle); naudioWaveOut.NumberOfBuffers = 5; //naudioWaveOut.DesiredLatency = 500; naudioWaveOut.Init(naudioWaveProvider); naudioWaveOut.Play(); timer1.Enabled = true; }
public MainWindow() { InitializeComponent(); player.Channel = "trance"; player.Codec = StreamCodec.MP3; player.MetadataChanged += (metadataChanged = new EventHandler(player_MetadataChanged)); player.StatusChanged += (statusChanged = new EventHandler(player_StatusChanged)); player.SampleReceived += new EventHandler<NAudio.Wave.SampleEventArgs>(player_SampleReceived); var output = new NAudio.Wave.WaveOut(); output.NumberOfBuffers = 3; output.Volume = 1.0f; player.Output = output; soundEngine.IsPlaying = false; spaVisualization.RegisterSoundPlayer(soundEngine); Task.Factory.StartNew(() => getChannels()); //ThemeManager.Instance.Dark(Colors.LightSteelBlue); ThemeManager.Instance.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Instance_PropertyChanged); }
public int EnqueueSamples(int channels, int rate, byte[] samples, int frames) { if (buffer == null) { buffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat(rate, channels)); //NAudio.Wave.DirectSoundOut dso = new NAudio.Wave.DirectSoundOut(70); //NAudio.Wave.AsioOut dso = new NAudio.Wave.AsioOut(); NAudio.Wave.WaveOut dso = new NAudio.Wave.WaveOut(); dso.Init(buffer); dso.Play(); player = dso; } int space = buffer.BufferLength - buffer.BufferedBytes; if (space > samples.Length) { if (times == 0) Console.WriteLine("Enqueue"); times = (times + 1) % 100; return frames; } return 0; }
//Sourced from: http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c-sharp private void PlayMp3FromUrl(string url) { try { //Poor practice CheckForIllegalCrossThreadCalls = false; using (Stream ms = new MemoryStream()) { using (Stream stream = WebRequest.Create(url) .GetResponse().GetResponseStream()) { byte[] buffer = new byte[32768]; int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } } ms.Position = 0; using (NAudio.Wave.WaveStream blockAlignedStream = new NAudio.Wave.BlockAlignReductionStream( NAudio.Wave.WaveFormatConversionStream.CreatePcmStream( new NAudio.Wave.Mp3FileReader(ms)))) { using (NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback())) { waveOut.Init(blockAlignedStream); waveOut.Play(); while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) { System.Threading.Thread.Sleep(100); } } } } } catch { msgbox msgbox = new msgbox(false, "An error has happened whilst attempting to play the soundbyte."); msgbox.Show(); } button9.Enabled = true; currentlyPlayingSB = false; }
private void THP_Load(object sender, EventArgs e) { pictureBox1.Image = File.GetFrame(0).ToBitmap(); Width = (int)((IO.Misc.THP.THPComponents.THPVideoInfo)File.Components.THPInfos[0]).Width + 20; Height = (int)((IO.Misc.THP.THPComponents.THPVideoInfo)File.Components.THPInfos[0]).Height + 29; audio = File.Components.THPInfos[1] != null; if (audio) { bb = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat((int)((IO.Misc.THP.THPComponents.THPAudioInfo)File.Components.THPInfos[1]).Frequentie, 2)); ww = new NAudio.Wave.WaveOut(); bb.DiscardOnBufferOverflow = true; ww.Init(bb); ww.Play(); // WaveLib.WaveNative.waveOutOpen(out WaveOut, 0, new WaveLib.WaveFormat((int)((IO.Misc.THP.THPComponents.THPAudioInfo)File.Components.THPInfos[1]).Frequentie, 16, 2), new WaveLib.WaveNative.WaveDelegate(WaveCallBack), 0, 0); //w = new WaveLib.WaveOutBuffer(WaveOut, (int)File.Header.MaxBufferSize); //w = new WaveLib.WaveOutPlayer(0, new WaveLib.WaveFormat((int)((IO.Misc.THP.THPComponents.THPAudioInfo)File.Components.THPInfos[1]).Frequentie, 16, 2), (int)File.Header.MaxBufferSize, 1, new WaveLib.BufferFillEventHandler(BufferFiller)); /*h.dwBytesRecorded = 0; * h.dwUser = IntPtr.Zero; * h.dwFlags = 0; * h.dwLoops = 0; * h.lpNext = IntPtr.Zero; * h.reserved = 0; * * unsafe * { * WaveLib.WaveNative.waveOutPrepareHeader(WaveOut, ref h, sizeof(WaveLib.WaveNative.WaveHdr)); * }*/ } //for (int i = 0; i < 10; i++) //{ // t.Enqueue(File.GetFrame(frame++)); //} //backgroundWorker1.RunWorkerAsync(); //timer1.Interval = (int)(1000f / File.Header.FPS - 0.5f); //timer1.Enabled = true; // Timer = SetTimer(Handle, IntPtr.Zero, /*(uint)(1000f / File.Header.FPS-0.68336f)*/(uint)(1000f / File.Header.FPS - (1000f / File.Header.FPS / 10f)), IntPtr.Zero); backgroundWorker2.RunWorkerAsync(); if (audio) { backgroundWorker1.RunWorkerAsync(); } if (audio) { //backgroundWorker1.RunWorkerAsync(); //bb = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat((int)((IO.Misc.THP.THPComponents.THPAudioInfo)File.Components.THPInfos[1]).Frequentie, 2)); //ww = new NAudio.Wave.WaveOut(); //bb.DiscardOnBufferOverflow = true; //ww.Init(bb); //ww.Play(); // WaveLib.WaveNative.waveOutOpen(out WaveOut, 0, new WaveLib.WaveFormat((int)((IO.Misc.THP.THPComponents.THPAudioInfo)File.Components.THPInfos[1]).Frequentie, 16, 2), new WaveLib.WaveNative.WaveDelegate(WaveCallBack), 0, 0); //w = new WaveLib.WaveOutBuffer(WaveOut, (int)File.Header.MaxBufferSize); //w = new WaveLib.WaveOutPlayer(0, new WaveLib.WaveFormat((int)((IO.Misc.THP.THPComponents.THPAudioInfo)File.Components.THPInfos[1]).Frequentie, 16, 2), (int)File.Header.MaxAudioSamples * 2 * 2, 1, new WaveLib.BufferFillEventHandler(BufferFiller)); /*h.dwBytesRecorded = 0; * h.dwUser = IntPtr.Zero; * h.dwFlags = 0; * h.dwLoops = 0; * h.lpNext = IntPtr.Zero; * h.reserved = 0; * * unsafe * { * WaveLib.WaveNative.waveOutPrepareHeader(WaveOut, ref h, sizeof(WaveLib.WaveNative.WaveHdr)); * }*/ } }
public UMCMainViewMode() { if (IsInDesignModeStatic) { Title = "扯淡云(并没有)音乐"; CreateFaviourtes = "CreateFaviourtes"; Img_Singer = "1"; ReSizeBtn = "Category"; Portrait = "Portrait"; UserName = "******"; Message = "Message"; Setting = "Setting"; // Cloud = "Cloud"; CreateFaviourtes = "CreateFaviourtes"; Downloads = "Downloads"; Faviourtes = "Faviourtes"; Friends = "Friends"; Like = "LikeRed"; LocalMusic = "LocalMusic"; Music = "Music"; MusicList = "MusicList"; Radio = "Radio"; Recent = "Recent"; Search = "Search"; MV = "MV"; // Previous = "Previous"; Play = "Play"; Next = "Next"; // StaticButtons = new ObservableCollection <ButtonContent>(); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Search", ButtonContent_Text = "搜索", FuncKey = "1" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Music", ButtonContent_Text = "发现音乐", FuncKey = "2" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "MV", ButtonContent_Text = "MV", FuncKey = "3" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Friends", ButtonContent_Text = "朋友", FuncKey = "4" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Friends", ButtonContent_Text = "朋友", FuncKey = "4" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Friends", ButtonContent_Text = "朋友", FuncKey = "4" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Friends", ButtonContent_Text = "朋友", FuncKey = "4" }); // SongName = "伤不起"; SingerName = "王玲"; PlayingCurrentTime = "00:00"; PlayingTotalTime = "03:49"; // PlayMethod = "PlaySingleCycle"; Volume = "Volume"; PlayList = "PlayList"; } else { //可以考虑放到xml文档里(反正就是配置文档) Title = "扯淡云(并没有)音乐"; CreateFaviourtes = "CreateFaviourtes"; Img_Singer = "1"; ReSizeBtn = "Category"; Portrait = "Portrait"; UserName = "******"; Message = "Message"; Setting = "Setting"; Previous = "Previous"; Play = "Play"; Next = "Next"; PlayMethod = "PlaySingleCycle"; Volume = "Volume"; Like = "LikeRed"; PlayList = "PlayList"; StaticButtons = new ObservableCollection <ButtonContent>(); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Search", ButtonContent_Text = "搜索", FuncKey = "1" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Music", ButtonContent_Text = "发现音乐", FuncKey = "2" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "MV", ButtonContent_Text = "MV", FuncKey = "3" }); StaticButtons.Add(new ButtonContent() { ButtonContent_Img = "Friends", ButtonContent_Text = "朋友", FuncKey = "4" }); titleButton_Click = new GalaSoft.MvvmLight.Command.RelayCommand <string>(TitleButtonFunc); listButton_Click = new GalaSoft.MvvmLight.Command.RelayCommand <string>(ListButtonFunc); previousSong = new GalaSoft.MvvmLight.Command.RelayCommand(PreviousSongFunc); playSong = new GalaSoft.MvvmLight.Command.RelayCommand(PlaySongFunc); nextSong = new GalaSoft.MvvmLight.Command.RelayCommand(NextSongFunc); wo = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback()); wo.PlaybackStopped += PlaybackStopped; songList = playEntity.Traversal(); getCurrrentTime_th = new Thread(() => { while (!Cancel) { PlayingCurrentTime = mp3FileReader.CurrentTime.ToString().Substring(0, 8); Thread.Sleep(500); } }); } }
internal static void StartAmbientLoop() { var athread = new Thread(() => { MemoryStream str = null; NAudio.Wave.Mp3FileReader mp3 = null; NAudio.Wave.WaveOut o = null; bool shuttingDown = false; Engine.AppearanceManager.OnExit += () => { shuttingDown = true; o?.Stop(); o?.Dispose(); mp3?.Close(); mp3?.Dispose(); str?.Close(); str?.Dispose(); }; while (shuttingDown == false) { if (Engine.SaveSystem.CurrentSave != null) { if (Engine.SaveSystem.CurrentSave.MusicEnabled) { str = new MemoryStream(GetRandomSong()); mp3 = new NAudio.Wave.Mp3FileReader(str); o = new NAudio.Wave.WaveOut(); o.Init(mp3); bool c = false; o.Play(); o.PlaybackStopped += (s, a) => { c = true; }; while (!c) { if (Engine.SaveSystem.CurrentSave.MusicEnabled) { try { o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; } catch { } } else { o.Stop(); c = true; } Thread.Sleep(10); } } else { Thread.Sleep(10); } } else { Thread.Sleep(10); } } }); athread.IsBackground = true; athread.Start(); }
private void FMV_Load(object sender, EventArgs e) { /*double ticks = 10000000.0 / (Video.Header.FrameRate / 256.0); float exp = (float)(ticks - Math.Floor(ticks)); if (exp != 0) { int i = 0; float result; do { i++; result = exp * i; } while((float)(result - Math.Floor(result)) != 0); }*/ //TODO: Calculate timing based on fps if ((Video.Header.Flags & 4) == 4) { AudioConverter = new ADPCM(); AudioBuffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat((int)Video.Header.AudioRate, 16, 1)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 8192 * 16; Player = new NAudio.Wave.WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); } new System.Threading.Thread(new System.Threading.ThreadStart(delegate { int state = 0; while (!stop) { if (Frames.Count != 0) { pictureBox1.Image = Frames.Dequeue(); switch (state) { case 0: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666666)); break; case 1: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666667)); break; case 2: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666667)); break; } state = (state + 1) % 3; } } System.Threading.Thread.CurrentThread.Abort(); })).Start(); backgroundWorker1.RunWorkerAsync(); }
private void Play_TTS_file(string filename) { Console.WriteLine("In Play_TTS_file start"); NAudio.Wave.WaveFileReader audio = new NAudio.Wave.WaveFileReader(filename); NAudio.Wave.IWavePlayer player = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback()); player.Init(audio); player.Play(); while (true) { if (player.PlaybackState == NAudio.Wave.PlaybackState.Stopped) { player.Dispose(); //MessageBox.Show("disposed"); audio.Close(); audio.Dispose(); break; } }; Console.WriteLine("After Play_TTS_File while loop"); }
public static void Brute() { TerminalBackend.PrefixEnabled = false; bool cracked = false; var brute = Properties.Resources.brute; var str = new System.IO.MemoryStream(brute); var reader = new NAudio.Wave.Mp3FileReader(str); var _out = new NAudio.Wave.WaveOut(); _out.Init(reader); _out.PlaybackStopped += (o, a) => { if (cracked == false) { cracked = true; TerminalCommands.Clear(); ConsoleEx.Bold = true; ConsoleEx.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" - access denied - "); ConsoleEx.ForegroundColor = ConsoleColor.Gray; ConsoleEx.Bold = false; ConsoleEx.Italic = true; Console.WriteLine("password could not be cracked before connection termination."); } TerminalBackend.PrefixEnabled = true; TerminalBackend.PrintPrompt(); _out.Dispose(); reader.Dispose(); str.Dispose(); }; _out.Play(); var t = new Thread(() => { Console.WriteLine("brute - version 1.0"); Console.WriteLine("Copyright (c) 2018 hacker101. All rights reserved."); Console.WriteLine(); Thread.Sleep(4000); Console.WriteLine("Scanning outbound connections..."); if (string.IsNullOrWhiteSpace(Applications.FileSkimmer.OpenConnection.SystemName)) { Thread.Sleep(2000); Console.WriteLine(" - no outbound connections to scan, aborting - "); _out.Stop(); _out.Dispose(); reader.Dispose(); str.Dispose(); } else { Thread.Sleep(2000); var con = Applications.FileSkimmer.OpenConnection; Console.WriteLine($@"{con.SystemName} ------------------ Active connection: ftp, rts System name: {con.SystemName} Users: {con.Users.Count}"); Thread.Sleep(500); var user = con.Users.FirstOrDefault(x => x.Permissions == Objects.UserPermissions.Root); if (user == null) { Console.WriteLine(" - no users found with root access - this is a shiftos bug - "); } else { Console.WriteLine(" - starting bruteforce attack on user: "******" - "); char[] pass = new char[user.Password.Length]; for (int i = 0; i < pass.Length; i++) { if (cracked == true) { break; } for (char c = (char)0; c < (char)255; c++) { if (!char.IsLetterOrDigit(c)) { continue; } pass[i] = c; if (pass[i] == user.Password[i]) { break; } Console.WriteLine(new string(pass)); } } if (cracked == false) { cracked = true; TerminalCommands.Clear(); Console.WriteLine(" - credentials cracked. -"); Console.WriteLine($@"sysname: {con.SystemName} user: {user.Username} password: {user.Password}"); } } } }); t.Start(); }