Re: PWM -> Audio Output



Incorrect attribution. I did not write this.

Rene wrote:
Jim Stewart schreef:
eeboy wrote:
I am using a PWM output on my micro to produce audio from headerless WAV
(RAW) files. The audio output works but the quality is not quite there. By
that I mean that there are 'artifacts' which appear in the audio output
from my device which do not appear in the RAW file.... mainly a popping
noise which seems to follow the amplitude.

I've discovered that I can remove these artifacts by changing the PWM
frequency. As I lower the frequency the pops and clicks go away but the
audio does not reproduce as nicely.
My audio playback source code has two parameters which effect the
playback. First, the sample rate which I currently have fixed at 8kHz for
FLASH space savings. Considering that all audio played back will be voice
prompts I thought this was sufficient. Second, the PWM frequency which I
have set to be a multiple of the sample rate. So, if the sample rate is
8kHz and my PWM frequency is 32 times that... I have 32 PWM periods per
sample. I get really nice reproduction at 32 and 64 times the sample rate
but the popping noise is present. I eliminate the popping noise with a
setting of 8 but then the audio is marginal.

My PWM output feeds through a first order RC filter which is set to cut
off at around 8kHz. In practice it's currently around 12kHz because I
didn't have the correct resistor value in my bin at the time I populated
the board. The output of the filter is then fed to a amplifier
(capacitively coupled).

As I don't see the OP in this thread, I will reply to this one, it is however not meant as a reply to Jim.

Could it be that You (so once more, You != Jim) do not fully understand PWM (just a question, not to be unkind, no problem if it would be the case, can't be an expert at everything)? You don't mention which PWM-resolution You are using which is rather important. When You say You are able to do 32x and even 64x oversampling, You must be working with quite a micro if You are using 8 bit.

First there is the resolution of Your PWM. Let's say this is 8-bit. That means that every period Your counter has to count from 0 to 255 (assuming You are not using the phase correct modes of e.g. Atmel, then it doubles). I'll presume that Your prescaler is at 1 and You are doing 64x oversampling. Your sampling rate is supposed to be 8 kHz (and as larwe also mentions, Your filter should cutt off at 4 kHz and not the 12 Khz You have made)(allthough, if we're talking output filter and You are actually oversampling that much, 12 kHz will do more than suffice - I doubt however that You are oversampling). That means Your clock frequency is 256x8000x64 = 131 MHz. I doubt this is the case.

You wrote "So, if the sample rate is 8kHz and my PWM frequency is 32 times that...", I am wondering what You mean with PWM frequency. Do You mean the frequency of the clock that drives the PWM counter or the frequency of the timerinterrupt, i.e. the number of times a sample is being output, so full count cycles of the timer? Could it be that You are in fact talking about the resolution of the pwm?

In another message You are talking about "the 4x multiplier works great", do You mean here oversampling? What are You multiplying?

So first get straight what the parameters You are talking about, really are:

1. Clock frequency of the micro: ?
2. Prescaler setting in pwm-timer: ?
3. Resolution of timer in it's current pwm-configuration: ?
4. Oversampling number: ?
5. Resolution of Your samples in the RAW file: ?
6. Sampling frequency at which the samples in the raw file have been taken: ? (I presume this is 8 kHz.)

How have the samples been taken? Did You, if You took them Yourself, use a better input filter as the output filter You are using now?

Your story is very unclear, if You fill in the values above things might get a bit clearer. Perhaps also mention what micro You are using, posting some sourcecode of the program You are using wouldn't be a bad idea as well.

The suggestion of Larwe to visualize the isr that updates the overflow value on the scope is a very good piece of advice. Tell us what frequency You see there and if the spaces between the isr's are constant.

Yours sincerely,
Rene
.



Relevant Pages

  • Re: PWM -> Audio Output
    ... The audio output works but the quality is not quite there. ... from my device which do not appear in the RAW file.... ... I've discovered that I can remove these artifacts by changing the PWM ... have set to be a multiple of the sample rate. ...
    (comp.arch.embedded)
  • Re: PWM -> Audio Output
    ... The audio output works but the quality is not quite there. ... I've discovered that I can remove these artifacts by changing the PWM ... have set to be a multiple of the sample rate. ... The poppiness is an absolutely sonically repeatable sound that can ...
    (comp.arch.embedded)
  • PWM -> Audio Output
    ... I am using a PWM output on my micro to produce audio from headerless WAV ... from my device which do not appear in the RAW file.... ... have set to be a multiple of the sample rate. ...
    (comp.arch.embedded)
  • Re: 96KHz and 192KHz Sampling Frequencies
    ... preferred sample rate for software mixer ... dostorted when I used a 192 KHz audio raw file, ... I have a OMAP Hardware which is interfaced with a TI's Hardware Audio Codec. ...
    (microsoft.public.windowsce.embedded)
  • Problems with Echo AudioFire12
    ... If I try to switch sample rate to i.e. 96.000 either in the application ... I was almost giving up, thinking that I'd got a faulty audio device, ... firewire port. ... AudioFire hardware device correctly changes sample rate as well ...
    (rec.audio.pro)

Loading