本文整理汇总了C#中IWaveProvider类的典型用法代码示例。如果您正苦于以下问题:C# IWaveProvider类的具体用法?C# IWaveProvider怎么用?C# IWaveProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IWaveProvider类属于命名空间,在下文中一共展示了IWaveProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResamplerDmoStream
/// <summary>
/// WaveStream to resample using the DMO Resampler
/// </summary>
/// <param name="inputProvider">Input Stream</param>
/// <param name="outputFormat">Desired Output Format</param>
public ResamplerDmoStream(IWaveProvider inputProvider, WaveFormat outputFormat)
{
this.inputProvider = inputProvider;
this.inputStream = inputProvider as WaveStream;
this.outputFormat = outputFormat;
this.resampler = new Resampler();
if (!resampler.MediaObject.SupportsInputWaveFormat(0, inputProvider.WaveFormat))
{
throw new ArgumentException("Unsupported Input Stream format", "inputStream");
}
resampler.MediaObject.SetInputWaveFormat(0, inputProvider.WaveFormat);
if (!resampler.MediaObject.SupportsOutputWaveFormat(0, outputFormat))
{
throw new ArgumentException("Unsupported Output Stream format", "outputStream");
}
resampler.MediaObject.SetOutputWaveFormat(0, outputFormat);
if (inputStream != null)
{
position = InputToOutputPosition(inputStream.Position);
}
this.inputMediaBuffer = new MediaBuffer(inputProvider.WaveFormat.AverageBytesPerSecond);
this.outputBuffer = new DmoOutputDataBuffer(outputFormat.AverageBytesPerSecond);
}
示例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: AddInputStream
/// <summary>
/// Add a new input to the mixer
/// </summary>
/// <param name="waveProvider">The wave input to add</param>
public void AddInputStream(IWaveProvider waveProvider)
{
if (waveProvider.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
throw new ArgumentException("Must be IEEE floating point", "waveProvider.WaveFormat");
if (waveProvider.WaveFormat.BitsPerSample != 32)
throw new ArgumentException("Only 32 bit audio currently supported", "waveProvider.WaveFormat");
if (inputs.Count == 0)
{
// first one - set the format
int sampleRate = waveProvider.WaveFormat.SampleRate;
int channels = waveProvider.WaveFormat.Channels;
this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channels);
}
else
{
if (!waveProvider.WaveFormat.Equals(waveFormat))
throw new ArgumentException("All incoming channels must have the same format", "waveProvider.WaveFormat");
}
lock (inputs)
{
this.inputs.Add(waveProvider);
}
}
示例4: MediaFoundationTransform
/// <summary>
/// Constructs a new MediaFoundationTransform wrapper
/// Will read one second at a time
/// </summary>
/// <param name="sourceProvider">The source provider for input data to the transform</param>
/// <param name="outputFormat">The desired output format</param>
public MediaFoundationTransform(IWaveProvider sourceProvider, WaveFormat outputFormat)
{
this.outputWaveFormat = outputFormat;
this.sourceProvider = sourceProvider;
sourceBuffer = new byte[ComputeSourceBufferSize(sourceProvider)];
outputBuffer = new byte[ComputeOutputBufferSize(outputFormat)]; // we will grow this buffer if needed, but try to make something big enough
}
示例5: ConvertWaveProviderIntoSampleProvider
/// <summary>
/// Helper function to go from IWaveProvider to a SampleProvider
/// Must already be PCM or IEEE float
/// </summary>
/// <param name="waveProvider">The WaveProvider to convert</param>
/// <returns>A sample provider</returns>
public static ISampleProvider ConvertWaveProviderIntoSampleProvider(IWaveProvider waveProvider)
{
ISampleProvider sampleProvider;
if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
{
// go to float
if (waveProvider.WaveFormat.BitsPerSample == 8)
{
sampleProvider = new Pcm8BitToSampleProvider(waveProvider);
}
else if (waveProvider.WaveFormat.BitsPerSample == 16)
{
sampleProvider = new Pcm16BitToSampleProvider(waveProvider);
}
else if (waveProvider.WaveFormat.BitsPerSample == 24)
{
sampleProvider = new Pcm24BitToSampleProvider(waveProvider);
}
else
{
throw new InvalidOperationException("Unsupported operation");
}
}
else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
{
sampleProvider = new WaveToSampleProvider(waveProvider);
}
else
{
throw new ArgumentException("Unsupported source encoding");
}
return sampleProvider;
}
示例6: RemoveInputStream
/// <summary>
/// Remove an input from the mixer
/// </summary>
/// <param name="waveProvider">waveProvider to remove</param>
public void RemoveInputStream(IWaveProvider waveProvider)
{
lock (inputs)
{
this.inputs.Remove(waveProvider);
}
}
示例7: AudioPlayer
public AudioPlayer(IWaveProvider provider)
{
_playbackDevice.Init(provider);
_playbackDevice.Play();
_playbackDevice.PlaybackStopped += (sender, args) => Console.WriteLine("Playback stopped: " + args.Exception);
}
示例8: Init
/// <summary>
/// Initialises the WaveOut device
/// </summary>
/// <param name="waveProvider">WaveProvider to play</param>
public void Init(IWaveProvider waveProvider)
{
if (playbackState != PlaybackState.Stopped)
{
throw new InvalidOperationException("Can't re-initialize during playback");
}
if (hWaveOut != IntPtr.Zero)
{
// normally we don't allow calling Init twice, but as experiment, see if we can clean up and go again
// try to allow reuse of this waveOut device
// n.b. risky if Playback thread has not exited
DisposeBuffers();
CloseWaveOut();
}
this.callbackEvent = new AutoResetEvent(false);
this.waveStream = waveProvider;
int bufferSize = waveProvider.WaveFormat.ConvertLatencyToByteSize((DesiredLatency + NumberOfBuffers - 1) / NumberOfBuffers);
MmResult result;
lock (waveOutLock)
{
result = WaveInterop.waveOutOpenWindow(out hWaveOut, (IntPtr)DeviceNumber, waveStream.WaveFormat, callbackEvent.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackEvent);
}
MmException.Try(result, "waveOutOpen");
buffers = new WaveOutBuffer[NumberOfBuffers];
playbackState = PlaybackState.Stopped;
for (int n = 0; n < NumberOfBuffers; n++)
{
buffers[n] = new WaveOutBuffer(hWaveOut, bufferSize, waveStream, waveOutLock);
}
}
示例9: Init
/// <summary>
/// Initialises the WaveOut device
/// </summary>
/// <param name="waveProvider">Wave provider to play</param>
public void Init(IWaveProvider waveProvider)
{
if (Thread.CurrentThread.ManagedThreadId != waveOutThread.ManagedThreadId)
{
lock (actionQueue)
{
actionQueue.Enqueue(new WaveOutAction(WaveOutFunction.Init, waveStream));
workAvailable.Set();
}
return;
}
waveStream = waveProvider;
int bufferSize = waveProvider.WaveFormat.ConvertLatencyToByteSize(desiredLatency);
//waveStream.GetReadSize((desiredLatency + 2) / 3);
numBuffers = 3;
MmException.Try(
WaveInterop.waveOutOpen(out hWaveOut, (IntPtr) devNumber, waveStream.WaveFormat, callback, IntPtr.Zero,
WaveInterop.CallbackFunction), "waveOutOpen");
buffers = new WaveOutBuffer[numBuffers];
playbackState = PlaybackState.Stopped;
var waveOutLock = new object();
for (int n = 0; n < numBuffers; n++)
{
buffers[n] = new WaveOutBuffer(hWaveOut, bufferSize, waveStream, waveOutLock);
}
}
示例10: Init
public Task Init(IWaveProvider waveProvider)
{
// do this still on the gui thread
mediaElement.SetSource(new WaveProviderRandomAccessStream(waveProvider), "audio/wav");
// must be a better way than this
return new Task(() =>{});
}
示例11: MediaFoundationTransform
/// <summary>
/// Constructs a new MediaFoundationTransform wrapper
/// Will read one second at a time
/// </summary>
/// <param name="sourceProvider">The source provider for input data to the transform</param>
/// <param name="outputFormat">The desired output format</param>
public MediaFoundationTransform(IWaveProvider sourceProvider, WaveFormat outputFormat)
{
this.outputWaveFormat = outputFormat;
this.sourceProvider = sourceProvider;
sourceBuffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond];
outputBuffer = new byte[outputWaveFormat.AverageBytesPerSecond + outputWaveFormat.BlockAlign]; // we will grow this buffer if needed, but try to make something big enough
}
示例12: LoadNextChunk
public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
{
int sourceBytesRequired = samplePairsRequired * 6;
sourceBuffer = GetSourceBuffer(sourceBytesRequired);
sourceBytes = source.Read(sourceBuffer, 0, sourceBytesRequired);
offset = 0;
}
示例13: VolumeWaveProvider16
public VolumeWaveProvider16(IWaveProvider sourceProvider)
{
this.sourceProvider = sourceProvider;
if (sourceProvider.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
throw new ArgumentException("Expecting PCM input");
if (sourceProvider.WaveFormat.BitsPerSample != 16)
throw new ArgumentException("Expecting 16 bit");
}
示例14: SingleChannelMuxProvider
public SingleChannelMuxProvider(IWaveProvider sourceProvider, int channelNum, int totalChannels)
{
_source = sourceProvider;
_channelNum = channelNum;
_totalChannels = totalChannels;
_bytesPerSample = sourceProvider.WaveFormat.BitsPerSample / 8;
_finalFormat = new WaveFormat(sourceProvider.WaveFormat.SampleRate, sourceProvider.WaveFormat.BitsPerSample, totalChannels);
}
示例15: 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;
}