当前位置: 首页>>代码示例>>C#>>正文


C# Mp3FileReader.Dispose方法代码示例

本文整理汇总了C#中NAudio.Wave.Mp3FileReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Mp3FileReader.Dispose方法的具体用法?C# Mp3FileReader.Dispose怎么用?C# Mp3FileReader.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NAudio.Wave.Mp3FileReader的用法示例。


在下文中一共展示了Mp3FileReader.Dispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PlaySound

 public void PlaySound(string name, Action done = null)
 {
     FileStream ms = File.OpenRead(_soundLibrary[name]);
     var rdr = new Mp3FileReader(ms);
     WaveStream wavStream = WaveFormatConversionStream.CreatePcmStream(rdr);
     var baStream = new BlockAlignReductionStream(wavStream);
     var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
     waveOut.Init(baStream);
     waveOut.Play();
     var bw = new BackgroundWorker();
     bw.DoWork += (s, o) =>
                      {
                          while (waveOut.PlaybackState == PlaybackState.Playing)
                          {
                              Thread.Sleep(100);
                          }
                          waveOut.Dispose();
                          baStream.Dispose();
                          wavStream.Dispose();
                          rdr.Dispose();
                          ms.Dispose();
                          if (done != null) done();
                      };
     bw.RunWorkerAsync();
 }
开发者ID:guozanhua,项目名称:KinectGestures,代码行数:25,代码来源:MainWindow.xaml.cs

示例2: waveformGenerateWorker_DoWork

        private void waveformGenerateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            WaveformGenerationParams waveformParams = e.Argument as WaveformGenerationParams;
            Mp3FileReader waveformMp3Stream = new Mp3FileReader(waveformParams.Path);
            WaveChannel32 waveformInputStream = new WaveChannel32(waveformMp3Stream);
            waveformInputStream.Sample += waveStream_Sample;

            int frameLength = fftDataSize;
            int frameCount = (int)((double)waveformInputStream.Length / (double)frameLength);
            int waveformLength = frameCount * 2;
            byte[] readBuffer = new byte[frameLength];
            waveformAggregator = new SampleAggregator(frameLength);

            float maxLeftPointLevel = float.MinValue;
            float maxRightPointLevel = float.MinValue;
            int currentPointIndex = 0;
            float[] waveformCompressedPoints = new float[waveformParams.Points];
            List<float> waveformData = new List<float>();
            List<int> waveMaxPointIndexes = new List<int>();

            for (int i = 1; i <= waveformParams.Points; i++)
            {
                waveMaxPointIndexes.Add((int)Math.Round(waveformLength * ((double)i / (double)waveformParams.Points), 0));
            }
            int readCount = 0;
            while (currentPointIndex * 2 < waveformParams.Points && waveformInputStream.Position < (waveformInputStream.Length - 1024))
            {
                waveformInputStream.Read(readBuffer, 0, readBuffer.Length);

                waveformData.Add(waveformAggregator.LeftMaxVolume);
                waveformData.Add(waveformAggregator.RightMaxVolume);

                if (waveformAggregator.LeftMaxVolume > maxLeftPointLevel)
                    maxLeftPointLevel = waveformAggregator.LeftMaxVolume;
                if (waveformAggregator.RightMaxVolume > maxRightPointLevel)
                    maxRightPointLevel = waveformAggregator.RightMaxVolume;

                if (readCount > waveMaxPointIndexes[currentPointIndex])
                {
                    waveformCompressedPoints[(currentPointIndex * 2)] = maxLeftPointLevel;
                    waveformCompressedPoints[(currentPointIndex * 2) + 1] = maxRightPointLevel;
                    maxLeftPointLevel = float.MinValue;
                    maxRightPointLevel = float.MinValue;
                    currentPointIndex++;
                }
                if (readCount % 3000 == 0)
                {
                    float[] clonedData = (float[])waveformCompressedPoints.Clone();
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        WaveformData = clonedData;
                    }));
                }

                if (waveformGenerateWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                readCount++;
            }

            float[] finalClonedData = (float[])waveformCompressedPoints.Clone();
            App.Current.Dispatcher.Invoke(new Action(() =>
            {
                fullLevelData = waveformData.ToArray();
                WaveformData = finalClonedData;
            }));
            waveformInputStream.Close();
            waveformInputStream.Dispose();
            waveformInputStream = null;
            waveformMp3Stream.Close();
            waveformMp3Stream.Dispose();
            waveformMp3Stream = null;
        }
开发者ID:moezRebai,项目名称:LightMusicPalyer,代码行数:75,代码来源:NAudioEngine.cs

