OpenWrt Forum Archive

Topic: simple audio output

The content of this topic has been archived on 19 Feb 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Someone managed to use a serial port as a very simple PWM DAC.
http://vivara.net.nyud.net:8090/blog/?p=24
Instead of tying up a serial port, could it be possible to "bit bang" a GPIO to do the same? A very simple transistor switch can handle the speaker driving or a resistored piezo speaker could be used. The GPIO can even be shared with, for example, a LED.
BTW, don't expect good quality (although it will likely be higher than the serial port due to higher frequencies and lack of start and stop bits), but it should work nicely for simple sound effects. (Imagine if you set up your router to check all the servers and say "Fault detected on server x."  if it finds a problem. Or if the router is part of a homemade robot...)

star582, you need some hardware that can buffer the data since you can not interrupt often enough to do this.

I know the parent post is old but I am currently working on using an FPGA with a character driver that uses the GPIO to send data to the FPGA every 1/10 of a second (interrupt is triggered by buffer size).  An FPGA is necessary so that its RAM can be used for the buffer, it then uses Pulse Density Modulation that is derived from a digital sigma-delta converter inside the FPGA.  I am attempting to make the logic synchronous because the serial port is too slow and asynchronous logic is a pain to simulate and debug.  So my design will have to synthesize to 166 MHz (I believe thats what the WRT54G runs at).  Since this design requires no add/mult or any other nasty logic, I don't think this will be a problem.

Using the serial port results in crummy audio quality, unless I use a CPLD with a MP3 decoder chip.

The total hardware cost including PCB, FPGA, and Config PROM will be less than $15 hopefully. 

If anyone would like to contact me with suggestions, help, or enthusiasm you can email me at lm317t ATT gmail GDOT com  minus ATT and GDOT

Thanks
Brian

hello.

For GPIOs, problem is not speed as for example my router can write to a GPIO in about 7 cycles => that's a max frequency of about 14MHz !!!


Problem is the fact that it will ouput a square signal that will sound very distorted.
I don't know if it possible with some electronics to convert in real time a 1bit signal to a 16bit one ?
If it is then we can easily expect a 44KHz - 16 bit stereo ouput => 2*44000*16 * 2 * 7 cycles ~= 20,000,000 cycles ~= 1/10 of CPU power.

With 9/10 of CPU which means 180MHz for a 200MHz CPU, maybe it is enough to decode MP3 in real time ?

Correct me if I am wrong.

Cyril

Cyril wrote:

hello.

For GPIOs, problem is not speed as for example my router can write to a GPIO in about 7 cycles => that's a max frequency of about 14MHz !!!


Problem is the fact that it will ouput a square signal that will sound very distorted.
I don't know if it possible with some electronics to convert in real time a 1bit signal to a 16bit one ?
If it is then we can easily expect a 44KHz - 16 bit stereo ouput => 2*44000*16 * 2 * 7 cycles ~= 20,000,000 cycles ~= 1/10 of CPU power.

With 9/10 of CPU which means 180MHz for a 200MHz CPU, maybe it is enough to decode MP3 in real time ?

Correct me if I am wrong.

Cyril

The 14 MHz must be reliable and basically real time.  This is not possible using interrupts or the Real Time Kernel module.  This would result in a real messy unpredictable DAC.  The way to do it, I believe, would be the way sound cards do this on most PCs, dump snippets to a buffer at an interval, plus or minus some error.  The buffer should be large enough to not overflow or starve in the intervals.

As for single bit audio, it is likely your PC sound card is 1 bit output, I know many DACs use this or something similar implemented in hardware, look at the Low-Pass Filter recommended by Cirrus Logic on the CS4270 for an example.  Here is a wikipedia article on PDM:
http://en.wikipedia.org/wiki/Pulse-density_modulation

I intend to run mine at 200 MHz from the system clock.

I need to know where I can get a clock signal (200MHz) on the board (I hope this is possible) on a WRT54G.

I respect your K.I.S.S.  attitude, but unfortunately for decent audio streamed in over the network, then decompressed, then sent to GPIO as PDM just is not reasonable without a Real Time Kernel module with nanosecond accuracy, which does not exist to my knowledge b/c its not exctly practical.

The discussion might have continued from here.