Пример #1
0
 /// <summary>
 /// Try to play the sound in the current animation.
 /// </summary>
 /// <param name="loopCount">How many times the sound should repeat. </param>
 /// <remarks>Sound is played only if the volume is greater than 0 and there are no sound problems.</remarks>
 public void Play(int loopCount)
 {
     if (Properties.Settings.Default.Volume > 0.0)
     {
         try
         {
             if (Audio.Volume != Properties.Settings.Default.Volume)
             {
                 Audio.Volume = Properties.Settings.Default.Volume;
             }
             // Set event handler only if looped
             if (loopCount > 0)
             {
                 LoopCount = loopCount;
             }
             AudioReader.Seek(0, SeekOrigin.Begin);
             Audio.Play();
         }
         catch (Exception e)
         {
             // Failed to play a wave, reset volume
             Properties.Settings.Default.Volume = 0;
             Program.Mainthread.ErrorMessages.AudioErrorMessage = e.Message;
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Try to play the sound in the current animation.
 /// </summary>
 /// <param name="loopCount">How many times the sound should repeat. </param>
 /// <remarks>Sound is played only if the volume is greater than 0 and there are no sound problems.</remarks>
 public void Play(int loopCount)
 {
     if (Program.MyData.GetVolume() > 0.0)
     {
         try
         {
             if (Audio.Volume != Program.MyData.GetVolume())
             {
                 Audio.Volume = (float)Program.MyData.GetVolume();
             }
             // Set event handler only if looped
             if (loopCount > 0)
             {
                 LoopCount = loopCount;
             }
             AudioReader.Seek(0, SeekOrigin.Begin);
             Audio.Play();
         }
         catch (Exception e)
         {
             // Failed to play a wave, reset volume
             Program.MyData.SetVolume(0.0);
             Program.Mainthread.ErrorMessages.AudioErrorMessage = e.Message;
         }
     }
 }
        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 = "";
            }
        }
Пример #4
0
 /// <summary>
 /// Try to play the sound in the current animation.
 /// </summary>
 /// <param name="loopCount">How many times the sound should repeat. </param>
 /// <remarks>Sound is played only if the volume is greater than 0 and there are no sound problems.</remarks>
 public void Play(int loopCount)
 {
     try
     {
         // Set event handler only if looped
         if (loopCount > 0)
         {
             LoopCount = loopCount;
         }
         AudioReader.Seek(0, SeekOrigin.Begin);
         Audio.Play();
     }
     catch (Exception)
     {
     }
 }
Пример #5
0
        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);
        }
 /// <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();
 }
Пример #7
0
        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();
        }
Пример #8
0
            public AudioPlayer(NAudio.Wave.IWaveProvider provider)
            {
                _playbackDevice.Init(provider);
                _playbackDevice.Play();

                _playbackDevice.PlaybackStopped += (sender, args) =>
                {
                    //MessageBox.Show("stop");
                    //Console.WriteLine("Playback stopped: " + args.Exception);
                };
            }
Пример #9
0
        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);
        }
Пример #10
0
        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();
        }
Пример #11
0
 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();
         }
     }
 }
Пример #12
0
 void PreviousSongFunc()
 {
     isCausedByFunc = true;
     songList       = playEntity.Traversal();
     if (songList != null && songList.Length != 0)
     {
         Play         = "Pause";
         PlayingIndex = (PlayingIndex + songList.Length - 1) % songList.Length;
         wo.Dispose();
         mp3FileReader    = new NAudio.Wave.Mp3FileReader(songList[PlayingIndex].FullName);
         PlayingTotalTime = mp3FileReader.TotalTime.ToString().Substring(0, 8);
         string[] temp = songList[PlayingIndex].Name.Split('-');
         SingerName = temp[0];
         SongName   = temp[1];
         wo.Init(mp3FileReader);
         wo.Play();
         if ((getCurrrentTime_th.ThreadState & ThreadState.Unstarted) == ThreadState.Unstarted)
         {
             getCurrrentTime_th.Start();
         }
         IsPlayed  = true;
         IsPlaying = true;
     }
 }
Пример #13
0
        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();
        }
Пример #14
0
        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();
            }
        }
Пример #15
0
        private static void TryJukeboxStart()
        {
            if (_jukeboxList == null)
            {
                return;
            }

            IList <Spotify.Track> tracks = _jukeboxList.Tracks;

            if (tracks.Count == 0)
            {
                Console.WriteLine("jukebox: No more tracks in playlist. Waiting");
                return;
            }

            if (_trackIndex >= tracks.Count)
            {
                Console.WriteLine("jukebox: Not more tracks in playlist. Waiting");
                return;
            }

            Spotify.Track track = tracks[_trackIndex];

            if (_currentTrack != null && !_currentTrack.IsClone(track))
            {
                _session.PlayerUnload();
                _audioSink.Stop();
                _audioProvider.ClearBuffer();
                _currentTrack = null;
            }

            if (track.Error != Spotify.Error.Ok)
            {
                return;
            }

            if (_currentTrack != null && _currentTrack.IsClone(track))
            {
                return;
            }

            Console.WriteLine("jukebox: Now playing \"{0}\"...", track.Name);

            _session.PlayerLoad(track);
            _session.PlayerPlay(true);
            _audioSink.Play();
            _currentTrack = track;
        }
Пример #16
0
        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();
        }
Пример #17
0
        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");
        }
Пример #18
0
        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;
        }
Пример #19
0
        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;
        }
Пример #20
0
        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();
        }
Пример #21
0
 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");
 }
Пример #22
0
 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();
 }
Пример #23
0
        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));
                 * }*/
            }
        }
Пример #24
0
 public override void Play()
 {
     waveOut.Play();
 }
Пример #25
0
        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();
            }



        }
        //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;
        }
Пример #27
0
        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();
        }