示例3: waveformGenerateWorker_DoWork

        private void waveformGenerateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var waveformParams = (WaveformGenerationParams)e.Argument;

            float[] waveformDataFromCache;
            if (waveformDataCache.TryGet(waveformParams.Path, out waveformDataFromCache))
            {
                Application.Current.Dispatcher.Invoke(() => WaveformData = waveformDataFromCache);
                return;
            }

            Mp3FileReader waveformMp3Stream = new Mp3FileReader(waveformParams.Path);
            WaveChannel32 waveformInputStream = new WaveChannel32(waveformMp3Stream);
            waveformInputStream.Sample += waveStream_Sample;

            int frameLength = fftDataSize;
            int frameCount = (int)((double)waveformInputStream.Length / (double)frameLength);
            int waveformLength = frameCount * 2;
            byte[] readBuffer = new byte[frameLength];
            waveformAggregator = new SampleAggregator(frameLength);

            float maxLeftPointLevel = float.MinValue;
            float maxRightPointLevel = float.MinValue;
            int currentPointIndex = 0;
            float[] waveformCompressedPoints = new float[waveformParams.Points];
            List<float> waveformData = new List<float>();
            List<int> waveMaxPointIndexes = new List<int>();

            for (int i = 1; i <= waveformParams.Points; i++)
            {
                waveMaxPointIndexes.Add((int)Math.Round(waveformLength * ((double)i / (double)waveformParams.Points), 0));
            }
            int readCount = 0;
            while (currentPointIndex * 2 < waveformParams.Points)
            {
                waveformInputStream.Read(readBuffer, 0, readBuffer.Length);

                waveformData.Add(waveformAggregator.LeftMaxVolume);
                waveformData.Add(waveformAggregator.RightMaxVolume);

                if (waveformAggregator.LeftMaxVolume > maxLeftPointLevel)
                    maxLeftPointLevel = waveformAggregator.LeftMaxVolume;
                if (waveformAggregator.RightMaxVolume > maxRightPointLevel)
                    maxRightPointLevel = waveformAggregator.RightMaxVolume;

                if (readCount > waveMaxPointIndexes[currentPointIndex])
                {
                    waveformCompressedPoints[(currentPointIndex * 2)] = maxLeftPointLevel;
                    waveformCompressedPoints[(currentPointIndex * 2) + 1] = maxRightPointLevel;
                    maxLeftPointLevel = float.MinValue;
                    maxRightPointLevel = float.MinValue;
                    currentPointIndex++;
                }
                if (readCount % 3000 == 0)
                {
                    float[] clonedData = (float[])waveformCompressedPoints.Clone();

                    try
                    {
                        App.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            WaveformData = clonedData;
                        }));
                    }
                    catch (TaskCanceledException)
                    {
                        e.Cancel = true;
                        return;
                    }
                    
                }

                if (waveformGenerateWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                readCount++;
            }

            float[] finalClonedData = (float[])waveformCompressedPoints.Clone();

            // Don't cache half-finished waveforms (my CDJ-1000MK3s do this...)
            if (!waveformGenerateWorker.CancellationPending)
                waveformDataCache.Add(waveformParams.Path, finalClonedData);

            App.Current.Dispatcher.Invoke(new Action(() =>
            {
                fullLevelData = waveformData.ToArray();
                WaveformData = finalClonedData;
            }));
            waveformInputStream.Close();
            waveformInputStream.Dispose();
            waveformInputStream = null;
            waveformMp3Stream.Close();
            waveformMp3Stream.Dispose();
            waveformMp3Stream = null;
        }
开发者ID:rdingwall,项目名称:mixplanner,代码行数:98,代码来源:NAudioEngine.cs

示例4: WzSoundProperty

 /// <summary>
 /// Creates a WzSoundProperty with the specified name from a file
 /// </summary>
 /// <param name="name">The name of the property</param>
 /// <param name="file">The path to the sound file</param>
 public WzSoundProperty(string name, string file)
 {
     this.name = name;
     Mp3FileReader reader = new Mp3FileReader(file);
     this.len_ms = (int)((double)reader.Length * 1000d / (double)reader.WaveFormat.AverageBytesPerSecond);
     this.frequency = reader.WaveFormat.SampleRate;
     //this.bps = (byte)reader.WaveFormat.BitsPerSample;
     this.header = CreateHeader(this.frequency);
     reader.Dispose();
     this.mp3bytes = File.ReadAllBytes(file);
 }
开发者ID:johnnyeven,项目名称:hasuite,代码行数:16,代码来源:WzSoundProperty.cs

示例5: WzSoundProperty

 /// <summary>
 /// Creates a WzSoundProperty with the specified name from a file
 /// </summary>
 /// <param name="name">The name of the property</param>
 /// <param name="file">The path to the sound file</param>
 public WzSoundProperty(string name, string file)
 {
     this.name = name;
     Mp3FileReader reader = new Mp3FileReader(file);
     this.len_ms = (int)((double)reader.Length * 1000d / (double)reader.WaveFormat.AverageBytesPerSecond);
     this.channels = (short)reader.Mp3WaveFormat.Channels;
     this.frequency = reader.Mp3WaveFormat.SampleRate;
     this.byterate = reader.Mp3WaveFormat.AverageBytesPerSecond;
     this.extraSize = (short)reader.Mp3WaveFormat.ExtraSize;
     this.blockSize = (short)reader.Mp3WaveFormat.blockSize;
     RebuildHeader();
     reader.Dispose();
     this.mp3bytes = File.ReadAllBytes(file);
 }
