b /lib: Learn, Imagine, Build Audio | /lib

/lib

Learn, Imagine, Build
Geoff Messier's Projects & Ideas

Audio

Of course, we want robot frogs to talk!

Capturing Audio Clips

Audio clips are currently captured from YouTube, recorded using Screenflow and then exported in AIFF format. At that point, they’re loaded into Audacity, converted to mono and exported as header-less unsigned 8-bit PCM files at a sample rate of 44.1~kHz. The pulse coded modulation (PCM) seems just to be the raw 8 bit sample values.

Electronics

Sound is expressed in decibels which, of course, is just a ratio of relative powers. The reference level chosen for audio is the 0.02~mPa (the pressure of air) so audio levels are given by $20\log_{10} A/0.02$, where $A$ is the pressure of the sound on your ears. Generally, 10~dB is approximately as loud as someone breathing and 60~dB is as loud as a conversation.

Consider the 8~ohm, 800~mW SP-1605 speaker (Digikey Part: 433-1104-ND). The speaker is rated to deliver 88~dB at 1~W (an extrapolated value since the speaker can’t take 1~W) and let’s assume we want a volume range from 50~dB to 68~dB. That corresponds to a maximum and minimum power of

\(\begin{array}{cc} P_{\rm max} = 30 - 20 = 10~{\rm dBm} & P_{\rm min} = 30 - 38 = -8~{\rm dBm} \end{array}\)

Assume a sinusoidal tone and that these powers are RMS so that the peak current through the speaker to get these power levels is $i = \sqrt{2P/R}$, where $R$ = 8~ohms. This means the min and max currents are 50~mA and 6.3~mA to get the volume range we want. The max output current sourced by the PIC 16x op-amp is 100~mA so this is within our range. The peak voltage across with 8~ohm speaker will vary between 400~mV and 50.4~mV.

Utilizing a non-inverting op-amp amplifier design, the positive op-amp input terminal will be connected internally in the PIC to the DAC output and the negative input will be connected to a grounded resistor $R_1$ and a second variable resistor $R_f$ connected to the output terminal. The output voltage is given by $V_o = (1+R_f/R_1)V_i$. Note that the minimum gain of the amplifier is unity when $R_f$ = 0.

Assuming the 10-bit DAC is used, the maximum voltage value is $V_{DD}$. Since our audio files only us the bottom 8 bits, the maximum input voltage to the op-amp will vary between 0~V and $V_DD \cdot 256/1024$ = 825~mV. Since we’re using a DC blocking cap, can assume we’re working with a zero DC offset sinusoid with a peak voltage of $825/2$ = 412.5~mV.

Since this voltage is greater than our target maximum voltage even with no amplification, we need to put a resistor in series with the speaker. Assuming a minimum amplifier gain of unity, the series resistance is equal to

\(R_s = 412.5/50.4 \cdot (8 - 8 \cdot 50.4/412.5) = 57.5\ \Omega\)

We require a linear voltage gain that varies between unity and 8. Assuming $R_1$ = 410~Ohm, $R_f$ needs to vary between 0~Ohm and $820 \cdot (8-1)$ = 2.87~kOhm.

Finally, a blocking capacitor must be used to remove the DC offset of the signal generated by the op-amp. This capacitor in series with the load resistance forms a high-pass filter with a 3~dB cutoff given by $f_c = 1/(2\pi R C)$. For a 4~Hz cutoff frequency and load resistance of 35~Ohms, the required series capacitor is 607.5~uF.