代码拉取完成,页面将自动刷新
using System;
using NAudio.Wave;
namespace SkyJukebox.NAudioFramework
{
/// <summary>
/// Very simple sample provider supporting adjustable balance
/// </summary>
public class BalanceSampleProvider : ISampleProvider
{
private readonly ISampleProvider _source;
/// <summary>
/// Initializes a new instance of BalanceSampleProvider
/// </summary>
/// <param name="source">Source Sample Provider</param>
public BalanceSampleProvider(ISampleProvider source)
{
if (source.WaveFormat.Channels != 2)
throw new InvalidOperationException("Input wave format must be stereo!");
_source = source;
LeftVolume = 1.0f;
RightVolume = 1.0f;
}
/// <summary>
/// WaveFormat
/// </summary>
public WaveFormat WaveFormat
{
get { return _source.WaveFormat; }
}
/// <summary>
/// Reads samples from this sample provider
/// </summary>
/// <param name="buffer">Sample buffer</param>
/// <param name="offset">Offset into sample buffer</param>
/// <param name="sampleCount">Number of samples desired</param>
/// <returns>Number of samples read</returns>
public int Read(float[] buffer, int offset, int sampleCount)
{
int samplesRead;
try { samplesRead = _source.Read(buffer, offset, sampleCount); }
catch
{
return 0;
}
if (RightVolume == 1.0f && LeftVolume == 1.0f) return samplesRead;
for (int n = 0; n < sampleCount; n += 2)
{
buffer[offset + n] *= LeftVolume;
buffer[offset + n + 1] *= RightVolume;
}
return samplesRead;
}
/// <summary>
/// Allows adjusting the left channel volume
/// </summary>
public float LeftVolume { get; set; }
/// <summary>
/// Allows adjusting the right channel volume
/// </summary>
public float RightVolume { get; set; }
/// <summary>
/// Legacy feature. -1 to 1.
/// </summary>
public float Pan
{
set
{
if (value > 0) LeftVolume -= value;
else if (value < 0) RightVolume += value;
else LeftVolume = RightVolume = 1.0f;
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。