本文整理汇总了C#中NAudio.Wave.WaveStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# WaveStream.Read方法的具体用法?C# WaveStream.Read怎么用?C# WaveStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.WaveStream
的用法示例。
在下文中一共展示了WaveStream.Read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
private static void Extract(Stream output, WaveStream waveStream, byte[] buffer)
{
if (waveStream == null)
return;
using (WaveFileWriter writer = new WaveFileWriter(output, waveStream.WaveFormat))
{
int count;
while ((count = waveStream.Read(buffer, 0, buffer.Length)) != 0)
writer.Write(buffer, 0, count);
}
}
示例2: CreateWaveFile
/// <summary>
/// Creates a Wave file by reading all the data from a WaveStream
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="stream">The source WaveStream</param>
public static void CreateWaveFile(string filename, WaveStream stream)
{
using (WaveFileWriter writer = new WaveFileWriter(filename, stream.WaveFormat))
{
byte[] buffer = new byte[stream.GetReadSize(4000)];
while (true)
{
int bytesRead = stream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
writer.WriteData(buffer, 0, bytesRead);
}
}
}
示例3: CreateAiffFile
/// <summary>
/// Creates an Aiff file by reading all the data from a WaveProvider
/// BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished,
/// or the Aiff File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static void CreateAiffFile(string filename, WaveStream sourceProvider)
{
using (var writer = new AiffFileWriter(filename, sourceProvider.WaveFormat))
{
byte[] buffer = new byte[16384];
while (sourceProvider.Position < sourceProvider.Length)
{
int count = Math.Min((int)(sourceProvider.Length - sourceProvider.Position), buffer.Length);
int bytesRead = sourceProvider.Read(buffer, 0, count);
if (bytesRead == 0)
{
// end of source provider
break;
}
writer.Write(buffer, 0, bytesRead);
}
}
}
示例4: Read
/// <summary>
/// Read an audio file.
/// </summary>
void Read()
{
#if WINDOWS
reader = new MediaFoundationReader(fileName);
duration = reader.TotalTime;
format = new AudioFormat(reader.WaveFormat);
var bytes = new byte[reader.Length];
var read = reader.Read(bytes, 0, bytes.Length);
data = new List<byte>(bytes);
#else
throw new NotImplementedException();
#endif
}
示例5: LoadStream
private int LoadStream(WaveStream waveStream) {
if (!isInitialized) {
Error("Trying to Load Stream format for uninitialized sound manager");
}
int channels, bits_per_sample, sample_rate;
byte[] sound_data = null;
for (int i = 0; i < managedSounds.Count; ++i) {
if (managedSounds[i].refCount <= 0) {
StopSound(managedSounds[i].bufferHandle);
AL.DeleteBuffer(managedSounds[i].bufferHandle);
managedSounds[i].bufferHandle = AL.GenBuffer();
managedSounds[i].refCount = 1;
sound_data = new byte[waveStream.Length];
waveStream.Read(sound_data, 0, (int)waveStream.Length);
channels = waveStream.WaveFormat.Channels;
bits_per_sample = waveStream.WaveFormat.BitsPerSample;
sample_rate = waveStream.WaveFormat.SampleRate;
AL.BufferData(managedSounds[i].bufferHandle, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate);
AL.Source(managedSounds[i].soundSource, ALSourcei.Buffer, managedSounds[i].bufferHandle);
return i;
}
}
SoundInstance newSound = new SoundInstance();
newSound.refCount = 1;
newSound.bufferHandle = AL.GenBuffer();
newSound.soundSource = AL.GenSource();
sound_data = new byte[waveStream.Length];
waveStream.Read(sound_data, 0, (int)waveStream.Length);
channels = waveStream.WaveFormat.Channels;
bits_per_sample = waveStream.WaveFormat.BitsPerSample;
sample_rate = waveStream.WaveFormat.SampleRate;
AL.BufferData(newSound.bufferHandle, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate);
AL.Source(newSound.soundSource, ALSourcei.Buffer, newSound.bufferHandle);
managedSounds.Add(newSound);
return managedSounds.Count - 1;
}
示例6: LoadAudio
public void LoadAudio(String filename)
{
try
{
waveStream = new NAudio.Wave.WaveFileReader(filename);
}
catch (Exception)
{
MessageBox.Show("Could not load Audio! WAV files only.");
return;
}
if (waveStream != null)
{
bytesPerSample = (waveStream.WaveFormat.BitsPerSample / 8) * waveStream.WaveFormat.Channels;
if (bytesPerSample == 0)
bytesPerSample = 1;
totalSamples = (int)(waveStream.Length / bytesPerSample);
// create a memory based copy so we can access internal data without moving position
MemoryStream ms = new MemoryStream((int)waveStream.Length);
ms.Position = 0;
byte[] waveData = new byte[samplesPerPixel * bytesPerSample];
while (waveStream.Position < waveStream.Length)
{
int bytesRead = waveStream.Read(waveData, 0, samplesPerPixel * bytesPerSample);
ms.Write(waveData, 0, bytesRead);
}
memoryStream = ms;
waveStream = new RawSourceWaveStream(memoryStream, waveStream.WaveFormat);
FitToScreen();
}
else
Reset();
//Zoom(0, 100000);
}
示例7: Read
/// <summary>
/// Read an audio file.
/// </summary>
void Read()
{
reader = new MediaFoundationReader(fileName);
duration = reader.TotalTime;
format = new AudioFormat(reader.WaveFormat);
var bytes = new byte[reader.Length];
var read = reader.Read(bytes, 0, bytes.Length);
data = new List<byte>(bytes);
}
示例8: TryReadFloat
// Read Mono
public static bool TryReadFloat(WaveStream waveStream, out float sampleValue)
{
// 16 bit PCM data
sampleValue = 0f;
if (waveStream.WaveFormat.BitsPerSample == 16)
{
byte[] buffer = new byte[2];
int read = waveStream.Read(buffer, 0, buffer.Length);
if (read < buffer.Length)
return false;
sampleValue = (float)BitConverter.ToInt16(buffer, 0) / 32768f;
return true;
}
return false;
}
示例9: ProcessFile
private void ProcessFile(WaveStream reader)
{
int fileLength = (int)reader.Length;
byte[] buffer = new byte[fileLength];
reader.Read(buffer, 0, fileLength);
ProcessData(buffer, fileLength);
}