private
void
RecordCapturedData(Socket Client,EndPoint epServer )
{
byte
[] capturedata =
null
;
int
readpos = 0, capturepos = 0, locksize = 0;
capturebuffer.GetCurrentPosition(
out
capturepos,
out
readpos);
locksize = readpos - iBufferOffset;
if
(locksize == 0)
{
return
;
}
if
(locksize < 0)
{
locksize += iBufferSize;
}
capturedata = (
byte
[])capturebuffer.Read(iBufferOffset,
typeof
(
byte
), LockFlag.FromWriteCursor, locksize);
try
{
int
intSet = capturedata.Length;
GetVoiceData(intSet,capturedata);
if
(IsRecord)
{
mWriter.Write(capturedata, 0, capturedata.Length);
mSampleCount += capturedata.Length;
}
}
catch
{
}
iBufferOffset += capturedata.Length;
iBufferOffset %= iBufferSize;
}
/// <summary>
/// 从字节数组中获取音频数据,并进行播放
/// </summary>
/// <param name="intRecv">字节数组长度</param>
/// <param name="bytRecv">包含音频数据的字节数组</param>
public
void
GetVoiceData(
int
intRecv,
byte
[] bytRecv)
{
if
(intPosWrite + intRecv <= memstream.Capacity)
{
if
((intPosWrite - intPosPlay >= 0 && intPosWrite - intPosPlay < intNotifySize) || (intPosWrite - intPosPlay < 0 && intPosWrite - intPosPlay + memstream.Capacity < intNotifySize))
{
memstream.Write(bytRecv, 0, intRecv);
intPosWrite += intRecv;
}
else
if
(intPosWrite - intPosPlay >= 0)
{
buffDiscript.BufferBytes = intPosWrite - intPosPlay;
SecondaryBuffer sec =
new
SecondaryBuffer(buffDiscript, PlayDev);
memstream.Position = intPosPlay;
sec.Write(0, memstream, intPosWrite - intPosPlay, LockFlag.FromWriteCursor);
sec.Play(0, BufferPlayFlags.Default);
memstream.Position = intPosWrite;
intPosPlay = intPosWrite;
}
else
if
(intPosWrite - intPosPlay < 0)
{
buffDiscript.BufferBytes = intPosWrite - intPosPlay + memstream.Capacity;
SecondaryBuffer sec =
new
SecondaryBuffer(buffDiscript, PlayDev);
memstream.Position = intPosPlay;
sec.Write(0, memstream, memstream.Capacity - intPosPlay, LockFlag.FromWriteCursor);
memstream.Position = 0;
sec.Write(memstream.Capacity - intPosPlay, memstream, intPosWrite, LockFlag.FromWriteCursor);
sec.Play(0, BufferPlayFlags.Default);
memstream.Position = intPosWrite;
intPosPlay = intPosWrite;
}
}
else
{
int
irest = memstream.Capacity - intPosWrite;
memstream.Write(bytRecv, 0, irest);
memstream.Position = 0;
memstream.Write(bytRecv, irest, intRecv - irest);
intPosWrite = intRecv - irest;
}
}