private void updateBuffer(object o)
{
for (int i = 0; i < _BufferLength; i++)
{
if (x >= _BitLength)
{
if (_currentTransmission.Count != 0)
{
x = 0;
_currentTransmission.RemoveAt(0);
}
}
else { x++; }
if (_currentTransmission.Count != 0)
{
// We are in the middle of a transmission: there is data to transmit
if (_currentTransmission[0]) { _amplitude = highVolume; } else { _amplitude = lowVolume; }
}
else if (_nextTransmission.Count != 0)
{
// There is no current transmission, but there is data waiting to be transmitted.
_currentTransmission = new List<bool>(_nextTransmission);
_nextTransmission.Clear();
_amplitude = lowVolume;
x = 0;
}else{
// There is no data to transmit at all. Shame. Real Shame.
_amplitude = lowVolume;
x = 0;
}
_FloatBuffer[i] = _amplitude * Math.Sin(Math.PI * _Phase * 2.0d);
_Phase += _timechange;
}
for (int i = 0; i < _BufferLength; i++)
{
short samp = (short)(_FloatBuffer[i] * short.MaxValue);
_ByteBuffer[i * 2 + 0] = (byte)(samp & 0xFF);
_ByteBuffer[i * 2 + 1] = (byte)(samp >> 8);
}
_dynamicSound.SubmitBuffer(_ByteBuffer);
}