开发者ID:tom3302,项目名称:MapleLib,代码行数:19,代码来源:WzSoundProperty.cs

示例6: worker_DoWork

        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Mp3FileReader reader = new Mp3FileReader(FileName);
            WaveChannel32 channel = new WaveChannel32(reader);
            channel.Sample += new EventHandler<SampleEventArgs>(channel_Sample);

            int points = 2000;

            int frameLength = (int)FFTDataSize.FFT2048;
            int frameCount = (int)((double)channel.Length / (double)frameLength);
            int waveformLength = frameCount * 2;
            byte[] readBuffer = new byte[frameLength];

            float maxLeftPointLevel = float.MinValue;
            float maxRightPointLevel = float.MinValue;
            int currentPointIndex = 0;
            float[] waveformCompressedPoints = new float[points];
            List<float> waveformData = new List<float>();
            List<int> waveMaxPointIndexes = new List<int>();

            for (int i = 1; i <= points; i++)
            {
                waveMaxPointIndexes.Add((int)Math.Round(waveformLength * ((double)i / (double)points), 0));
            }
            int readCount = 0;
            while (currentPointIndex * 2 < points)
            {
                channel.Read(readBuffer, 0, readBuffer.Length);

                waveformData.Add(InputSampler.LeftMax);
                waveformData.Add(InputSampler.RightMax);

                if (InputSampler.LeftMax > maxLeftPointLevel)
                    maxLeftPointLevel = InputSampler.LeftMax;
                if (InputSampler.RightMax > maxRightPointLevel)
                    maxRightPointLevel = InputSampler.RightMax;

                if (readCount > waveMaxPointIndexes[currentPointIndex])
                {
                    waveformCompressedPoints[(currentPointIndex * 2)] = maxLeftPointLevel;
                    waveformCompressedPoints[(currentPointIndex * 2) + 1] = maxRightPointLevel;
                    maxLeftPointLevel = float.MinValue;
                    maxRightPointLevel = float.MinValue;
                    currentPointIndex++;
                }
                if (readCount % 3000 == 0)
                {
                    WaveformData = (float[])waveformCompressedPoints.Clone();
                }

                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                readCount++;
            }

            FullLevelData = waveformData.ToArray();
            WaveformData = (float[])waveformCompressedPoints.Clone();

            // Cleanup
            channel.Close();
            channel.Dispose();
            channel = null;
            reader.Close();
            reader.Dispose();
            reader = null;
        }
开发者ID:pbeardshear,项目名称:TempoMonkey,代码行数:69,代码来源:WaveformTimeline.cs

示例7: Mp3ToWav

 public static void Mp3ToWav(string mp3File, string outputFile)
 {
     using (Mp3FileReader reader = new Mp3FileReader(mp3File))
     {
         CreateWaveFile2(outputFile, reader);
         reader.Dispose();
     }
 }
开发者ID:Qder,项目名称:MusicEditor,代码行数:8,代码来源:WavFileUtils.cs

示例8: playSong

        protected override void playSong()
        {
            try {

                currentSong = nextSong;
                if (currentSong == null) {

                    currentSong = getNextSong();
                    if (currentSong == null) {
                        MessageBox.Show("No songs to play.");
                        return;
                    }
                }

                if (fileReader != null)
                    fileReader.Dispose();
                fileReader = new Mp3FileReader(currentSong.filepath);

            } catch (Exception) {
                MessageBox.Show("Error reading " + currentSong + ".\n" +
                    "File does not exist or cannot be read.");
                if (fileReader != null)
                    fileReader.Dispose();
                loadNextSong(null, null);
                return;
            }

            startGUIThread();

            waveChannel = new WaveChannel32(fileReader, 1, panSlider.Pan);
            waveChannel.PadWithZeroes = false;

            SampleChannel sampleChannel = new SampleChannel(waveChannel);
            sampleChannel.PreVolumeMeter += onPreVolumeMeter;
            volumeDelegate = (vol) => sampleChannel.Volume = vol;
            volumeDelegate(absoluteVolume * mixedVolume);

            //Debug.WriteLine("absoluteVolume: " + absoluteVolume + " mixedVolume: " + mixedVolume);
            //Debug.WriteLine("absoluteVolume * mixedVolume = " + absoluteVolume * mixedVolume);

            postVolumeMeter = new MeteringSampleProvider(sampleChannel);
            postVolumeMeter.StreamVolume += onPostVolumeMeter;

            deviceOut.Init(postVolumeMeter);
            deviceOut.Play();

            label_EndTime.Text = String.Format("{0:00}:{1:00}",
                        (int)fileReader.TotalTime.TotalMinutes,
                        fileReader.TotalTime.Seconds);

            label_SongTitle.Text = currentSong.ToString();
        }
开发者ID:TheDizzler,项目名称:DJMixer,代码行数:52,代码来源:Player.cs


注:本文中的NAudio.Wave.Mp3FileReader.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。