I've been reading about outputting PCM audio through the internal PC speaker using "Pulse-width modulation". If I understand correctly, this is acheived by retracting the speaker cone before it has a chance to fully extend. My question is now this: would it be possible, by spending all CPU resources on this task, to keep the speaker cone in its current mid-extension position, by rapidly (as fast as the CPU will allow) toggling the current to it?
>>1
The limit of human hearing is about 20KHz, the typical modern CPU clock frequency is 2GHz, which means that you have to spend some CPU resources (a couple instructions) about once every 100,000 cycles.
Name:
Anonymous2011-11-17 8:26
No. Your speaker cone will generate a sound at the frequency rate of the current cycles. Maybe the sound amplitude would be small.
You could try using the serial port (or a USB-to-serial dongle) to do PWM on a speaker instead. Of course, won't work for too high frequencies, but it should be interesting anyway.
I saw this done and working surprisingly well back in the 486 era.
Name:
OP2011-11-17 8:45
The reason I'm asking, as some may have already figured out, is because by freezing the state of the speaker between samples would, according to my theory, output a higher quality signal, because of lowering the amplitude of the carrier. Is this correct, or have I completely misunderstood something?
>>8
That's what PWM does - it generates a quasi-analogue signal based on the ratio of "on" vs "off" time. The more "on"-time, the further the cone is pushed out.
It can sound pretty impressive on a proper PC speaker. It will sound like crap on the piezoelectric buzzer that is probably soldered onto your current motherboard.
Name:
Anonymous2011-11-17 16:22
>>10
It'll sound like crap either way because there's no low-pass filtering.
>>1
Basically, PWM is a common trick in electromechanical, electromagnetic and electroluminescent transducer control to vary power with just one bit of resolution. When the delivery of power is divided in discrete windows, and those windows contain a time dependent switch of full power and no power, the total power per window is the integral of the on `area' of that window's graph. So you don't really need to wonder if it is because of physical inertial limitations of the cone or anything like that, the answer is just varied exertion of electricity into mechanical power into air vibrations. For the purpose of human perception this technique is convincing if the window size is small, hence, a very high sample rate. In audio this should be in the half million Hz range. PWMing of LEDs and LCDs is very common and can be done at 60Hz or less as the eyes are very slow at updates.
>>11
That's what the inertia of the speaker membrane is for.
Name:
Anonymous2011-11-17 22:40
>>14
You've never seen shitty Christmas lights or low brightness LED displays. With shitty Christmas lights you can see them flicker, just like CRTs.
With LED backlit displays, turn down their brightness, then wave your hand in front of them. Compare to when the brightness is at max.
Name:
Anonymous2011-11-17 23:33
>>16 With LED backlit displays, turn down their brightness, then wave your hand in front of them.
That is not a valid use case.
Name:
Anonymous2011-11-18 1:08
>>14
Thank you very much for explaining why this technique works, but now I'm wondering if I have misunderstood how the speaker works on a physical level.
>>18
Your understanding of the speaker is probably still correct given the PWM explanation, what I meant by that part was to not worry too much about the physical details when choosing how to do the PWM. From the point of view of programming audio waveforms, power delivered to the speaker and what the speaker actually does with it is kinda decoupled, as it will have to do `something' with the power given, including stuff like compensating acceleration and velocity, `store' the power as EMF reflections that send out the indebted power along the other way of the coil movement, just releasing it as heat, etc. (and every speaker will be different in how it handles this anyway, I'm sure 8 ohm PC speakers will vary a lot even within the same batch as its cheap chinese crap).
>>20
Not sure if trolling...
I believe this is fundamentally broken. The physical details of the speaker are exactly why the PWM trick works at all. That is why the type of speaker makes a difference.
Nor does human hearing work by "averaging" power levels over a window - the ear hears frequencies. You need to produce a convincing frequency spectrum, you can't fool it by just flickering fast enough.
By your way of thinking there would be no problem dimming a fluorescent lamp - just deliver some power and it will have to do `something' with it.
>>17
Moving your eyes around while reading a LED backlit screen or a projector or CRT is a valid use case, “faggot”
If you can't see it, your Autism has affected your visual center.
Name:
Anonymous2011-11-19 10:52
>>21 You need to produce a convincing frequency spectrum, you can't fool it by just flickering fast enough.
What happens if you have a heavy enough membrane: you deliver high-frequency pulses of varying width such that if you smooth them at twice the frequency, the averaged voltage (and therefore the displacement of the membrane) forms a 1000Hz sine wave. If your frequency is 100KHz and the membrane is physically unable to oscillate faster than at 20KHz, then you get this smoothing right there and produce a nice clean sine wave.
Now consider how the ear hears frequencies: it has microscopic "hairs" of varying weight and length (and therefore different resonant frequencies). So even if you have a very light membrane which is able to push out your 100KHz square waveform, the oscillators in your ear would average it and get excited by it proportionally to their resonant frequencies in exactly the same fashion as the heavy speaker membrane gets driven by the high-frequency voltage oscillations.
Sure, in that case you will also get some high-frequency noise as well (the hallmark of the "8-bit sound"), but the frequency spectrum you are trying to produce would be there loud and clear.
Name:
Anonymous2011-11-20 9:54
The reason why PWM works with piezo speakers is pretty simple:
In any speaker, sound is created by the movement of the diaphragm. With a typical electromagnetic speaker, the rod can be fully extended or fully retracted, or any range between the two. Oscillations between those cases create the sound. It is important to note, however, that the diaphragm does not move instantaneously. If you are using a sampling rate of 44khz, even though that sampling rate can carry a 22khz signal, it's unlikely that the speaker can oscillate that fast, and the sound will be aliased to a different frequency.
PWM with piezo speakers *will* work (look up the ZX Spectrum if you don't believe me) because of the natural aliasing of the speaker. It doesn't matter if a PWMed version of a signal isn't electrically identical, when the piezo speaker just isn't "good" enough to play that kind of sound.