本文整理汇总了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, );
}
}
示例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();
}
}
}
示例3: BuildWavePartAudio
private ISampleProvider BuildWavePartAudio(UWavePart part, UProject project)
{
AudioFileReader stream;
try { stream = new AudioFileReader(part.FilePath); }
catch { return null; }
return new WaveToSampleProvider(stream);
}
示例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();
}
}
}
示例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);
}
示例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();
}
}
}
示例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)
{
}
});
}
示例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);
}
示例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);
}
}
示例10: playnhac
private void playnhac()
{
IWavePlayer waveOutDevice;
AudioFileReader audioFileReader;
waveOutDevice = new WaveOut();
audioFileReader = new AudioFileReader("animal.mp3");
waveOutDevice.Init(audioFileReader);
waveOutDevice.Play();
}
示例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();
}
示例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>();
}
示例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();
}
示例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);
}
}
示例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);
}