Audio output from a serial port

rs232

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.

23 thoughts on “Audio output from a serial port

  1. 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. :)

  2. Jason,

    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.

    Regards,
    Mark
    markrages@gmail

    ps. who’s Mike?

  3. 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.

  4. 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.

    -Tired2

  5. 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 :-)

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

  7. 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?

  8. 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.

  9. 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.

  10. 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…

  11. 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.

  12. 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….

  13. 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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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