Background: A class D amplifier drives a load/speaker by two mossfets in a push-pull configuration with their gates being controlled digitally, with pulse-width modulation.
The class D amplifier changes the signal to digital, it is typically between 250kHz and 1.5MHz (maximintegrated) With a Photon being 120MHz and a low level pin toggle in 4-6 cycles there seems to be enough room to do calculations as well. Is there has already been a library written to do what I want, or do you know of a good reason not to? A single MOSFET, resistor, and speaker controlling an analog audio signal from a single digital pin sounds like my kind of fun.
Resources:
http://www.georgegardner.info/electronics/class-d-avr.html
Wi-Fi Walkie Talkies, genius!
I usually research things to death before I ask, but my general keywords aren’t turning up anything.
When this is running in main, I can get 8-bit audio to 25kHz, but I’d need 10x that speed to start. Thanks.
while (playPosition < RECORDING_MAX) {
playPosition += 1;
ampBitMask = 0x80;
for(uint8_t playTiming = 0xFF; playTiming > 0; playTiming -= 1) { // 8-bit loop
if (audio[playPosition] & ampBitMask) {
pinSetFast(SPEAKER_PIN);
} else {
pinResetFast(SPEAKER_PIN);
}
if (playTiming == ampBitMask) { // shifts towards LSB after it is done masking every value of that bit
ampBitMask >>= 1;
}
}
}