本文整理汇总了C#中IAudioStream.ReadBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# IAudioStream.ReadBuffer方法的具体用法?C# IAudioStream.ReadBuffer怎么用?C# IAudioStream.ReadBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAudioStream
的用法示例。
在下文中一共展示了IAudioStream.ReadBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Flow
public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
{
var obufPos = 0;
var inPos = 0;
var oend = count;
while (obufPos < oend)
{
// read enough input samples so that opos < 0
while (FRAC_ONE_LOW <= opos)
{
// Check if we have to refill the buffer
if (inLen == 0)
{
inPos = 0;
inLen = input.ReadBuffer(inBuf, RateHelper.IntermediateBufferSize);
if (inLen <= 0)
return obufPos / 2;
}
inLen -= (stereo ? 2 : 1);
ilast0 = icur0;
icur0 = inBuf[inPos++];
if (stereo)
{
ilast1 = icur1;
icur1 = inBuf[inPos++];
}
opos -= FRAC_ONE_LOW;
}
// Loop as long as the outpos trails behind, and as long as there is
// still space in the output buffer.
while (opos < FRAC_ONE_LOW && obufPos < oend)
{
// interpolate
int out0, out1;
out0 = (short)(ilast0 + (((icur0 - ilast0) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW));
out1 = stereo ? (short)(ilast1 + (((icur1 - ilast1) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW)) : out0;
// output left channel
RateHelper.ClampedAdd(ref obuf[obufPos + (reverseStereo ? 1 : 0)], (out0 * volLeft) / Mixer.MaxMixerVolume);
// output right channel
RateHelper.ClampedAdd(ref obuf[obufPos + (reverseStereo ? 0 : 1)], (out1 * volRight) / Mixer.MaxMixerVolume);
obufPos += 2;
// Increment output position
opos += oposInc;
}
}
return obufPos / 2;
}
示例2: Flow
public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
{
Debug.Assert(input.IsStereo == stereo);
var osamp = count / 2;
if (stereo)
osamp *= 2;
// Reallocate temp buffer, if necessary
if (osamp > _bufferSize)
{
_buffer = new short[osamp];
_bufferSize = osamp;
}
// Read up to 'osamp' samples into our temporary buffer
var len = input.ReadBuffer(_buffer, _bufferSize);
int iPos = 0;
var oPos = 0;
var inc = stereo ? 2 : 1;
// Mix the data into the output buffer
for (; iPos < len; iPos += inc)
{
var out0 = _buffer[iPos];
var out1 = stereo ? _buffer[iPos + 1] : out0;
// output left channel
RateHelper.ClampedAdd(ref obuf[oPos + (reverseStereo ? 1 : 0)], (out0 * volLeft) / Mixer.MaxMixerVolume);
// output right channel
RateHelper.ClampedAdd(ref obuf[oPos + (reverseStereo ? 0 : 1)], (out1 * volRight) / Mixer.MaxMixerVolume);
oPos += 2;
}
return oPos / 2;
}
示例3: Flow
public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
{
int pos = 0;
int oend = count * 2;
while (pos < oend)
{
// read enough input samples so that opos >= 0
do
{
// Check if we have to refill the buffer
if (inLen == 0)
{
inPtr = 0;
inLen = input.ReadBuffer(inBuf, RateHelper.IntermediateBufferSize);
if (inLen <= 0)
return pos / 2;
}
inLen -= (stereo ? 2 : 1);
opos--;
if (opos >= 0)
{
inPtr += (stereo ? 2 : 1);
}
} while (opos >= 0);
short out0, out1;
out0 = inBuf[inPtr++];
out1 = (stereo ? inBuf[inPtr++] : out0);
// Increment output position
opos += oposInc;
// output left channel
RateHelper.ClampedAdd(ref obuf[reverseStereo ? 1 : 0], (out0 * (int)volLeft) / Mixer.MaxMixerVolume);
// output right channel
RateHelper.ClampedAdd(ref obuf[(reverseStereo ? 1 : 0) ^ 1], (out1 * (int)volRight) / Mixer.MaxMixerVolume);
pos += 2;
}
return pos / 2;
}