本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例7: Mp3ToWav
public static void Mp3ToWav(string mp3File, string outputFile)
{
using (Mp3FileReader reader = new Mp3FileReader(mp3File))
{
CreateWaveFile2(outputFile, reader);
reader.Dispose();
}
}
示例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();
}