What is the easiest way to get audio from a WAV file into a line-level format, ready to be plugged into the amplifier of a HiFi audio set (or portable speaker)? As [Konrad Beckmann] demonstrated on Twitter, all you really need is a UART, a cable and a TRS phono plug. In this case a USB-TTL adapter based around the FTDI FT232R IC: the TTL-232R-3V3-AJ adapter with 12 Mbps USB on one end, and a 3 Mbps UART on the other end.
[Konrad] has made the C-based code available on GitHub. Essentially what happens underneath the hood is that it takes in a PCM-encoded file (e.g. WAV). As a demonstration project, it requires the input PCM files to be a specific sample rate, as listed in the README, which matches the samples to the baud rate of the UART. After this it’s a matter of encoding the audio file, and compiling the uart-sound
binary.
The output file is the raw audio data, which is encoded in PDM, or Pulse-Density Modulation. Unlike Pulse-Code Modulation (PCM), this encoding method does not encode the absolute sample value, but uses binary pulses, the density of which corresponds to the signal level. By sending PDM data down the UART’s TX line, the other side will receive these bits. If said receiving device happens to be an audio receiver with an ADC, it will happily receive and play back the PDM signal as audio. As one can hear in the video embedded in the tweet, the end result is pretty good.
If we look at at the datasheet for the TTL-232R-3V3-AJ adapter cable, we can see how it is wired up:
When we compare this to the wiring of a standard audio TRS jack, we can see that the grounds match in both wirings, and TX (RX on the receiving device) would match up with the left channel, with the right channel unused. A note of caution here is also required: this is the 3.3V adapter version, and it lists its typical output high voltage as 2.8V, which is within tolerances for line-level inputs. Not all inputs will be equally tolerant of higher voltages, however.
Plugging random TRS-equipped devices into one’s HiFi set, phone or boombox is best done only after ascertaining that no damage is likely to result. Be safe, and enjoy the music.
Most of my music has an odd parity
Haha
The thing about PDM is that all you need to convert it to analog is a low pass filter.
Most audio devices have a low pass filter at the input – either explicitly or implicitly in the bandwidth of the amplifier stage.
You can connect that PDM output from the FTDI cable to the line in of pretty much any amplifier and expect it to make audio out of it.
Wikipedia of PDM: https://en.wikipedia.org/wiki/Pulse-density_modulation#Digital-to-analog_conversion
Any concerns about the voltage level can be addressed (fixed) with a series resistor between the FTDI output and the line in input.
Cool hack, at any rate.
Remember when they did this on the TI graphics calculators, driving it with a Z80. Super cool trick
PDM encoding is very complex compared to PCM, so all “convenience” gained at the output stage is lost at the input stage.
Right, but since by then we’re already in the analog domain there’s no need to decode the PDM stream. Methinks you were missing the point.
I think you missed my point. Getting the analog signal into the digital domain with PDM is the non-trivial part.
My first thought is that doing it that way would eliminate the advantage of digital because your analog amplifier isn’t limited to discreet ones and zeros so it would amplify any noise too. But maybe this could be fixed by putting a non-inverting buffer in front of it with sufficiently fast response time.
Finally A HACK !
FTDI should be bankrupted and destroyed.
The china clones work fine with *nixens.
…but I might accidentally have gotten some originals…
*sigh!*
If they go EOL, the left over parts that are on fire sale would end up on breakout boards. The masks would accidentally be acquired by some factories there too.
Why? Because they protected their IP from defective clones?
You are more than welcome to use Chinium garbage in your projects. I prefer to use devices that work as specified and don’t rely on bogus drivers. Next time you work on a Class III medical device or a DO-178D project, please specify your (apparently) favourite garbage and see how far you get.
Preventing their driver from working with clone chips would be a justifiable level of IP protection. Bricking chips was not justifiable IP protection.
There were lots of major electronics manufacturers and distributors that *did* do their due diligence in trying to obtain legitimate FTDI parts, but ended up with bricked products largely due to FTDI’s own supply chain mismanagement.
FTDI purposely and maliciously acted to cause permanent physical damage to property that they did not own, and for that reason they shouldn’t be trusted by hobbyists or by professionals.
Sony rootkit… installing software unknowingly to the user to disable their hardware, and hiding the presence of said software.
I’d put them in a worse camp than FTDI, but I don’t see anyone complaining so bitterly about them.
FWIW, the Sony rootkit didn’t permanently brick your computer, and it was the cause for quite a large amount of public backlash.
That being said, screw DRM in general. It doesn’t prevent piracy at all, it just prevents people from being able to consume content they legitimately own.
And speaking of Sony, for a while there it was easier for me to pirate a 4k copy of a movie that I already owned on 4k BluRay than it was to play it from the BluRay drive in my computer, which tells you about what DRM incentivizes. Now I can at least play it, but no real way of making a copy to watch on my laptop or phone on the go.
Coincidentally, I own a lot of CDs and DVDs, but only a single 4k BluRay.
* headline actually reflects article content
* Contains a good summary with relevant links
* Interesting content
* Well written
Article is a solid 10/10, well done :-)
This hack is of course really cool too, just got very impressed by this post.
“Article totally misinterpreted how the hack works.”
The speaker doesn’t need an ADC or a DAC, either.
Pretty much any (audio) amplifier with line in is adequate.
Could you hack the cable to connect the RX line to a handshaking (output) line – then stereo might become possible?
Or else some of the FTDI chips can be re-flashed to change the gpio usage – whether this can change an RX to an output I can’t remember.
I wonder how well this would play with a class D amp? Maybe there would be some intermod!
Yes it seems likely with reprogramming with FTPROG that the FT232RQ in the lead can use the RX as a GPIO output, job done.
While it is fun and a hack, USB audio dongle are cheaper and far superior than real FTDI cable.
I have many of these cables. What is the process to verify that it is a real FTDI?
From what I seem to remember reading about them:
– connect to a Windows PC
– if it still works, it is real
– if it is bricked, it was a knock-off.
What’s a “TRS phono plug”?
I think we’re talking standard 1/8 inch phone plug, but the text is all over the place.
” TRS” makes me think Radio Shack computer, but they didn’t originate the plug and only very narrow minded (as in no other experience) woukd think such plugs were named after the computer.
But it’s also been a long time since Radio Shack made their own computers, so even if somedid call them “TRS cables”, the reference is now long in the past.
Tip-ring-sleeve. Also found as trrs for 3-channel (composite video with stereo) on devices too small for the corresponding RCA jacks
Tip
Ring
Sleeve
Very cool! We did the opposite of this about ten years ago to control robotics with Android phones.
You can do better than just PDM, and use higher-than-first order delta-sigma modulation for better sound quality. Second order should be trivial. (I wrote a program to do this a while ago; it works fine on the 1.5Mbit/s I can get out of the UART integrated into my mainboard or a PL2303 cable I have)
If you can tune the proper filter for 5th order, at 3mbit/sec you should be able to get SACD quality out of it.
Cool! Share your code? I’d like to see.
Here’s the code for just the DS DAC itself
https://gist.github.com/rnjacobs/091ed975fb7dd762f095bf3e6c9350e6
Not included: other commands to set the serial port to 1.5Mbps (e.g. minicom, maybe setserial), or the hacked up alternative copy of the pl2303 kernel module that instead emits 16N1 serial.
Results vary depending on how good your computer and serial port are at keeping the transmit queue full. Dropouts sound much worse than you might think, because they’re at sonic rates. For my specific test hardware, 921600 bps works better than 1.5Mbps.
Using a standard audio connector (1/8″ TRS plug) to transmit a digitized audio is really begging for somebody to plug it into an analog system by mistake. Luckily, this probably won’t catch on in a big way and show up in consumer devices.
But that’s the point. The amplifier converts the digital to analog.
This is not a new technique. I remember an article in Dr. Dobbs in the nineties that explained it, but I don’t think it was new then.
I remember getting a stray piece of hadware in an RS232 hood (it was labelled, but I can’t remember what it was supposed to be used with.
I opened it up, and clearly it was to take the serial signal and feed a small speaker.
Yep, I get it now… wasn’t paying enough attention and thought the subject was something more like SPDIF over a UART
Um, am I missing something?
I though that audio output via PWM on an RS232 port wasn’t uncommon.
I’ve got a book from the mid 2000s with sample applications that play WAVs via TXD, too.
“Um, am I missing something?”
You are missing the USB part. 20 years ago this was much easier, you would just flip the “set break condition” bit in one of the UART registers to manipulate TXD.
Um, but a least on Windows, all the USB-Serial converters I tried so far imitated the RS232 behavior, including the 16550A UART..
The very same programs worked the same on such converters..
Big-banging the additional control lines (RI, RTS, CTS, DTR) was also no problem. – I used Delphi 3 Pro and Visual Basic v6 with Port.dll.
In facf, many sound card interfaces for amateur radio do have a simple USB-Serial board inside, so programs can keep using RTS and DTR for PTT, as if a real serial port was available. The only downside I can think of these converters is the use of TTL levels (0v or 3.3/5v) instead of +12/-12v, because some old circuits expect the correct voltages..
Perhaps they could have tested their driver with all possible hacked clones to ensure that none would have any unintended side effects as a result of their driver accessing them. Is that what you would *really* expect?
People were cheap and bought junk or used untrustworthy suppliers. Do you advocate everyone stop buying from every vendor that shipped the cloned junk and claimed is was genuine FTDI? I bet not.
What if you designed in a component that was subsequently cloned with stolen IP and the specs of that component were such that substantial and expensive damage would not result as a result of using the originally designed component properly, but that the clone would destroy the device containing it. Would you then blame the original component supplier for not providing larger margins on their datasheet?
The command sequence that caused the problem should have had no effect on probably built devices, but stolen IP failed. Who’s fault is this and why should the person whose IP was stolen care?
I know several people who share your view. Some were being cheap and got burned. Others were unaware of the fake devices. All of them are blaming the wrong company/person.
>Do you expect them to test every clone to make sure there were no unintended side effects.
But they weren’t unintended side effects. They did it *on purpose*. They fully intended to cause permanent damage. If it was accidental, it would still be unfortunate, but it would be completely understandable and it would not have been anywhere close to as much of a big deal as it is.
>People were cheap and bought junk or used untrustworthy suppliers.
The problem is that destroying consumers stuff isn’t really punishing vendors, and it sure as heck isn’t punishing the people who actually made the counterfeit chips (who already have their money and are near unaccountable). For a lot of the actual end users, the first time they ever heard about FTDI was from a technician telling them that the reason their equipment is permanently damaged was because FTDI purposely destroyed it, and that is terrible PR.
>Do you advocate everyone stop buying from every vendor that shipped the cloned junk and claimed is was genuine FTDI? I bet not.
What? Of course I advocate to stop buying from vendors known to sell fake chips. That’s basic supply chain management.
>Would you then blame the original component supplier for not providing larger margins on their datasheet?
This isn’t about *margins*. If I accidentally buy a fake opamp and it doesn’t meet spec and blows up in my circuit, then that sucks but that has nothing to do with the original designer. But if I unknowingly buy a headphone amplifier that happens to contain a fake opamp that at least mostly meet spec and is currently working fine and then the original owner of the IP comes into my house and decides to purposefully break the entire amp into pieces because the opamp had slightly different ripple characteristics, then they are responsible for that damage because they were the ones who decided to break my stuff, not the counterfeiter.
>All of them are blaming the wrong company/person.
If I haven’t already made it sufficiently clear, I need you to understand that it isn’t either or. I am not defending the counterfeiters. They are bad actors and should be punished, as well as the distributors and manufacturers that knowingly support them. FTDI are *also* bad actors for intentionally causing property damage, and therefore I will avoid using their products in the future and will instead seek out alternatives where possible.
People who unknowingly bought counterfeit chips are not the problem, they are victims of counterfeiting just like FTDI was, because they were defrauded. FTDI chose to punish other victims of the crime, rather than the perpetrators.
FTDI easily could have had the driver say “device is not genuine, comms disabled” and forced those companies to write their own drivers to protect their IP. But they chose to cause permanent damage instead.
I am not aware of any explicit , deliberate attempt by FTDI to damage cloned chips with stolen IP. Perhaps you have some special knowledge of this that I don’t.
The information that I have is that FTDI was attempting to ID cloned, stolen chips and that method ended up ‘bricking’ the stolen chips. At some point FTDI realized this was occurring and reverted their drivers not to do this test.
I disagree that people who bought products containing chips with stolen IP are innocent third parties. They bought a product that was defective by design, even unknowingly, probably because they were trying to save money. Most of this stuff was Chiesium crap, but some were made in the US and other countries. The consumers should have returned the item to the seller for a full refund under the implied merchantability warranty required by most consumer transactions. Of course, if they ordered from AliBaba or the like, they were out of luck and are reaping the rewards of buying junk.
If consumers do not act to punish retailers for selling defective by design products, this problem and others related to poor quality and poor service life will never be addressed. If I buy a product and it fails, I return it or tell the seller to fix it at their expense. If I deliberately buy junk to save money, then I accept that I have junk and it is at my risk if it catches fire the next day.
I do not understand your notion that if a defective component is installed in a system and fails because some software that assumes certain operational characteristics is somehow the software’s fault. Defective is defective. It does not matter who wrote the software.
I do agree that it would have been better that FTDI found another method to inactivate the chips with stolen IP, but the end result would have been the same for the cheapskate consumers – a device that did not work. Perhaps someone would have made a driver that worked with this device, but installing a driver from a random actor who could do further damage with a defective driver (crashes, blue screens, data corruption).
I guess we will have to agree to differ on FTDI’s motivation in this matter. I wish you luck in finding suitable USB->serial chips of good quality. I’ve not found any that are nearly as good as FTDI and I refuse to compromise the functionality and quality of my designs.
Question ! Question! So this mean I can grab an arduino uno with samples and send the music direct to RX/TX pins? or even better use an attiny85 with some of those “fake serial port” library and output the good stuff to an amplifier? Do you think this is doable guys?