📖 What Pearson does

Chapter 2 is a tour of the very simplest things electronic circuits can do. It teaches you that electricity is just moving charges, that conductors and insulators are materials with different degrees of “willingness to move electrons”, and that speakers and microphones are the same device run in reverse. There are four small experiments:

  • The world’s simplest speaker. Wind wire around a magnet, hold the magnet near a paper cone, drive alternating current through the wire, watch the cone shake and make sound.
  • Speaker-as-microphone identity crises. Take two speakers, hook them to each other through an amplifier. Speak into one. The other makes your voice louder. (The first half of this is in Chapter 2; the second half — using a speaker as a real microphone — is in Chapter 4.)
  • Piezomania. Press a piezo buzzer (a small flat disc that flexes when voltage is applied), listen to the click. Then tap the piezo, listen to the small voltage it makes. Piezos are both speakers and microphones.
  • Sound through your skull. Hold a vibrating tuning fork against your skull. The sound gets louder, because your bones conduct vibration better than air.

The chapter ends with a section called “A moment of clarity” that distils everything: voltage is a difference in charge between two points; current is the rate at which charge moves; resistance is how much the material pushes back; and “audio” is just voltage waving around at a frequency the ear can hear (20 Hz to 20 000 Hz).

🎓 Background: what “voltage” is in our firmware

Pearson spends most of this chapter explaining that voltage is a number, not a thing. It is a measurement of “potential energy per unit charge” — i.e., a measurement of how much oomph the electrons have. When the book’s “Hello World oscillator” later outputs a wave of voltage, the voltage is a number that swings between, say, +0.5 V and -0.5 V at some frequency.

In our firmware, the equivalent of a voltage sample is a 16-bit signed integer. The AMY library (the audio engine we use) represents each audio sample as a number between -32 768 and +32 767. Zero is “silence”. +32 767 is “as loud as possible, speaker pushed fully out”. -32 768 is “as loud as possible, speaker pushed fully in”. Anything in between is some position of the speaker cone. The DAC chip (PCM5102A) is the part that turns the number into actual voltage at 44 100 times per second — that 44 100 is the sample rate, and it is exactly Pearson’s “44 100 voltage readings per second”.

So when our firmware plays a recording, what is actually happening is: a long array of 16-bit integers (one per centisecond of audio) gets streamed to the DAC, which turns each integer into a voltage. The electromagnet inside the speaker responds to the voltage by wiggling. The air in front of the speaker wiggles. Your eardrum wiggles. You hear sound.

This is the single most important sentence in this whole book: audio is a sequence of numbers that some hardware eventually turns into wiggling air. Every audio effect, every filter, every reverb, every pitch-shifter in our project — and every circuit in Pearson’s book — is a way of transforming that sequence.

The I²S microphone we use (the INMP441) is exactly the reverse: it listens to the air pressure and emits a stream of 16-bit integers at 44 100 samples/second. That stream goes into a buffer. The buffer becomes a slot. The slot gets played back through the DAC. That is the entire pipeline of F-001 (record a sample) — Pearson’s “speaker-as-microphone” project, in software.

🔧 Try it on the device

This is the first hands-on chapter in our book. Make sure you have headphones or a speaker plugged in.

Exercise 1: confirm the firmware can produce sound.

> slot_play 1

If slot 1 has nothing in it, you’ll get silence (or possibly an AMY synth tone if the slot is configured as a melodic slot and has a default patch). That is fine. The point is the verb works — the firmware is talking to the DAC, and the DAC is talking to your earphones.

Exercise 2: record 2 seconds of ambient sound from the microphone.

> record_mic 1 2

Hold the device near a sound source — your mouth, a fan, a favourite song on your phone’s speaker. After two seconds the firmware prints:

Recorded 2.00 s -> slot 1 (88200 samples)

Now play it back:

> slot_play 1

You should hear what you just recorded. The 88 200 samples is exactly 2.0 seconds × 44 100 samples/second. The 16-bit integers are sitting in PSRAM, waiting to be streamed out.

Exercise 3: see what you recorded.

> slot_info

The firmware prints a 16-line table. Slot 1’s row shows RECORDED 2000 ms (or similar). The other slots show empty.

Exercise 4: do Pearson’s “microphone identity crisis” experiment in software.

Record your voice into slot 1, then immediately play it back through slot 1. The firmware doesn’t know the difference between the input side (INMP441 mic, I²S RX) and the playback side (PCM5102A DAC, I²S TX). To the firmware, both are 16-bit integers at 44 100 samples/sec. Just as Pearson showed that a speaker is a microphone run in reverse, our firmware shows that the same buffer can be the input or the output of the audio system. There is no fundamental difference.

🛠 Code reference

  • Record from the I²S mic — main/audio/amy_bridge.c, amy_bridge_record_mic(). The function opens an I²S RX channel, fills a 16-bit sample buffer, and calls pcm_load_external() to register the buffer with AMY as a playable preset.
  • Play a recorded slot — same file, amy_bridge_play_note(), with e.wave = PCM and e.patch_number = PO33_PRESET_BASE + slot.
  • The 44 100 sample rate — main/config.h, AMY_SAMPLE_RATE. Changing it would make the firmware sound like a chipmunk (up) or like a foghorn (down).
  • The PSRAM pool — same file, s_pcm_pool[]. This is where recorded audio lives. The pool is 40 seconds long (40 s × 44 100 samples/s × 2 bytes/sample = 3.5 MB).

🚫 What we can’t simulate

  • Piezo buzzers. We don’t expose a piezo GPIO in this firmware’s default hardware. The INMP441 is a MEMS mic, which works on a different principle (capacitive sensing, not piezo). The piezo project — “tap the piezo, hear the click, then tap again and watch the voltage on a multimeter” — has no digital analog in our current firmware.
  • Sound through your skull. Pearson’s tuning-fork experiment is about your skeleton conducting vibration better than air. There is no firmware analog because there is no “skull” in the firmware. The amplifier (the PCM5102A and the LM4853 or similar headphone amp) is the closest analog: it does for the audio signal what your skull does for the tuning fork.