add comment

This commit is contained in:
sim1222 2023-07-26 22:36:08 +09:00
parent 7995cdc5c5
commit c31cb93ec6

View File

@ -28,12 +28,12 @@ public class VolumeAdjustedWaveStream : WaveStream
var read = _waveStream.Read(buffer, offset, count);
try
{
for (var i = 0; i < read; i += 2)
for (var i = 0; i < read; i += 2) // 2 bytes per sample
{
var sample = (short) ((buffer[offset + i + 1] << 8) | buffer[offset + i]);
sample = (short) (sample * _volume);
buffer[offset + i] = (byte) (sample & 0xFF);
buffer[offset + i + 1] = (byte) (sample >> 8);
var sample = (short) ((buffer[offset + i + 1] << 8) | buffer[offset + i]); // convert two bytes to one short (little endian)
sample = (short) (sample * _volume); // <- anything between 0.0 and 1.0
buffer[offset + i] = (byte) (sample & 0xFF); // split the short into two bytes
buffer[offset + i + 1] = (byte) (sample >> 8); // see above
}
}
catch (Exception e)