Esempio n. 1
0
 public void Init(string path)
 {
     Reset();
     reader = new AudioFileReader(path);
     barPlayer.TotalTime = reader.TotalTime;
     player.Init(reader);
     tmrRefresh.Start();
     RefreshPlayButton();
 }
Esempio n. 2
0
 private static async Task PlayMp3Async(string mp3FilePath)
 {
     using var audioFile    = new AudioFileReader(mp3FilePath);
     using var outputDevice = new WaveOutEvent();
     outputDevice.Init(audioFile);
     outputDevice.Play();
     int totalTime = Convert.ToInt32(Math.Floor(audioFile.TotalTime.TotalMilliseconds));
     await Task.Delay(totalTime);
 }
Esempio n. 3
0
        ///////////////////////////////////////////////////////////////////////////////////////////

        // FUNCTIONS //////////////////////////////////////////////////////////////////////////////
        private void SoundInite()
        {
            _waveOut = new WaveOutEvent
            {
                DeviceNumber = 0,
            };
            _waveProvider = new BufferedWaveProvider(new WaveFormat(8000, 32, 2));
            _waveOut.Init(_waveProvider);
        }
Esempio n. 4
0
 private void openFileDialog_FileOk(object sender, CancelEventArgs e)
 {
     audioPath    = openFileDialog.FileName;
     fileReader   = new MediaFoundationReader(audioPath);
     outputDevice = new WaveOutEvent();
     outputDevice.Init(fileReader);
     musicTrackBar.Maximum = fileReader.TotalTime.Minutes * 60 + fileReader.TotalTime.Seconds;
     maximumDuration.Text  = fileReader.TotalTime.Minutes.ToString("00") + ":" + fileReader.TotalTime.Seconds.ToString("00");
 }
Esempio n. 5
0
        public MusicPlayer(string filePath)
        {
            waveOut   = new WaveOutEvent();
            mp3Reader = new Mp3FileReader(filePath);
            waveOut.Init(mp3Reader);


            SongTitle = System.IO.Path.GetFileName(filePath);
        }
