audio

sci.electronics.design audio

Anyone know of some c or assembley code for reading a .wav file (8000 cps,

8 bit linear data, mono) and converting to a single wire output. That would probably be "pulse width modulation" but there are hints on the internet of other methods with bit (not byte) rates below 8000 bps which would be attractive. The device needs a bare bones setup that will fit in an avr type microntroller. Roughly only 10 seconds of voice is required, so this would seem possible.

Hul

Reply to
Hul Tytus
Loading thread data ...

Reply to
bitrex

It should be straightforward enough to implement on an AVR without a hardware DAC via one of the hardware PWM outputs as well. Check out the SDFat library from here:

Run the hardware PWM at 5-6 times your desired "sample rate", and you could have a circular buffer and round-robin threads of execution where the highest priority one is triggering every sample period and sending values to the PWM register, while the other thread holds a pointer X number of samples ahead into the circular buffer and is pulling blocks of samples from the SD card into it.

The "threads" don't have to be anything elaborate, really just timer compare interrupts with the "consumer" set to fire at the sample rate, and the "producer" set to load a new block into the buffer after say X/2 samples have been read out, load time dependent

Reply to
bitrex

I was going to say "nothing so specific, unless you happen to find it on the web" and -- guess what!

--
Tim Wescott 
Control systems, embedded software and circuit design 
 Click to see the full signature
Reply to
Tim Wescott

Why run the hardware PWM at that speed? To make output filtering easier?

You're going to have an issue with using PWM: to get 16 bits of precision with "plain old" PWM you'd need to have a clock that's 65536 times faster than the sample rate -- i.e., close to 3GHz for 44kHz sampling.

You'll be able to improve that somewhat by sampling out faster and using sigma-delta techniques, but I fear that for really high quality audio it's a "can't get there from here" sort of problem with the available resources on an AVR.

--
Tim Wescott 
Control systems, embedded software and circuit design 
 Click to see the full signature
Reply to
Tim Wescott

OP did say "8 bit linear mono at 8000bps." ;-)

Some old uPs from the 80s could PWM intelligible sounding speech into a speaker. I think decent-sounding 8 bit 8kHz audio should be possible with an AVR at 20 MHz or something

It won't be CD quality for sure, but you can definitely spit out okay-sounding audio via PWM on an AVR. They aren't your Dad's 8 bit!

If there's a 16 bit PWM channel available like on an ATMega one might be able to u-law encode the PCM data to 8 and use a lookup table to expand on output for somewhat better quality

Reply to
bitrex

Yeah. But I can't remember the math off the top of my head; for 8 bit equivalent resolution for a source sampling rate of 8kHz even a 128kHz PWM clock is probably not good enough with a simple RC filter. I do recall that the worst-case settling time for RC filtered PWM is really, really bad.

A 2-pole op amp Bessel filter would be better

Reply to
bitrex

Check dis out:

Reply to
bitrex

I did that once on a PC. I commandeered the time of day clock interrupt by setting it for 8 kHz in the 82xx timing controller chip (8253 maybe?) and hooking it to my routine. My routine read one sample from an audio file and used that to set the width of the pulse driving the speaker using another section of the 82xx timing controller chip.

The audio was not very good at all, but it was still audio and did not require an external speaker or sound card. This was in the days when a sound card and CD were bundled together to add "multimedia" to your PC and were not cheap. One of my bosses heard my PC making modem sounds (with no modem) and wanted to know how I was doing that. Seems our customers wanted to be able to hear these sounds as part of a training course we provided but it was a major hassle for them to order the multimedia package to make this possible. I looked pretty good that day and I was actually just playing on the computer during lunch!

--

Rick C
Reply to
rickman

OK. I completely missed that. 256 * 8000 = 4.096MHz might even be a reasonable clock rate on an AVR, and you could do at least some noise shaping with sigma-delta techniques to make the lower frequencies better.

--
Tim Wescott 
Control systems, embedded software and circuit design 
 Click to see the full signature
Reply to
Tim Wescott

so long as 8 bit audio is acceptable you can get about 8000 samples per second from a 10MHZ AVR - should be enough for near telephone quality voice reproduction.

--
This email has not been checked by half-arsed antivirus software
Reply to
Jasen Betts

One company built a monophonic virtual analog synthesizer using an ATMega8 running at 20MHz, that spit out 16 bit 44.1 kHz audio from a parallel output DAC. The waveforms were stored as lookup tables in memory, and at 20MHz/44.1kHz even including ISR and lookup-table memory access overhead there were still about 400 clock cycles per sample available to do some basic DSP.

Plenty of clocks to do the calculations required for a basic envelope generator and 4-pole resonant digital filter when an 8x8 -> 16 signed multiply including write-back is only a 2 clock cycle instruction.

Reply to
bitrex

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.