Audio output from a serial port


Yes, it is possible to get sound output from a serial port. Sure, it sounds terrible, but what did you expect. [markrages] ttyplay program first resamples the WAV file to the baud rate of the serial port. It then uses Sigma-Delta modulation to encode the analog signal into a binary bitstream. You should really try this out. The picture above is from when I was testing it out since it only took a minute to grab the parts and a second to compile. Mark says audio quality could be improved by using a higher baudrate. There is a lot of noise though. Somebody want to put together a simple RC filter/amplifier; I can actually think of a project this might be useful for. Read more about ttyplay here.


  1. GitiUp4o9 says: this is for the parallel port, and i don’t know if it sounds any better.


  2. This is phenomenal! Kinda. I have tried on multiple occasions to communicate with a serial port. Granted, I was using PERL on a Windows machine, and was trying to manipulate the state of a servo controller, so the circumstances were a little different. I found that just about anything was abnormally difficult through the Win32::SerialPort interface (either that, or I was missing something).

    I will certainly be examining the source to this nifty lil’ project. It appears to be easier than I had imagined to do this kind of thing in C. I’m sure me and the termios.h header will become best of friends. :)

  3. Markrages says:


    The easiest way to do serial is Python’s PySerial module. It’s not hard at all.

    Originally, I just wrote the bytes to stdout and redirected them to /dev/ttyS0:

    ./prog > /dev/ttyS0

    But the audio kept skipping, so I figured I’d better set the port up myself.


    ps. who’s Mike?

  4. Ohde says:

    Wow, this is heavy nostalgia for me. I remember having a similar commercial-built device hooked up to my parallel port about eleven years ago, playing sound with just about the same quality.

  5. Tired says:

    This is pretty cool. It could be used to play an audio file stored on an eeprom out the serial ports of a microcontroller. Could be very useful, the chips to play wav/mp3 files can be kindof expensive if I remember right… this might offer a low cost alternative.


  6. Bruce Walker says:

    Nostalgia all right: I remember even having serial ports.
    (Mac owner. :-)

  7. A2E says:

    This reminds me of a website I found for doing serial audio out on a PIC:

    I am going to try this on my PIC based robot.

  8. Damnit, that’s the third time I’ve misspelled someones name in the last week. I’ve gotta stop writing these things at 5 am.

  9. Paul says:

    I remember doing something similar for a 6809 programming course. We had these boxes with a 1 bit output connected to a speaker. The project was to make the speaker sound a siren when the ‘fire alarm’ was triggered. I made mine talk :-)

  10. disasteradio says:

    woah, I’m smellin’ another sweet way to crustify those synth tracks!

  11. shavenwarthog says:

    linked page croaked, but the software and documentation is still available:

  12. DarkFader says:

    An RC filter and amplifier is definately required. Serial port probably won’t like it if you hook up your headphones.
    And doesn’t sigma-delta modulation require an integrator? Perhaps they meant DPWM? (discontinuous PWM, dithering PWM, digital PWM)

  13. opg says:

    HEY! I was looking for something very similar to this yesterday! So, you know how you can do the same thing with the cassette jack on an Apple IIe? Well, how can you do this on a Tandy 102 laptop? The cassette output uses a DIN-5 jack and a cable that connects from that to a regular tape recorder with a 1/8″ jack.

    And another thing: the DIN-5 jack is the same as a MIDI cable (same pinouts, too). How can I get the Tandy to send MIDI data this way?

  14. markrages says:

    the site’s back up, but coral cache hasn’t caught on yet. Click on my name for the direct link.

    darkfader, the integrator is in software. See the block diagram. the PWM techniques you mentioned are suited for power inversion, not audio.

    You can get by without a filter (at high baudrates) because sigma-delta shapes the noise up in frequency. For example at 115200 baud, a zero signal would get modulated to a 115.2 kHz square wave. You can’t hear it. Your speakers can’t play it. When you start trying to play more interesting signals, the noise moves down the spectrum, but it concentrates near the top.

  15. markrages says:

    Sorry, that should be a “57.6 kHz square wave”. The bitstream will be 01010101010101… (i.e., periodicity of 2 bits).

    Still above human hearing, but it might annoy the dog.

  16. fred says:

    Check out for something like this using a dsPIC and an SD Card. Uses the PIC’s PWM feature to play the audio off of an SD Card. Plays raw wave audio or 4 channel MOD music files.

  17. DarkFader says:

    Ok, no explicit filter then. It’s not for hi-fi audio anyways :)
    Here’s something about DPWM for audio:
    But it might be only good with high frequency clocks, since not much logic is needed.
    There was also a link to a good introduction to delta-sigma:

  18. markrages says:

    Thanks for the S-D link darkfader. That’s much better than the information I was working with. Or the incomprehensible wikipedia article.

    Hmm, I wonder if a higher-order converter would sound better…

  19. ryan says:

    What’s old is new again. All the sounds on the Apple II were made by flipping a single bit, and thereby ‘clicking’ the speaker at different frequencys. What was that address, $C020 or $C030- one for the casette port, one for the speaker.

  20. opg says:

    I’ve been using POKE commands on the Apple IIe to toggle the speaker. There is actually a range of POKE commands/addresses that you can use:

    POKE -16336,0 to -16321,0 toggles the internal speaker. The second address (0) can range from 0-250 to alter the pitch.

    POKE -16337,0 to -16352,0 (also 0-250) toggles the speaker but sends it straight out thru the cassette ouput to mixer. And oh what a fat, fat sound!

    But you are right, $c030 is the same as -163336.

    Now if I could only do the same on the Tandy 102….

  21. matt harlum says:

    just a thought, the voltages outputted from your serial port can range from 0-12v dc, now wouldn’t it be a bad thing to output that to your amp?

    other than that i reckon thats top work, cant wait to try it out :P

  22. Gant klockor says:

    Ronnie James Dio – RIP

  23. Trevor says:

    Does anyone know where to get the source code/ terminal application?

    I could use this at work!

    Thanks :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 96,405 other followers