Esempio n. 6
0
        private WaveOutEvent PlayMusic(string filename)
        {
            var audioFileReader = new AudioFileReader(@"Resources\" + filename);
            var waveOutEvent    = new WaveOutEvent();

            waveOutEvent.Init(audioFileReader);
            waveOutEvent.Play();
            return(waveOutEvent);
        }
Esempio n. 7
0
 //////////////////////////////////////////////////////////////////////
 //
 //////////////////////////////////////////////////////////////////////
 public Sound1()
 {
     m_waveProvider = new QuadrangularWaveProvider32(SoundManager.eSoundChannel.e_soundChannel_1, 0xFF10, 0xFF11, 0xFF12, 0xFF13, 0xFF14, true, "s01.wav");
     m_waveProvider.SetWaveFormat(44100, 2);
     m_waveOut = new WaveOutEvent();
     m_waveOut.DesiredLatency = 100;
     m_waveOut.Init(m_waveProvider);
     m_waveOut.Play();
 }
Esempio n. 8
0
        private void ListView1_DoubleClick(object sender, EventArgs e)
        {
            string         wavPath        = textOTOpath.Text.Remove(textOTOpath.Text.LastIndexOf(@"\") + 1);
            WaveOutEvent   waveOut        = new WaveOutEvent();
            WaveFileReader waveFileReader = new WaveFileReader(wavPath + listView1.SelectedItems[0].SubItems[1].Text);

            waveOut.Init(waveFileReader);
            waveOut.Play();
        }
Esempio n. 9
0
        public void Doof() //Afspiller sang når man start programmet
        {
            outputDevice = new WaveOutEvent();
            audioFile    = new AudioFileReader(AppDomain.CurrentDomain.BaseDirectory + "\\Musik\\My Name Is Doof.flac");
            LoopStream loop = new LoopStream(audioFile);

            outputDevice.Init(loop);
            outputDevice.Play();
        }
 //set current song
 private void _setCurrentSong(Song song)
 {
     OutputDevice = new WaveOutEvent();
     OutputDevice.PlaybackStopped += _onPlayBackStopped;
     AudioFile = new AudioFileReader(song.Path);
     OutputDevice.Init(AudioFile);
     this._updateSliederAll();
     this.SongListView.SelectedIndex = this.SongList.CurrentIndex;
 }
Esempio n. 11
0
 internal static void PlaySound(string musicFile, int milliSeconds = 0)
 {
     // Takes in an audio file & controls the wait time to start
     audioFile    = new AudioFileReader(musicFile);
     outputDevice = new WaveOutEvent();
     outputDevice.Init(audioFile);
     outputDevice.Play();
     Thread.Sleep(milliSeconds);
 }
Esempio n. 12
0
File: Beep.cs Progetto: hearchad/poc
        public void Play(int duration = 500)
        {
            stereo.LeftVolume  = Volume.Left;
            stereo.RightVolume = Volume.Right;

            waveOut.Stop();
            waveOut.Init(stereo.Take(TimeSpan.FromMilliseconds(duration)));
            waveOut.Play();
        }
Esempio n. 13
0
 public void Stop()
 {
     _mixer.RemoveAllMixerInputs();
     _outputDevice.Stop();
     if (EnumerateDevices().ContainsKey(_outputDevice.DeviceNumber))
     {
         _outputDevice.Init(_mixer);
     }
 }
Esempio n. 14
0
        public static void play(String name)
        {
            WaveOutEvent   output_device = new WaveOutEvent();
            Stream         stream        = Properties.Resources.ResourceManager.GetStream(name);
            WaveFileReader reader        = new WaveFileReader(stream);

            output_device.Init(reader);
            output_device.Play();
        }
Esempio n. 15
0
 public void LoadFile(string fileName)
 {
     audioFile = new AudioFileReader(fileName);
     if (outputDevice.PlaybackState != PlaybackState.Stopped)
     {
         Stop();
     }
     outputDevice.Init(audioFile);
 }
Esempio n. 16
0
 public void PreExecution()
 {
     player              = new WaveOutEvent();
     provider            = new BufferedWaveProvider(recorder.WaveFormat);
     player.DeviceNumber = settings.DeviceChoice;
     player.Init(provider);
     player.Play();
     provider.BufferDuration = new TimeSpan(0, 0, 0, 0, settings.BufferSize);
 }
Esempio n. 17
0
        public static void Play(byte[] data)
        {
            MemoryStream ms     = new MemoryStream(data);
            WaveStream   ws     = new Mp3FileReader(ms);
            WaveOutEvent output = new WaveOutEvent();

            output.Init(ws);
            output.Play();
        }
Esempio n. 18
0
        //static BufferedWaveProvider m_provider;

        //static AudioClip m_clip;

        public static void Init()
        {
            var fileName      = "Sound/honk.wav";
            var rootDirectory = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
            var dir           = Path.Combine(Path.Combine(rootDirectory, Defaults.PrivateAssetsDirectory), fileName);

            m_audioFile = new AudioFileReader(dir);

            m_outputDevice = new WaveOutEvent()
            {
                NumberOfBuffers = 10,
                DesiredLatency  = 85
            };
            m_outputDevice.Init(m_audioFile);


            //var asset = new Assets("Sound/noot");

            //foreach (var n in asset.Bundle.GetAllAssetNames())
            //{
            //    if(n.EndsWith(".wav"))
            //    {
            //        var obj2 = asset.Bundle.LoadAsset<AudioClip>(n);
            //        obj2.LoadAudioData();
            //        Console.WriteLine(obj2.GetType());
            //        Console.WriteLine(obj2);
            //        m_clip = obj2;
            //    }
            //    if (!n.EndsWith(".prefab"))
            //        continue;
            //    var obj = asset.Bundle.LoadAsset<GameObject>(n);
            //    if (obj == null)
            //        continue;
            //    var source = obj.GetComponentInChildren<AudioSource>();
            //    if (source == null)
            //        continue;

            //    var clip = source.clip;
            //    if (clip == null)
            //        continue;

            //    float[] data = new float[clip.samples * clip.channels];
            //    clip.GetData(data, data.Length);

            //    m_provider = new BufferedWaveProvider(new WaveFormat(48000, 16, 1));
            //    var samples = GetSamplesWaveData(data, data.Length);
            //    m_provider.AddSamples(samples, 0, samples.Length);

            //    m_outputDevice = new WaveOutEvent()
            //    {
            //        NumberOfBuffers = 10,
            //        DesiredLatency = 85
            //    };
            //    m_outputDevice.Init(m_provider);
            //}
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            Console.Clear();

            WaveFileStream waveProvider = new WaveFileStream("song.wav");

            var waveOut = new WaveOutEvent
            {
                NumberOfBuffers = 2
            };

            waveOut.Init(waveProvider);
            waveOut.Play();

            Console.WriteLine("Playing song!");
            int cx = Console.CursorLeft;
            int cy = Console.CursorTop;

            Console.CursorVisible = false;

            char[] input    = new char[30];
            int    inputPos = 0;

            while (waveOut.PlaybackState == PlaybackState.Playing)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Backspace && inputPos != 0)
                    {
                        input[inputPos--] = ' ';
                    }
                    else if (key.Key == ConsoleKey.Enter && inputPos != 0)
                    {
                        if (int.TryParse(new string(input), out int result))
                        {
                            waveProvider.Position = waveProvider.FormatChunkData.ByteRate * result;
                        }
                        inputPos = 0;
                        Array.Clear(input, 0, 30);
                    }
                    else
                    {
                        input[inputPos] = key.KeyChar;
                        if (inputPos <= 28)
                        {
                            inputPos++;
                        }
                    }
                }
                Console.SetCursorPosition(0, cy + 1);
                Console.Write(input);
                Console.SetCursorPosition(cx, cy);
                Console.Write("Playing for {0}s", waveProvider.Position / waveProvider.FormatChunkData.ByteRate);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Handling packets received on the RTP socket. One of the simplest, if not the simplest, cases, is
        /// PCMU audio packets. THe handling can get substantially more complicated if the RTP socket is being
        /// used to multiplex different protocols. This is what WebRTC does with STUN, RTP and RTCP.
        /// </summary>
        /// <param name="rtpSocket">The raw RTP socket.</param>
        /// <param name="rtpSendSession">The session infor for the RTP pakcets being sent.</param>
        private static async void RecvRtp(Socket rtpSocket, RTPSession rtpRecvSession, CancellationTokenSource cts)
        {
            try
            {
                DateTime lastRecvReportAt    = DateTime.Now;
                uint     packetReceivedCount = 0;
                uint     bytesReceivedCount  = 0;
                byte[]   buffer = new byte[512];

                IPEndPoint anyEndPoint = new IPEndPoint((rtpSocket.AddressFamily == AddressFamily.InterNetworkV6) ? IPAddress.IPv6Any : IPAddress.Any, 0);

                Log.LogDebug($"Listening on RTP socket {rtpSocket.LocalEndPoint}.");

                using (var waveOutEvent = new WaveOutEvent())
                {
                    var waveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));
                    waveProvider.DiscardOnBufferOverflow = true;
                    waveOutEvent.Init(waveProvider);
                    waveOutEvent.Play();

                    var recvResult = await rtpSocket.ReceiveFromAsync(buffer, SocketFlags.None, anyEndPoint);

                    Log.LogDebug($"Initial RTP packet recieved from {recvResult.RemoteEndPoint}.");

                    while (recvResult.ReceivedBytes > 0 && !cts.IsCancellationRequested)
                    {
                        var rtpPacket = new RTPPacket(buffer.Take(recvResult.ReceivedBytes).ToArray());

                        packetReceivedCount++;
                        bytesReceivedCount += (uint)rtpPacket.Payload.Length;

                        for (int index = 0; index < rtpPacket.Payload.Length; index++)
                        {
                            short  pcm       = NAudio.Codecs.MuLawDecoder.MuLawToLinearSample(rtpPacket.Payload[index]);
                            byte[] pcmSample = new byte[] { (byte)(pcm & 0xFF), (byte)(pcm >> 8) };
                            waveProvider.AddSamples(pcmSample, 0, 2);
                        }

                        recvResult = await rtpSocket.ReceiveFromAsync(buffer, SocketFlags.None, anyEndPoint);

                        if (DateTime.Now.Subtract(lastRecvReportAt).TotalSeconds > RTP_REPORTING_PERIOD_SECONDS)
                        {
                            // This is typically where RTCP receiver (SR) reports would be sent. Omitted here for brevity.
                            lastRecvReportAt = DateTime.Now;
                            var remoteRtpEndPoint = recvResult.RemoteEndPoint as IPEndPoint;
                            Log.LogDebug($"RTP recv report {rtpSocket.LocalEndPoint}<-{remoteRtpEndPoint} pkts {packetReceivedCount} bytes {bytesReceivedCount}");
                        }
                    }
                }
            }
            catch (ObjectDisposedException) { } // This is how .Net deals with an in use socket being closed. Safe to ignore.
            catch (Exception excp)
            {
                Log.LogError($"Exception processing RTP. {excp}");
            }
        }
