當前位置: 首頁>>代碼示例>>C#>>正文


C# Wave.AudioFileReader類代碼示例

本文整理匯總了C#中NAudio.Wave.AudioFileReader的典型用法代碼示例。如果您正苦於以下問題:C# AudioFileReader類的具體用法?C# AudioFileReader怎麽用?C# AudioFileReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AudioFileReader類屬於NAudio.Wave命名空間,在下文中一共展示了AudioFileReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanDownsampleAnMp3File

 public void CanDownsampleAnMp3File()
 {
     string testFile = @"D:\Audio\Music\Coldplay\Mylo Xyloto\03 - Paradise.mp3";
     if (!File.Exists(testFile)) Assert.Ignore(testFile);
     string outFile = @"d:\test22.wav";
     using (var reader = new AudioFileReader(testFile))
     {
         // downsample to 22kHz
         var resampler = new WdlResamplingSampleProvider(reader, 22050);
         var wp = new SampleToWaveProvider(resampler);
         using (var writer = new WaveFileWriter(outFile, wp.WaveFormat))
         {
             byte[] b = new byte[wp.WaveFormat.AverageBytesPerSecond];
             while (true)
             {
                 int read = wp.Read(b, 0, b.Length);
                 if (read > 0)
                     writer.Write(b, 0, read);
                 else
                     break;
             }
         }
         //WaveFileWriter.CreateWaveFile(outFile, );
     }
 }
開發者ID:LibertyLocked,項目名稱:NAudio,代碼行數:25,代碼來源:WdlResamplingSampleProviderTests.cs

示例2: Main

        static void Main(string[] args)
        {
            string mp3FilesDir = Directory.GetCurrentDirectory();

            if (args.Length > 0)
            {
                mp3FilesDir = args.First();
            }

            var waveOutDevice = new WaveOut();

            var idToFile = Directory.GetFiles(mp3FilesDir, "*.mp3", SearchOption.AllDirectories).ToDictionary(k => int.Parse(Regex.Match(Path.GetFileName(k), @"^\d+").Value));
            while (true)
            {
                Console.WriteLine("Wprowadz numer nagrania");
                var trackId = int.Parse(Console.ReadLine());

                using (var audioFileReader = new AudioFileReader(idToFile[trackId]))
                {
                    waveOutDevice.Init(audioFileReader);
                    waveOutDevice.Play();

                    Console.ReadLine();
                }
            }
            
        }
開發者ID:onliner10,項目名稱:FiszkiPlayer,代碼行數:27,代碼來源:Program.cs

示例3: BuildWavePartAudio

 private ISampleProvider BuildWavePartAudio(UWavePart part, UProject project)
 {
     AudioFileReader stream;
     try { stream = new AudioFileReader(part.FilePath); }
     catch { return null; }
     return new WaveToSampleProvider(stream);
 }
開發者ID:KineticIsEpic,項目名稱:OpenUtau,代碼行數:7,代碼來源:PlaybackManager.cs

示例4: CachedSound

 public CachedSound(string audioFileName)
 {
     using (var audioFileReader = new AudioFileReader(audioFileName))
     {
         WaveFormat = audioFileReader.WaveFormat;
         if (WaveFormat.SampleRate != 44100 || WaveFormat.Channels != 2)
         {
             using (var resampled = new ResamplerDmoStream(audioFileReader, WaveFormat.CreateIeeeFloatWaveFormat(44100, 2)))
             {
                 var resampledSampleProvider = resampled.ToSampleProvider();
                 WaveFormat = resampledSampleProvider.WaveFormat;
                 var wholeFile = new List<float>((int) (resampled.Length));
                 var readBuffer = new float[resampled.WaveFormat.SampleRate * resampled.WaveFormat.Channels];
                 int samplesRead;
                 while ((samplesRead = resampledSampleProvider.Read(readBuffer, 0, readBuffer.Length)) > 0)
                 {
                     wholeFile.AddRange(readBuffer.Take(samplesRead));
                 }
                 AudioData = wholeFile.ToArray();
             }
         }
         else
         {
             var wholeFile = new List<float>((int) (audioFileReader.Length / 4));
             var readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels];
             int samplesRead;
             while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0)
             {
                 wholeFile.AddRange(readBuffer.Take(samplesRead));
             }
             AudioData = wholeFile.ToArray();
         }
     }
 }
開發者ID:Yaguar666,項目名稱:ffxivapp-common,代碼行數:34,代碼來源:CachedSound.cs

示例5: ExtractWaveProvider

		long _length;		// Number of bytes left to read

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="start">in seconds</param>
		/// <param name="length">in seconds</param>
		public ExtractWaveProvider(AudioFileReader reader, float start, float length) {
			_reader = reader;
			// Position to start
			_reader.Position = _reader.WaveFormat.SecondsToBytes(start);
			// Number of bytes to read
			_length = _reader.WaveFormat.SecondsToBytes(length);
		}
開發者ID:nikkilocke,項目名稱:AlbumRecorder,代碼行數:14,代碼來源:ExtractWaveProvider.cs

示例6: play_Click

        private void play_Click(object sender, EventArgs e)
        {
            if (playlist.SelectedItems.Count>0)
            {
                id = fn.IndexOf(playlist.SelectedItem.ToString());
                if (waveOutDevice.PlaybackState.ToString() != "Paused")
                {
                    t.Stop();
                    stp();
                    audioFileReader = new AudioFileReader(fp[id]);
                    waveOutDevice = new WaveOut();
                    waveOutDevice.Init(audioFileReader);
                    trackbar.Maximum = (int)audioFileReader.TotalTime.TotalSeconds + 1;
                    //deb.Items.Add(audioFileReader.TotalTime.Seconds.ToString());
                    audioFileReader.Volume = (float)vol.Value / 100;
                    waveOutDevice.Play();
                    t.Start();

                }
                else
                {
                    waveOutDevice.Play();
                    t.Start();
                }
            }
            
           
            
        }
