FT232RL USB Serial sound card hack

Did you know that you could play sound using an usb to uart/serial converter , by just using an FT232RL usbserial and an external speaker with amplifier?
Let’s take a look at the software side first, the basic idea is to send bytes purposedly crafted to create some sort of PWM.
So we have 8 bits each byte sent, which mean 8 levels, kinda crappy if you like hi-fi sound , but that’s not the purpose of this hack obviously.

So the easiest way is to send these bytes for each level

Level

Bits

-4

00000000

-3

10000000

-2

11000000

-1

11100000

0

11110000

1

11111000

2

11111100

3

11111110

4

11111111

A simple python script with pyserial can easily do it, by taking bytes from stdin coming from a raw mono s8 pcm file , to the usbserial

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

importserial

importstruct

importsys

importtime

ser=serial.Serial()

ser.baudrate=576000#By trial and error i found out this to be the best speed which does not give bad sound on the speaker

ser.port="/dev/ttyUSB0"

ser.parity="N"

ser.stopbits=1

ser.xonxoff=0

ser.bytesize=8

ser.open()

whileTrue:

buf=sys.stdin.read(1024)

iflen(buf)==0:

break

s=time.time()

data=""

forcinbuf:

val=struct.unpack("b",c)[0]# Convert the byte to a signed int8

val=4+(val/127.0)*4# Clamp it from -127,+127 to 0,8

val=int(val)#Convert it back to int to be able to do str*int

bstr="0"*(8-val)+"1"*val# Convert it to val ones and 8-val zeroes to obtain values in the above table

data+=chr(int(bstr,2))# Convert the bits , like "11100000" to the byte

The 58000 sample rate value is obtained experimentally by looking at the script output , to see how much bytes/sec are actually sent

To play it:

1

cat filename.raw|python2.7serialsound.py

Connect the GND pin of the serial converter to the ground of the amplifier cable, and the TX pin to the signal pin.

If you get strange interference because your amplifier is class D and it is not filtered, you need to add a lowpass filter with cutoff frequency of 22 Khz

Result:

Thanks to Valerio “Gurzo” Morgante ( latanadelgurzo.blogspot.it ) who was working on doing the opposite ( Emulating a serial port using a sound card ) and that gave me the idea of obtaining sound output using an inexpensive FT232RL usb-serial