Esempio n. 21
0
 private void SoundPlayer(string Path)
 {
     try
     {
         Mp3FileReader Mp3FileReader = new Mp3FileReader(Path);
         WaveOutEvent.Init(Mp3FileReader);
         WaveOutEvent.Play();
     }
     catch { }
 }
 public SoundpanelAudioPlayer(Stream audioBuffer, float volume)
 {
     _audioFileReader          = new WaveFileReader(audioBuffer);
     _output                   = new WaveOutEvent();
     _output.PlaybackStopped  += _output_PlaybackStopped;
     waveChannel               = new WaveChannel32(_audioFileReader);
     waveChannel.PadWithZeroes = false;
     _output.Init(waveChannel);
     PlaybackStopType = PlaybackStopTypes.PlaybackStoppedReachingEndOfFile;
 }
Esempio n. 23
0
        public ResourceSound(string resourcePath, byte[] data) : base(resourcePath, data)
        {
            if (!resourcePath.EndsWith(".ogg"))
            {
                throw new Exception("Only *.ogg audio files are supported");
            }

            _mixer = new MixingSampleProvider(new VorbisSampleProvider(new MemoryStream(data)).WaveFormat);
            _outputDevice.Init(_mixer);
        }
Esempio n. 24
0
 public static void DeathSound()
 {
     using (var waveOut = new WaveOutEvent())
         using (var wavReader = new WaveFileReader("DS.wav"))
         {
             waveOut.Init(wavReader);
             waveOut.Play();
             Thread.Sleep(9000);
         }
 }