開發者ID:npuMa94,項目名稱:npuMathecreator,代碼行數:29,代碼來源:Form1.cs

示例7: Start

        private async Task Start(string audioFile)
        {
            await Task.Run(() =>
            {
                try
                {
                    lock (syncLock)
                    {
                        using (var audioFileReader = new AudioFileReader(audioFile))
                        {
                            audioFileReader.Volume = settingsService.Settings.Volume * 0.01f;

                            using (dso = new DirectSoundOut(settingsService.Settings.AudioDeviceId))
                            {
                                dso.Init(audioFileReader);

                                using (eventWaiter = new ManualResetEvent(false))
                                {
                                    dso.Play();
                                    dso.PlaybackStopped += (sender, args) => eventWaiter.Set();
                                    eventWaiter.WaitOne();
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {

                }
            });
        }
開發者ID:pjmagee,項目名稱:swtor-caster,代碼行數:32,代碼來源:AudioService.cs

示例8: Main

		public static void Main(string[] argv)
		{
			ISampleProvider decoder = new AudioFileReader(FILE);
			SpectrumProvider spectrumProvider = new SpectrumProvider(decoder, 1024, HOP_SIZE, true);
			float[] spectrum = spectrumProvider.nextSpectrum();
			float[] lastSpectrum = new float[spectrum.Length];
			List<float> spectralFlux = new List<float>();

			do
			{
				float flux = 0;
				for(int i = 0; i < spectrum.Length; i++)
				{
					float @value = (spectrum[i] - lastSpectrum[i]);
					flux += @value < 0 ? 0 : @value;
				}
				spectralFlux.Add(flux);

				System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length);
			} while((spectrum = spectrumProvider.nextSpectrum()) != null);

			Plot plot = new Plot("Hopping Spectral Flux", 1024, 512);
			plot.plot(spectralFlux, 1, Color.Red);
			new PlaybackVisualizer(plot, HOP_SIZE, FILE);
		}
開發者ID:LuckyLuik,項目名稱:AudioVSTToolbox,代碼行數:25,代碼來源:HoppingSpectralFlux.cs

示例9: ConvertToMP3

        public static void ConvertToMP3(string inFile, string outFile, int bitRate = 64)
        {

            using (var reader = new AudioFileReader(inFile))
            {
                using (var writer = new LameMP3FileWriter(outFile, reader.WaveFormat, bitRate))
                    reader.CopyTo(writer);
            }
        }
開發者ID:rayanc,項目名稱:Pecuniaus,代碼行數:9,代碼來源:AudioHelper.cs

示例10: playnhac

 private void playnhac()
 {
     IWavePlayer waveOutDevice;
     AudioFileReader audioFileReader;
     waveOutDevice = new WaveOut();
     audioFileReader = new AudioFileReader("animal.mp3");
     waveOutDevice.Init(audioFileReader);
     waveOutDevice.Play();
 }
開發者ID:tranquangchau,項目名稱:cshap-2008-2013,代碼行數:9,代碼來源:Form1.cs

示例11: PlaySong

 public void PlaySong()
 {
     // Instantiate audio player
     waveOutDevice = new WaveOut();
     // Set MP3 to play
     audioFileReader = new AudioFileReader(GetSong());
     // Init device and call play
     waveOutDevice.Init(audioFileReader);
     waveOutDevice.Play();
 }
開發者ID:Brendo311,項目名稱:AlarmClockWakeTheFuckUp,代碼行數:10,代碼來源:SoundAlarm.cs

示例12: OnsetDetection

        // Constructor
        public OnsetDetection(AudioFileReader pcm, int sampleWindow)
        {
            PCM = pcm;
            SampleSize = sampleWindow;

            spectrum = new float[sampleWindow / 2 + 1];
            previousSpectrum = new float[spectrum.Length];
            rectify = true;
            fluxes = new List<float>();
        }
開發者ID:CodeFunta,項目名稱:HudlFfmpeg,代碼行數:11,代碼來源:OnsetDetection.cs

示例13: PlaySound

        public static void PlaySound(NotificationSound sound)
        {
            IWavePlayer waveOutDevice;
            AudioFileReader audioFileReader;
            waveOutDevice = new WaveOut();

            audioFileReader = new AudioFileReader("resources/sounds/message.mp3");
            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();
        }
開發者ID:kioltk,項目名稱:VKDesktop,代碼行數:10,代碼來源:Notificator.cs

示例14: buttonSelectFile_Click

 private void buttonSelectFile_Click(object sender, EventArgs e)
 {
     Cleanup();
     var ofd = new OpenFileDialog();
     ofd.Filter = "Audio files|*.wav;*.mp3";
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         this.reader = new AudioFileReader(ofd.FileName);
     }
 }
開發者ID:LibertyLocked,項目名稱:NAudio,代碼行數:10,代碼來源:AsioDirectPanel.cs

示例15: LoadMp3File

        public void LoadMp3File(string fileName)
        {
            if (aReader != null)
                aReader.Dispose();

            aReader = new AudioFileReader(fileName);
            var sampleChannel = new SampleChannel(aReader, true);
            volumeMeter = new MeteringSampleProvider(sampleChannel);

            player.Init(volumeMeter);
        }
開發者ID:dotinfinity,項目名稱:srw,代碼行數:11,代碼來源:RadioStationMain.cs


注:本文中的NAudio.Wave.AudioFileReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。