本文整理汇总了C#中IWaveProvider.Read方法的典型用法代码示例。如果您正苦于以下问题:C# IWaveProvider.Read方法的具体用法?C# IWaveProvider.Read怎么用?C# IWaveProvider.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWaveProvider
的用法示例。
在下文中一共展示了IWaveProvider.Read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadNextChunk
public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
{
int sourceBytesRequired = samplePairsRequired * 6;
sourceBuffer = GetSourceBuffer(sourceBytesRequired);
sourceBytes = source.Read(sourceBuffer, 0, sourceBytesRequired);
offset = 0;
}
示例2: LoadNextChunk
public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
{
int sourceBytesRequired = samplePairsRequired;
sourceBuffer = BufferHelpers.Ensure(sourceBuffer, sourceBytesRequired);
sourceBytes = source.Read(sourceBuffer, 0, sourceBytesRequired);
offset = 0;
}
示例3: LoadNextChunk
public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
{
int sourceBytesRequired = samplePairsRequired * 2;
sourceSample = 0;
sourceBuffer = BufferHelpers.Ensure(sourceBuffer, sourceBytesRequired);
sourceWaveBuffer = new WaveBuffer(sourceBuffer);
sourceSamples = source.Read(sourceBuffer, 0, sourceBytesRequired) / 2;
}
示例4: LoadNextChunk
public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
{
int sourceBytesRequired = samplePairsRequired * 4;
sourceBuffer = GetSourceBuffer(sourceBytesRequired);
sourceWaveBuffer = new WaveBuffer(sourceBuffer);
sourceSamples = source.Read(sourceBuffer, 0, sourceBytesRequired) / 2;
sourceSample = 0;
}
示例5: CreateWaveFile
/// <summary>
/// Creates a Wave 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 Wave File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
{
using (WaveFileWriter writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
{
byte[] buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
writer.Write(buffer, 0, bytesRead);
}
}
}
示例6: CreateWaveFile
/// <summary>
/// Creates a Wave 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 Wave File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
{
using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
{
var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
// Write will throw exception if WAV file becomes too large
writer.Write(buffer, 0, bytesRead);
}
}
}
示例7: AppendWaveFile
public static void AppendWaveFile(string filename, IWaveProvider sourceProvider)
{
using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat, FileMode.Append))
{
long outputLength = 0;
var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
outputLength += bytesRead;
if (outputLength > Int32.MaxValue)
{
throw new InvalidOperationException("WAV File cannot be greater than 2GB. Check that sourceProvider is not an endless stream.");
}
writer.Write(buffer, 0, bytesRead);
}
}
}
示例8: CreateWaveFileAsync
/// <summary>
/// Creates a Wave 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 Wave File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static async Task CreateWaveFileAsync(string filename, IWaveProvider sourceProvider)
{
StorageFile fileOperation = await StorageFile.GetFileFromPathAsync(filename);
Stream fileStream = await fileOperation.OpenStreamForWriteAsync();
using (var writer = new WaveFileWriterRT(fileStream, sourceProvider.WaveFormat))
{
writer.filename = filename;
long outputLength = 0;
var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
outputLength += bytesRead;
// Write will throw exception if WAV file becomes too large
writer.Write(buffer, 0, bytesRead);
}
}
}
示例9: CreateWaveFile
internal static void CreateWaveFile(string filename, IWaveProvider sourceProvider, Action<long> progressCallback)
{
Debug.Assert(progressCallback != null);
using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
{
long outputLength = 0;
var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
outputLength += bytesRead;
// Write will throw exception if WAV file becomes too large
writer.Write(buffer, 0, bytesRead);
progressCallback(bytesRead);
}
}
}
示例10: FillBuffer
private void FillBuffer(IWaveProvider playbackProvider, int frameCount)
{
IntPtr buffer = renderClient.GetBuffer(frameCount);
int readLength = frameCount*bytesPerFrame;
int read = playbackProvider.Read(readBuffer, 0, readLength);
if (read == 0)
{
playbackState = PlaybackState.Stopped;
}
Marshal.Copy(readBuffer, 0, buffer, read);
int actualFrameCount = read/bytesPerFrame;
/*if (actualFrameCount != frameCount)
{
Debug.WriteLine(String.Format("WASAPI wanted {0} frames, supplied {1}", frameCount, actualFrameCount ));
}*/
renderClient.ReleaseBuffer(actualFrameCount, AudioClientBufferFlags.None);
}
示例11: ConvertOneBuffer
private long ConvertOneBuffer(IMFSinkWriter writer, int streamIndex, IWaveProvider inputProvider, long position, byte[] managedBuffer)
{
long durationConverted = 0;
int maxLength;
IMFMediaBuffer buffer = MediaFoundationApi.CreateMemoryBuffer(managedBuffer.Length);
buffer.GetMaxLength(out maxLength);
IMFSample sample = MediaFoundationApi.CreateSample();
sample.AddBuffer(buffer);
IntPtr ptr;
int currentLength;
buffer.Lock(out ptr, out maxLength, out currentLength);
int read = inputProvider.Read(managedBuffer, 0, maxLength);
if (read > 0)
{
durationConverted = BytesToNsPosition(read, inputProvider.WaveFormat);
Marshal.Copy(managedBuffer, 0, ptr, read);
buffer.SetCurrentLength(read);
buffer.Unlock();
sample.SetSampleTime(position);
sample.SetSampleDuration(durationConverted);
writer.WriteSample(streamIndex, sample);
//writer.Flush(streamIndex);
}
else
{
buffer.Unlock();
}
Marshal.ReleaseComObject(sample);
Marshal.ReleaseComObject(buffer);
return durationConverted;
}
示例12: CreateRepositionTestFile
private void CreateRepositionTestFile(string saveFile, IWaveProvider source, Action reposition)
{
using (var writer = new WaveFileWriter(saveFile, source.WaveFormat))
{
// half-second buffer
var buffer = new byte[writer.WaveFormat.AverageBytesPerSecond / 2];
// read three and a half seconds (half a second is to ensure Resampler has some leftovers to drain)
for (int n = 0; n < 7; n++)
{
var read = source.Read(buffer, 0, buffer.Length);
writer.Write(buffer, 0, read);
}
Array.Clear(buffer, 0, buffer.Length);
// two seconds of absolute silence
for (int n = 0; n < 4; n++)
{
writer.Write(buffer, 0, buffer.Length);
}
// do the reposition
reposition();
// now read some more out
for (int n = 0; n < 6; n++)
{
var read = source.Read(buffer, 0, buffer.Length);
writer.Write(buffer, 0, read);
}
}
}