Esempio n. 25
0
 public static void GainSound()
 {
     using (var waveOut = new WaveOutEvent())
         using (var wavReader = new WaveFileReader("GS.wav"))
         {
             waveOut.Init(wavReader);
             waveOut.Play();
             Thread.Sleep(750);
         }
 }
Esempio n. 26
0
 public static void PlayBackgroundMusic()
 {
     using (var waveOut = new WaveOutEvent())
         using (var wavReader = new WaveFileReader("MGSBM.wav"))
         {
             waveOut.Init(wavReader);
             waveOut.Play();
             Thread.Sleep(14100);
         }
 }
Esempio n. 27
0
        public void InitWithStreamerData(StreamerData data)
        {
            this.data = data;
            file      = new AudioFileReader(data.NotifySoundPath);
            device.Init(file);
            device.Play();
            device.PlaybackStopped += Device_PlaybackStopped;

            ContentTextBlock.Text = $"{data.DisplayName}님의 방송이 켜졌습니다!";
        }
Esempio n. 28
0
 public AudioPlaybackEngine(int sampleRate = 44100, int channelCount = 2, int deviceNumber = 0)
 {
     outputDevice = new WaveOutEvent();
     outputDevice.DeviceNumber = deviceNumber;
     mixer           = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount));
     mixer.ReadFully = true;
     volume          = new VolumeSampleProvider(mixer);
     outputDevice.Init(volume);
     outputDevice.Play();
 }
Esempio n. 29
0
        public void PlayAudio()
        {
            string fileName = "myMp3File.mp3";
            var    builder  = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
            var    reader   = new Mp3FileReader(fileName, builder);

            // play or process the file, e.g.:
            _WaveOut.Init(reader);
            _WaveOut.Play();
        }
Esempio n. 30
0
 public TempPlayback(string ownedby)
 {
     owner  = ownedby;
     Buff   = new BufferedWaveProvider(new WaveFormat(48000, 1));
     WavOut = new WaveOutEvent();
     WavOut.DeviceNumber = -1;
     //WavOut.DesiredLatency = 25;
     WavOut.Init(Buff);
     WavOut.Play();
 }