Closed ziriax closed 8 years ago
float
referes to IeeeFloat 32bit. In CSCore, PCM samples aren't expressed as floating point values.
Sorry, let me refine my question.
Why is the sample
argument scaled when BitsPerSample
is 8 or 24, but not when it is 16?
For 8-bit, sample
is mapped from [0..1] to [0..0xFF]
For 24-bit, sample
is mapped from [0..1] to [0..2147483648.0] (also strange, I would expect a mapping to [0..0xFFFFFF]
But for 16-bit, sample
is not mapped at all
Furthermore, it seems that Pcm16BitToSample
does scale when reading back to float:
buffer[index] = (float) BitConverter.ToInt16(this._buffer, startIndex) / 32768f;
Ahh I see. You were right. That was a mistake.
Thanks for fixing this! This might break existing code of course :)
One small thing, with your fix, the scaling is not symmetric, since now you multiply by short.MaxValue
= 32767
when writing, but divide by 32768f
when reading. Shouldn't that also be 32767f
?
Why is
WriteSample
not multiplying the sample when BitsPerSample is 16? Is this by design?