本文整理汇总了C#中NAudio.Wave.Mp3FileReader类的典型用法代码示例。如果您正苦于以下问题:C# Mp3FileReader类的具体用法?C# Mp3FileReader怎么用?C# Mp3FileReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Mp3FileReader类属于NAudio.Wave命名空间,在下文中一共展示了Mp3FileReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestSpeed
public TestSpeed()
{
//WaveStream str1 = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\guitar1.mp3");
//WaveStream str2 = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\molecules.mp3");
//WaveMixerStream32 mix = new WaveMixerStream32(new [] {str1, str2}, false);
var mp3Filename = @"C:\WS\jmerde\trunk\_VisualStudio\AudioBooker\IlyaFranker\Content\snd\ilyafrank_open.mp3";
WavComposite writer = new WavComposite("../../wawa.wav");
writer.AppendAllOfFile(mp3Filename, null);
writer.AppendAllOfFile(mp3Filename, 2);
writer.AppendAllOfFile(mp3Filename, 0.5);
writer.Close();
//format = readerWave.WaveFormat;
//writer = new WaveFileWriter(destFilename, format);
//var wave = new Mp3FileReader(mp3Filename);
using (var reader = new Mp3FileReader(mp3Filename))
using (var pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
using (var downsampledStream = new WaveFormatConversionStream(new WaveFormat(
(int)(pcmStream.WaveFormat.SampleRate * 1.5),
reader.WaveFormat.BitsPerSample,
reader.WaveFormat.Channels), pcmStream))
{
WaveFileWriter.CreateWaveFile("../../xello.wav", downsampledStream);
}
}
开发者ID:miktemk,项目名称:AudioBooker,代码行数:30,代码来源:TestSpeed.cs
示例2: 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
示例3: Encode
public byte[] Encode()
{
int ms = 20;
int channels = 2;
int sampleRate = 48000;
int blockSize = 48 * 2 * channels * ms; //the size per each frame to encode
byte[] buffer = new byte[blockSize]; //a nicely sized pcm buffer to work with.
var outFormat = new WaveFormat(sampleRate, 16, channels);
if(__filename.EndsWith(".mp3"))
{
using (var mp3Reader = new Mp3FileReader(__filename))
{
using (var resampler = new WaveFormatConversionStream(outFormat, mp3Reader))
{
int byteCount;
using (BinaryWriter bw = new BinaryWriter(new MemoryStream()))
{
while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
{
//now to encode
byte[] opusOutput = new byte[buffer.Length]; //extra bytes but that's okay
int opusEncoded = encoder.EncodeFrame(buffer, 0, opusOutput);
bw.Write((ushort)opusEncoded);
bw.Write(opusOutput, 0, opusEncoded);
}
MemoryStream baseStream = bw.BaseStream as MemoryStream;
return baseStream.ToArray();
}
}
}
}
return null;
}
开发者ID:Luigifan,项目名称:dca4net,代码行数:35,代码来源:DcaEncoder.cs
示例4: CanLoadAndReadVariousProblemMp3Files
public void CanLoadAndReadVariousProblemMp3Files()
{
string testDataFolder = @"C:\Users\Mark\Downloads\NAudio";
if (!Directory.Exists(testDataFolder))
{
Assert.Ignore("{0} not found", testDataFolder);
}
foreach (string file in Directory.GetFiles(testDataFolder, "*.mp3"))
{
string mp3File = Path.Combine(testDataFolder, file);
Debug.WriteLine(String.Format("Opening {0}", mp3File));
using (var reader = new Mp3FileReader(mp3File))
{
byte[] buffer = new byte[4096];
int bytesRead;
int total = 0;
do
{
bytesRead = reader.Read(buffer, 0, buffer.Length);
total += bytesRead;
} while (bytesRead > 0);
Debug.WriteLine(String.Format("Read {0} bytes", total));
}
}
}
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:25,代码来源:Mp3FileReaderTests.cs
示例5: CutFile
private static void CutFile(string sourceFile, int startSecond, int endSecond, string resultFile)
{
using (var reader = new Mp3FileReader(sourceFile))
{
FileStream writer = File.Create(resultFile);
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
var currentSecond = (int)reader.CurrentTime.TotalSeconds;
if (currentSecond >= startSecond && currentSecond <= endSecond)
{
writer.Write(frame.RawData, 0, frame.RawData.Length);
}
else
{
if (currentSecond > endSecond)
{
writer.Dispose();
break;
}
}
}
writer.Dispose();
}
}
开发者ID:tamerlan,项目名称:Mimimi,代码行数:28,代码来源:Program.cs
示例6: Play
public static Task Play(this Captcha captcha)
{
return Task.Run(() =>
{
using (MemoryStream memory = new MemoryStream(captcha.Data, false))
{
memory.Seek(0, SeekOrigin.Begin);
using (Mp3FileReader reader = new Mp3FileReader(memory))
using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(reader))
using (WaveStream stream = new BlockAlignReductionStream(pcm))
{
using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
{
waveOut.Init(stream);
waveOut.Play();
while (waveOut.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(100);
}
}
}
}
});
}
开发者ID:amacal,项目名称:ine,代码行数:26,代码来源:AudioExtensions.cs
示例7: GetFileLength
private static TimeSpan GetFileLength(string mp3Path)
{
using (var reader = new Mp3FileReader(mp3Path))
{
return reader.TotalTime;
}
}
开发者ID:tamerlan,项目名称:Mimimi,代码行数:7,代码来源:Program.cs
示例8: WavHeaderFromMp3
/// <summary>
/// Считывает данные о заголоке из MP3 файла
/// </summary>
public static NAudio.Wave.WaveFormat WavHeaderFromMp3(Stream Stream)
{
using (var reader = new NAudio.Wave.Mp3FileReader(Stream))
{
return reader.WaveFormat;
}
}
开发者ID:YaStark,项目名称:ShazamO,代码行数:10,代码来源:NAudioWrapper.cs
示例9: GetNextChunk
public double[][] GetNextChunk(int samplesDesired, Mp3FileReader fr, bool fullnormalize = false)
{
byte[] buffer = new byte[samplesDesired * 4];
short[] left = new short[samplesDesired];
//short[] right = new short[samplesDesired];
double[] leftd = new double[samplesDesired];
//double[] rightd = new double[samplesDesired];
int bytesRead = 0;
try
{
bytesRead = fr.Read(buffer, 0, 4 * samplesDesired);
}
catch
{
new Exception("An error occurred while reading file");
}
int index = 0;
for (int sample = 0; sample < bytesRead / 4; sample++)
{
left[sample] = BitConverter.ToInt16(buffer, index); index += 2;
//right[sample] = BitConverter.ToInt16(buffer, index);
index += 2;
}
if (fullnormalize)
leftd = Utilities.NormalizeFull(ref left, left.Length);
else
leftd = Utilities.Normalize(ref left, left.Length);
return new double[][] { leftd, null }; //rightd };
}
开发者ID:johnnybuggy,项目名称:HOLO1,代码行数:34,代码来源:SoundReader.cs
示例10: Mp3ToWav
public static void Mp3ToWav(string mp3File, string outputFile)
{
using (Mp3FileReader reader = new Mp3FileReader(mp3File))
{
WaveFileWriter.CreateWaveFile(outputFile, reader);
}
}
开发者ID:AwesomeMusicGame,项目名称:MasterGame,代码行数:7,代码来源:MusicPlayer.cs
示例11: AudioPlayer
public AudioPlayer(Resource resource, TabPage tab)
{
var soundData = (Sound)resource.Blocks[BlockType.DATA];
var stream = soundData.GetSoundStream();
waveOut = new WaveOutEvent();
if (soundData.Type == Sound.AudioFileType.WAV)
{
var rawSource = new WaveFileReader(stream);
waveOut.Init(rawSource);
}
else if (soundData.Type == Sound.AudioFileType.MP3)
{
var rawSource = new Mp3FileReader(stream);
waveOut.Init(rawSource);
}
playButton = new Button();
playButton.Text = "Play";
playButton.TabIndex = 1;
playButton.Size = new Size(100, 25);
playButton.Click += PlayButton_Click;
tab.Controls.Add(playButton);
}
开发者ID:SteamDatabase,项目名称:ValveResourceFormat,代码行数:26,代码来源:AudioPlayer.cs
示例12: FileSelected
protected void FileSelected(string path)
{
fileBrowser = null;
if (path != null)
{
Debug.Log(path);
if(path.Contains(".mp3"))
{
Debug.Log(path);
using (Mp3FileReader reader = new Mp3FileReader(path))
{
Debug.Log("Reached");
path = path.Replace(".mp3", ".wav");
WaveFileWriter.CreateWaveFile(path , reader);
}
}
path = "file://" + path;
WWW wtf = new WWW(path);
//Wait for wtf to finish
while (!wtf.isDone)
{
}
SceneManager.getInstance.setClip(wtf.GetAudioClip(false));
}
}
开发者ID:NickCellino,项目名称:RiftMusicVisualizer,代码行数:27,代码来源:UIManagerScript.cs
示例13: PlayMP3
public bool PlayMP3(string fileName)
{
if (fileName == null) { return false; }
if (fileName.StartsWith("http")) {
return StreamMP3(fileName);
}
speaking = true;
WSRConfig.GetInstance().logInfo("PLAYER", "Start MP3 Player");
using (var ms = File.OpenRead(fileName))
using (var mp3Reader = new Mp3FileReader(ms))
using (var pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader))
using (var baStream = new BlockAlignReductionStream(pcmStream))
using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) {
waveOut.Init(baStream);
waveOut.Play();
played.Add(fileName);
while (baStream.CurrentTime < baStream.TotalTime && played.Contains(fileName)) {
Thread.Sleep(100);
}
played.Remove(fileName);
waveOut.Stop();
}
WSRConfig.GetInstance().logInfo("PLAYER", "End MP3 Player");
speaking = false;
return true;
}
开发者ID:Oniric75,项目名称:WSRMacro,代码行数:29,代码来源:WSRSpeaker.cs
示例14: Describe
public string Describe(string fileName)
{
var stringBuilder = new StringBuilder();
using (var reader = new Mp3FileReader(fileName))
{
Mp3WaveFormat wf = reader.Mp3WaveFormat;
stringBuilder.AppendFormat("MP3 File WaveFormat: {0} {1}Hz {2} channels {3} bits per sample\r\n",
wf.Encoding, wf.SampleRate,
wf.Channels, wf.BitsPerSample);
stringBuilder.AppendFormat("Extra Size: {0} Block Align: {1} Average Bytes Per Second: {2}\r\n",
wf.ExtraSize, wf.BlockAlign,
wf.AverageBytesPerSecond);
stringBuilder.AppendFormat("ID: {0} Flags: {1} Block Size: {2} Frames per Block: {3}\r\n",
wf.id, wf.flags, wf.blockSize, wf.framesPerBlock
);
stringBuilder.AppendFormat("Length: {0} bytes: {1} \r\n", reader.Length, reader.TotalTime);
stringBuilder.AppendFormat("ID3v1 Tag: {0}\r\n", reader.Id3v1Tag == null ? "None" : reader.Id3v1Tag.ToString());
stringBuilder.AppendFormat("ID3v2 Tag: {0}\r\n", reader.Id3v2Tag == null ? "None" : reader.Id3v2Tag.ToString());
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
stringBuilder.AppendFormat("{0},{1},{2}Hz,{3},{4}bps, length {5}\r\n",
frame.MpegVersion, frame.MpegLayer,
frame.SampleRate, frame.ChannelMode,
frame.BitRate, frame.FrameLength);
}
}
return stringBuilder.ToString();
}
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:30,代码来源:Mp3FileInspector.cs
示例15: SoundResource
public SoundResource(ResourceManager mgr, string fullName, Stream stream, Format fmt)
{
_manager = mgr;
FullName = fullName;
switch (fmt)
{
case Format.MP3:
{
Mp3FileReader mp3 = new Mp3FileReader(stream);
_reader = mp3;
break;
}
case Format.WAV:
{
WaveFileReader wav = new WaveFileReader(stream);
_reader = wav;
break;
}
default:
throw new InvalidOperationException("Unsupported extension.");
}
_stream = new WaveChannel32(_reader);
_stream.PadWithZeroes = false;
_wavDevice.PlaybackStopped += _wavDevice_PlaybackStopped;
}
开发者ID:Veggie13,项目名称:Genesis,代码行数:28,代码来源:SoundResource.cs
示例16: DataFromMp3
/// <summary>
/// Асинхронно считывает данные из MP3 файла в массив; верхний индекс - номер канала, нижний - номер сэмпла
/// </summary>
public static async Task<int[][]> DataFromMp3(Stream Stream)
{
using (var reader = new NAudio.Wave.Mp3FileReader(Stream))
{
return await Task<int[][]>.Factory.StartNew(() => _readMp3(reader));
}
}
开发者ID:YaStark,项目名称:ShazamO,代码行数:10,代码来源:NAudioWrapper.cs
示例17: TestMix
public TestMix()
{
//WaveStream str1 = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\guitar1.mp3");
//WaveStream str2 = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\molecules.mp3");
//WaveMixerStream32 mix = new WaveMixerStream32(new [] {str1, str2}, false);
var background = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\ferriss.mp3");
var message = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\guitar1.mp3");
var mixer = new WaveMixerStream32();
mixer.AutoStop = true;
var messageOffset = background.TotalTime;
var messageOffsetted = new WaveOffsetStream(message, TimeSpan.FromSeconds(1.5), TimeSpan.Zero, message.TotalTime.Subtract(TimeSpan.FromSeconds(1)));
var background32 = new WaveChannel32(background);
background32.PadWithZeroes = false;
background32.Volume = 0.9f;
var message32 = new WaveChannel32(messageOffsetted);
message32.PadWithZeroes = false;
message32.Volume = 0.7f;
var s1 = new RawSourceWaveStream(background32, new WaveFormat(8000, 16, 1));
var s2 = new RawSourceWaveStream(message32, new WaveFormat(8000, 16, 1));
WaveFormat targetFormat = WaveFormat.CreateIeeeFloatWaveFormat(128, 2);
var ss1 = new WaveFormatConversionStream(targetFormat, background32);
//var c = new WaveFormatConversionStream(WaveFormat.CreateALawFormat(8000, 1), background32);
//var stream_background32 = new WaveFormatConversionStream(new WaveFormat(256, 32, 2), background32);
//var stream_message32 = new WaveFormatConversionStream(new WaveFormat(256, 32, 2), message32);
mixer.AddInputStream(s1);
mixer.AddInputStream(s2);
WaveFileWriter.CreateWaveFile("mycomposed.wav", new Wave32To16Stream(mixer));
}
开发者ID:miktemk,项目名称:AudioBooker,代码行数:35,代码来源:TestMix.cs
示例18: mp3Processor
public mp3Processor(string file)
{
buf = new byte[maxLen];
WaveStream mp3Reader = new Mp3FileReader(file);
int read = mp3Reader.Read(buf, 0, buf.Length);
len = read;
}
开发者ID:vlad7777,项目名称:Music-Recognition,代码行数:8,代码来源:mp3Processor.cs
示例19: mp3ToWav
//If necessary, convert mp3 to wav - avoid Unity file stream restrictions
private static void mp3ToWav(string mp3path, string outputPath)
{
using (Mp3FileReader reader = new Mp3FileReader(mp3path)) {
using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)) {
WaveFileWriter.CreateWaveFile(outputPath, pcmStream);
}
}
}
开发者ID:robideau,项目名称:MusicShelf,代码行数:9,代码来源:InitAudio.cs
示例20: OpenMp3Stream
private static WaveChannel32 OpenMp3Stream(string fileName)
{
WaveChannel32 inputStream;
WaveStream mp3Reader = new Mp3FileReader(fileName);
WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader);
WaveStream blockAlignedStream = new BlockAlignReductionStream(pcmStream);
inputStream = new WaveChannel32(blockAlignedStream);
return inputStream;
}
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:9,代码来源:AudioPlayback.cs
注:本文中的NAudio.Wave.Mp3FileReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论