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.
http://linuxgazette.net/109/john.html this is for the parallel port, and i don’t know if it sounds any better.
FIRST!
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. :)
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?
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.
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
Nostalgia all right: I remember even having serial ports.
(Mac owner. :-)
This reminds me of a website I found for doing serial audio out on a PIC:
http://www.romanblack.com/picsound.htm
I am going to try this on my PIC based robot.
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.
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 :-)
woah, I’m smellin’ another sweet way to crustify those synth tracks!
linked page croaked, but the software and documentation is still available:
http://vivara.net.nyud.net:8090/software/ttyplay/
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)
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?
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.
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.
Check out http://www.k9spud.com/traxmod/ 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.
Ok, no explicit filter then. It’s not for hi-fi audio anyways :)
Here’s something about DPWM for audio: http://www.fpga4fun.com/PWM_DAC.html
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:
http://www.beis.de/Elektronik/DeltaSigma/DeltaSigma.html
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…
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.
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….
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
Ronnie James Dio – RIP
Does anyone know where to get the source code/ terminal application?
I could use this at work!
Thanks :)