Program to record speech audio into RAM and then play it back, moving Billy Bass's mouth in sync with the speech.

Dependencies:   mbed

Remember Big Mouth Billy Bass?

I've made a simple demo program for him using the Freescale FRDM-KL25Z board. I've hooked up the digital I/O to his motor driver transistors and pushbutton switch.

This program records 1.8 seconds of speech audio from ADC input when the pushbutton is pressed, then plays the audio back with Billy Bass's mouth controlled so that it opens during vowel sounds.

The ADC input is driven from a microphone and preamplifier, via a capacitor and into a resistor divider connected to the +3.3V supply pin to provide mid-range biasing for the ADC signals.

The DAC output is connected to his audio amplifier input (to the trace that was connected to pin 10 of the controller IC). I had to provide a DC bias using the DAC to get the single transistor amplifier biased into proper operation.

For more on the method of vowel recognition, please see the paper:

Y. Nishida, Y. Nakadai, Y. Suzuki, T. Sakurai, T. Kurokawa, and H. Sato. 1999.

Voice recognition focusing on vowel strings on a fixed-point 20-MIPS DSP board.

In Proceedings of the Acoustics, Speech, and Signal Processing, 1999. on 1999 IEEE International Conference - Volume 01 (ICASSP '99), Vol. 1. IEEE Computer Society, Washington, DC, USA, 137-140. DOI=10.1109/ICASSP.1999.758081



File content as of revision 7:f0e5450449cb:

#ifndef __included_fast_analog_in_h
#define __included_fast_analog_in_h

#include "mbed.h"

namespace NK

using namespace mbed;
extern "C" void ADC0_IRQHandler(void);

class FastAnalogIn: public mbed::AnalogIn
    void start_read() {
        ADC0->SC1[0] = ADC_SC1_ADCH(_adc.adc)
                       | ADC_SC1_AIEN_MASK;     // enable interrupt

    void abort_read() {
        ADC0->SC1[0] = ADC_SC1_ADCH(0x1F);

    uint16_t read_u16() {
        // Wait Conversion Complete
        while ((ADC0->SC1[0] & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK);

        // Return value
        return (uint16_t)ADC0->R[0];

    uint16_t read_u16_nowait() {
        return (uint16_t)ADC0->R[0];

    // 0x0000 => 0x80 (-128)
    // 0x7fff => 0xFF (-1)
    // 0x8000 => 0x00 (0)
    // 0xffff => 0x7f (127)
    int8_t read_s8_nowait() {
        int32_t val = read_u16_nowait();
        return (val + 0x80 - 0x8000) >> 8;

    FastAnalogIn(PinName pin)
        : mbed::AnalogIn(pin) {

        NVIC_SetVector(ADC0_IRQn, (uint32_t)&ADC0_IRQHandler);

        ADC0->CFG1 = ADC_CFG1_ADLPC_MASK    // Low-Power Configuration
                     | ADC_CFG1_ADIV(4)       // Clock Divide Select: (Input Clock)/4
                     | ADC_CFG1_ADLSMP_MASK   // Long Sample Time
                     | ADC_CFG1_MODE(3)       // (16)bits Resolution
                     | ADC_CFG1_ADICLK(1);    // Input Clock: (Bus Clock)/2

        ADC0->CFG2 = 0   // ADxxA channels are selected
                     | ADC_CFG2_ADACKEN_MASK    // Asynchronous Clock Output Enable
                     | ADC_CFG2_ADHSC_MASK      // High-Speed Configuration
                     | ADC_CFG2_ADLSTS(0);      // Long Sample Time Select

        ADC0->SC2 = ADC_SC2_REFSEL(0);      // Default Voltage Reference

        ADC0->SC3 = ADC_SC3_AVGE_MASK       // Hardware Average Enable
                    | ADC_SC3_AVGS(3);        // 16 Samples Averaged

        ADC0->SC1[0] = ADC_SC1_ADCH(_adc.adc)
                       | ADC_SC1_AIEN_MASK;     // enable interrupt

    void enable_interrupt() {
    void disable_interrupt() {