本文整理汇总了C#中NAudio.Wave.WaveStream类的典型用法代码示例。如果您正苦于以下问题:C# WaveStream类的具体用法?C# WaveStream怎么用?C# WaveStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WaveStream类属于NAudio.Wave命名空间,在下文中一共展示了WaveStream类的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: WaveFormatConversionStream
/// <summary>
/// Create a new WaveFormat conversion stream
/// </summary>
/// <param name="targetFormat">Desired output format</param>
/// <param name="sourceStream">Source stream</param>
public WaveFormatConversionStream(WaveFormat targetFormat, WaveStream sourceStream)
{
this.sourceStream = sourceStream;
this.targetFormat = targetFormat;
conversionProvider = new WaveFormatConversionProvider(targetFormat, sourceStream);
length = EstimateSourceToDest((int)sourceStream.Length);
position = 0;
}
示例3: Load
public bool Load(string path, Guid device)
{
var cext = path.GetExt();
_myWaveOut = new DirectSoundOut(device);
try
{
_myWaveStream = _codecs.First(v => v.Extensions.Contains(cext)).CreateWaveStream(path);
}
catch
{
return false;
}
if (_myWaveStream == null) return false;
if (_myWaveStream.WaveFormat.Channels == 2)
{
_myBalanceSampleProvider = new BalanceSampleProvider(_myWaveStream.ToSampleProvider());
_myVolumeSampleProvider = new VolumeSampleProvider(_myBalanceSampleProvider);
_myBalanceSampleProvider.Pan = (float)Balance;
}
else _myVolumeSampleProvider = new VolumeSampleProvider(_myWaveStream.ToSampleProvider());
_myEqualizer = new Equalizer(_myVolumeSampleProvider, _equalizerBands) { Enabled = _enableEqualizer };
_myWaveOut.Init(_myEqualizer);
_myWaveOut.PlaybackStopped += MyWaveOutOnPlaybackStopped;
_myVolumeSampleProvider.Volume = (float)Volume;
return true;
}
示例4: AddInputStream
/// <summary>
/// Add a new input to the mixer
/// </summary>
/// <param name="waveStream">The wave input to add</param>
public void AddInputStream(WaveStream waveStream)
{
if (waveStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
throw new ArgumentException("Must be IEEE floating point", "waveStream");
if (waveStream.WaveFormat.BitsPerSample != 32)
throw new ArgumentException("Only 32 bit audio currently supported", "waveStream");
if (inputStreams.Count == 0)
{
// first one - set the format
int sampleRate = waveStream.WaveFormat.SampleRate;
int channels = waveStream.WaveFormat.Channels;
this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channels);
}
else
{
if (!waveStream.WaveFormat.Equals(waveFormat))
throw new ArgumentException("All incoming channels must have the same format", "waveStream");
}
lock (inputsLock)
{
this.inputStreams.Add(waveStream);
this.length = Math.Max(this.length, waveStream.Length);
// get to the right point in this input file
waveStream.Position = Position;
}
}
示例5: WaveListenerProvider
public WaveListenerProvider(WaveStream sourceStream)
{
this.sourceStream = sourceStream;
waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sourceStream.WaveFormat.SampleRate, sourceStream.WaveFormat.Channels);
sampleAggregator.FftCalculated += new EventHandler<FftEventArgs>(FftCalculated);
sampleAggregator.PerformFFT = true;
}
示例6: MeteringStream
public MeteringStream(WaveStream sourceStream, int samplesPerNotification)
{
SourceStream = sourceStream;
if (sourceStream.WaveFormat.BitsPerSample != 32)
throw new ArgumentException("Metering Stream expects 32 bit floating point audio", "sourceStream");
maxSamples = new float[sourceStream.WaveFormat.Channels];
this.SamplesPerNotification = samplesPerNotification;
}
示例7: EffectStream
public EffectStream(EffectChain effects, WaveStream sourceStream)
{
this.effects = effects;
this.source = sourceStream;
foreach (Effect effect in effects)
{
InitialiseEffect(effect);
}
}
示例8: CreatePcmStream
/// <summary>
/// Creates a stream that can convert to PCM
/// </summary>
/// <param name="sourceStream">The source stream</param>
/// <returns>A PCM stream</returns>
public static WaveStream CreatePcmStream(WaveStream sourceStream)
{
if (sourceStream.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
{
return sourceStream;
}
WaveFormat pcmFormat = AcmStream.SuggestPcmFormat(sourceStream.WaveFormat);
return new WaveFormatConversionStream(pcmFormat, sourceStream);
}
示例9: PlaySong
public int PlaySong(string path)
{
int result = 0;
sync.InvokeIfRequired((Action)delegate
{
CleanPlayerAndStream();
result = -1;
if (!string.IsNullOrEmpty(path))
{
try
{
MakePlayerInternal();
stream = CreateStream(path);
player.Init(stream);
player.Play();
result = (int)(stream.Length / stream.WaveFormat.AverageBytesPerSecond);
}
catch (Exception)
{
CleanPlayerAndStream();
}
}
});
return result;
}
示例10: MainForm
public MainForm()
{
waveOutDevice = null;
mainOutputStream = null;
volumeStream = null;
InitializeComponent();
}
示例11: playWave
/// <summary>
/// Lejátszik egy .mp3 fájlt
/// </summary>
/// <param name="audioFile">.mp3 fájl</param>
public static void playWave(string audioFile)
{
thread = new WaveOut();
stream = CreateInputStream(audioFile);
thread.Init(stream);
thread.Play();
}
示例12: Initialize
private void Initialize()
{
var extension = Path.GetExtension(file).ToLowerInvariant();
if (extension.Equals(".wav"))
{
reader = new WaveFileReader(file);
}
else
{
reader = new Mp3FileReader(file);
}
var format = reader.WaveFormat;
this.sampleRate = format.SampleRate;
this.channels = format.Channels;
this.Format = new AudioProperties(format.SampleRate, format.BitsPerSample,
format.Channels, (int)reader.TotalTime.TotalSeconds);
if (format.BitsPerSample != 16)
{
Dispose(true);
}
}
示例13: NAudioDecoder
public NAudioDecoder(string file)
{
extension = Path.GetExtension(file).ToLowerInvariant();
ready = false;
if (extension.Equals(".wav"))
{
reader = new WaveFileReader(file);
}
else
{
reader = new Mp3FileReader(file);
}
var format = reader.WaveFormat;
bitsPerSample = format.BitsPerSample;
sampleRate = format.SampleRate;
channels = format.Channels;
duration = (int)reader.TotalTime.TotalSeconds;
ready = (format.BitsPerSample == 16);
}
示例14: 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;
}
示例15: CreateReaderStream
/// <summary>
/// Creates the reader stream, supporting all filetypes in the core NAudio library,
/// and ensuring we are in PCM format
/// </summary>
/// <param name="fileName">File Name</param>
private void CreateReaderStream(string fileName)
{
if (fileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
{
readerStream = new WaveFileReader(fileName);
if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm && readerStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
{
readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream);
readerStream = new BlockAlignReductionStream(readerStream);
}
}
else if (fileName.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase))
{
readerStream = new Mp3FileReader(fileName);
}
else if (fileName.EndsWith(".aiff"))
{
readerStream = new AiffFileReader(fileName);
}
else
{
// fall back to media foundation reader, see if that can play it
readerStream = new MediaFoundationReader(fileName);
}
}