I need to drive a speaker, fairly efficiently and at different frequencies.
I just need to make beeps and boops, but the current specification I have calls out various volumes and tones.
The two bits of information I'm looking for are (1) suggested strategies for making it work (should I just drive a half-bridge from my microprocessor, and synthesize the sound, should I get a class D chip, etc.), and (2) what's a reasonably accurate model for a speaker as seen by an amplifier? I know it doesn't just present an 8-ohm load, but I don't know what load it does present, or what aspect (voltage or current) of what's happening at the speaker terminals translates to sound pressure at the diaphram.
Thanks all -- so far all my audio stuff has been mostly cookbook, with no need for low power consumption.
This is the absolute best PC speaker I ever bought, and it was only $20 then. You should buy this and look at the amplifiers they use in it, AND even the cabinet design, because even the current $100+ jobs out there now can't beat mine, and I will be buying more of them. The problem is that they are no longer made. So get 'em while they're hot, because they ALL got cheaper after the year these were introduced.
Speakers slew-rate limit but you'll need to be fervent in low-pass filtering PWM output to them to prevent heat buildup.
Modelling them is to despair. You can get the Theile-Small parameters for the speaker ( maybe? ) but that's really pointed at designing the optimum box for the thing.
I also have to wonder if you'll be quick enough on the PIO pin to generate all desired waveforms. My intuition is that the PWM frequency needs to be ... quite a bit higher than the desired output frequency unless you're planning to radically restrict the frequency space of the output.
** Most speakers (ie simple cone drivers) present a nearly resistive load at frequencies between 200 and 500Hz. Above 500Hz the impedance begins to r ise due to voice coil inductance, approximately doubling in value for each two octaves. The soft iron pole piece has high eddy current loss so makes a poor inductor core.
Below 200Hz, impedance rises by several times to a resonance at some freque ncy, where it is precisely resistive again. The phase angle between voltage and current reaches 60 degrees or more at the steepest parts of the up or down slope, leading and lagging.
The impedance minimum occurs in the range between 200 and 500Hz and is typi cally 15% above the DC resistance value. Most of this increase is due to fr ictional loss in the cone's suspension.
** Sound pressure follows the magnetic force applied by the voice coil to t he cone. This force follows the current or voltage at a given frequency and produces acceleration of the cone,(f = ma). Constant acceleration of the cone produces a constant sound level over the frequency range where the co ne is rigid - above that, SPL will increase or decrease cyclically due to s tanding waves on the cone.
The pressure response is then non predictable and you need to see a measure d curve. Beware, speaker cones radiate from the front and the back plus ar e directional, particularly at mid and high audio frequencies.
Below 200Hz, enclosure design dominates the pressure response curve AND the impedance curve - a tuned enclosure producing upper and lower impedance pe aks instead of just one with a sealed or open back enclosure.
If your spec requires particular SPLs at particular frequencies, I strongly recommend you obtain a decent SPL meter, set it to "flat" or "C" curve and obtain your levels empirically - at the specified distance .
In which frequency range are these tones ? What are the size limits of the speaker ?
With small speakers and low frequencies, you end up into the resonance area and the impedance varies a lot. Above that, the impedance is quite constant, within a few tens of percent of nominal.
At low frequencies, below a few hundred Hertz, the human ear sensitivity drops quite quickly and the situation gets worse with lower absolute sound levels. Getting human attention at 50 Hz requires much more audio power than at 1-3 kHz.
With half bridge you either need a split supply or a big electrolytic capacitor to get rid of the Vcc/2 DC bias.
I would expect to get the sensitivity figures for most speakers specifying the SPL at 1 m at 1 kHz. This figure varies quite a lot from speaker type to an other, so you should pick a speaker with good sensitivity, if low power is essential, usually with the expense of frequency range.
** That is not what published impedance curves show.
Typical 8 ohm, 5 inch woofers rise to about 20 ohms at 20kHz. The larger the voice coil diameter, the lower down the rise begins and the greater the final value. Some high powered 15 inch woofers ( ie JBL2226) can rise to over 100 ohms.
Specialty wide range speakers, like twin cone types, have a copper ring or disk on top of the iron pole piece that inhibits the usual rise in impedance and extends the frequency range.
Give yourself a little headroom on the volume if you can. The purchasing guy will buy a slightly crappier speaker, or the enclosure guy will give you fewer speaker grille slots (if you're lucky) or point it away from the user (if not).
If you have (or can cheaply get) a bunch of flash or ROM, it might not be totally insane to store samples and play them back as needed. It's easier to do chords or even voice this way, if you want.
In super perfect world, you have both sample playback and synthesis. Sometimes you have some sounds or tones that are always the same - the "happy" POST-ok sound, keypad beeps, etc - which are good candidates for sample playback. You may also have sounds that should change in real time based on what is happening, like a user adjustment or something the box is measuring - so the user can twiddle something else while listening - which are good candidates for synthesis.
Some programs you might want to know about:
siggen - audio signal generator, GUI or command-line. Can write to .WAV. Linux only.
sox - audio file format converter. Can convert to and from "raw" files (ints at various widths and sample rates), which is often what you want for a sample in ROM. Linux and legacy systems.
audacity - GUI audio editor. Can also do FFTs so you can figure out where that ringing sound is coming from. Linux and legacy systems.
The thing which may seem surprising for something that looks like a coil of wire is that speakers can be capacitive at some frequencies and inductive at others. They are generally only resistive at resonance.
Moving coil speakers can just be be treated as nominal resistance - its not precise but plenty close enough for bleep type work. At resonances R increases.
But if you only need bleeps with efficiency you'd do better with moving iron, many times as efficient and cheaper. The little sounders that were famously used on dialup modems are moving iron. From that point you get 2 options:
If you just want single frequency, a self resonant speaker/osc combo will get you max volume by heading for resonance.
If you want more capability, you can drive the thing from a bistable that's flipped by more intelligent circuitry to generate your wanted frequencies. Volume control can be achieved simply by narrowing the pulses.
If you do use moving iron, their impedance is marish. They're effectively dirty inductors, with X varying very widely indeed. Use an output that can drive the dc resistance and you're safe, X is always higher than that - except at dc :)
I remember writing a program that took over the real time interrupt timer to provide a hardware basis for a PWM output to that speaker. One of my supervisors heard me playing modem sounds and wanted to know what sound card I was using. When I told him it was just the PC speaker he about flipped. Sound cards were still pretty uncommon in those days and he needed a way to play modem sounds through the PC speaker. It sounded ratty, but a lot better than beeps and boops. 8 kHz sample rate with a faster PWM, I don't recall the rate.
The funny part was the real time interrupt never got disconnected and it made the time run way fast. lol
That's because, like a crystal, the electromotive forces turn the acoustic actions into electrical actions. So you may not "see" the capacitance, but it is there in the spring of the speaker cone and even the air if it is in an enclosure.