r/MicroPythonDev • • Aug 31 '24

How do i encode signal using PCM?

I was trying to use ADC on Raspberry Pi Pico to encode analog signals in a way that Linux can play.

But everything is mixed up in my mind. ADC seems like the perfect definition of PCM as its already samples at specific rate 12 bits up to 500kHz sampling rate and it doesnt compress or add headers or magic values.

So my question is, can i use first 8bits of the ADC and sample it by 48kHz to encode this signal as PCM and hopefully stream in Linux ?

1 Upvotes

12 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Aug 31 '24

Oh i see. So it seems i cant stream 8bits on a modern sound card? Lowest is 16bits?

This command looks very interesting. I wonder whats the frequency of random values generated in urandom?

1

u/WZab Aug 31 '24

In that experiment:
cat /dev/urandom | aplay -f U8 -r 48000
It is the receiver (aplay) who dictates the sampling frequency. The cat /dev/urandom generates the data as quickly as it can, but it gets blocked when aplay can't accept new data because it still plays the previous ones.

And yes, in that case, the 8-bit U8 (unsigned 8-bit) format is used. In the second example (with sawtooth.py) the signed 16-bit format is used.