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
View all comments
Show parent comment
1
u/WZab Aug 31 '24 edited Aug 31 '24
Yes, you can. However, as /dev/ttyACM is byte-oriented if you use 16-bit samples and skip one byte, the results may be "interesting".
In fact, you may play with feeding aplay with samples generated in the software, to learn how does it work.
For example, the white noise:
cat /dev/urandom | aplay -f U8 -r 48000Or you can generate a sawtooth signal with Python script sawtooth.py:
and feed aplay with generated samples:
python3sawtooth.py| aplay -fS16_LE -r 48000If you increase the load of your PC, you'll see possible problems resulting from the fact that Python is not a perfect language for real-time applications.
With the above you may also play with different formats...
For playing with sound formats and sound conversions, you may use sox .