PCM samples are signed?
-
- Posts: 29
- Joined: Sun Nov 01, 2020 7:23 pm
- Location: United States
PCM samples are signed?
I was reading the VERA documentation and to me it was unclear whether the PCM sampler uses signed or unsigned samples. Thanks!
- StephenHorn
- Posts: 565
- Joined: Tue Apr 28, 2020 12:00 am
- Contact:
PCM samples are signed?
It's at the tail end of the official documentation:
Audio data formats
Audio data is two's complement signed. Depending on the selected mode the data needs to be written to the FIFO in the following order:
Mode | Order in which to write data to FIFO |
---|---|
8-bit mono | <mono sample> |
8-bit stereo | <left sample> <right sample> |
16-bit mono | <mono sample (7:0)> <mono sample (15:8)> |
16-bit stereo | <left sample (7:0)> <left sample (15:8)> <right sample (7:0)> <right sample (15:8)> |
Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
- StephenHorn
- Posts: 565
- Joined: Tue Apr 28, 2020 12:00 am
- Contact:
PCM samples are signed?
"Two's complement signed" means it's a signed integer. If the "two's complement" part is what's confusing, it's the same way that C and C++ represent their signed numbers.
To negate a value in two's complement, invert all the bits and then add 1 to the result.
So, for instance, 0x0001 is "1", to create "-1" you would invert all the bits (getting 0xFFFE) and then add 1 (getting 0xFFFF, which is "-1" in two's complement). Similarly, negating -1 starts by negating all the bits (getting 0x0000) and then adding 1 (getting 0x0001, which is "1" in two's complement).
Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
PCM samples are signed?
On 6/23/2021 at 2:07 AM, StephenHorn said:
"Two's complement signed" means it's a signed integer. If the "two's complement" part is what's confusing, it's the same way that C and C++ represent their signed numbers. ...
It's also what you will get from a 6502 assembler that supports computed values if you do, eg, "0-512".
Back in the 50s and 60s, there was a greater diversity of ways to represent negative values. The other signed representations used back in the day were one's complement, which is just inverting each bit (and which makes $FFFF the 16bit "negative zero") and signed magnitude, where one bit represents the sign and the rest is the absolute value.
One's complement is still found in some dedicated signal processing hardware, but two's complement basically took over starting for most purposes in the 70s and is what is assumed as "normal" today.
The 6502 is a bit funny in that it does subtraction as a one's complement machine would do ... invert all bits of the operand and add to the accumulator ... but by using "SEC" as the "clear borrow" instruction and "CLC" as the "set borrow'" instruction, it WORKS as a two's complement subtraction.