Page 1 of 1

PCM samples are signed?

Posted: Tue Jun 22, 2021 11:38 pm
by totodilespy

I was reading the VERA documentation and to me it was unclear whether the PCM sampler uses signed or unsigned samples. Thanks!


PCM samples are signed?

Posted: Wed Jun 23, 2021 6:01 am
by StephenHorn

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)>


PCM samples are signed?

Posted: Wed Jun 23, 2021 6:07 am
by StephenHorn

"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).


PCM samples are signed?

Posted: Sun Jan 09, 2022 5:27 pm
by BruceMcF


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.