This complete sampler built in a cigar box is a good starting point for getting into low level sound sampling with the Critter Board. The cigar box sampler uses a Critter Board with a flash card socket to record up to 30 seconds of sounds onto flash cards. The sound can be played back using the three knobs on the bottom to control loop points and speed. The cards may also be used with other instruments such as the Pink Prairie Guitar or the ugly guitar.
On the front is a 1/4" sound input jack and 9v power jack. In addition to the built in amplifier and speaker, there is a sound output jack on the back.
The sound input feeds into this circuit. The circuit provides some amplification and scales the audio to the 0 - 3.3 volt range. The audio circuit is conneted right to one of the LPC2138s ADC inputs. Also in the picture is a small amplifier that powers the internal speaker.
Notice also that the sound output jack and power input jack on the Critter Board are not used. In this case it was easier to use panel mounted jacks for power and sound, and we also wanted 1/4" jacks. Conveniently the Critter Board provides headers for these connections in addition to the on-board jacks.
The following connections are made to the Critter Board. In addition, the audio input circuit has a pot to control gain, and there is a pot connected to the volume control header on the Critter Board to control output volume.
The mode switch is a 3 position switch (on-off-on) that selects the function of the sampler. When the switch is in the center position, the sampler is playing in reverse. When the switch is down, the sampler plays forward. And when the switch is up, the sampler is in record mode.
In record mode the button is used to erase the flash memory and record a new sample. The first time the button is pressed after flipping the switch up starts the erase sequence. This takes a few seconds, during which the LED on the flash card is on. When the erase sequence is complete a timer interrupt is started that samples the audio input at around 16 KHz. The LED on the flash card becomes a peak indicator and flashes whenever the input is over -3dB. Pressing the button at this point records the sound to flash memory as long is it is held down. When the memory is full (about 30 seconds), the sampler jumps back into play mode.
In play mode (forward and reverse), the knobs control loop start point, loop length, and rate. The sample play rate is changed by adjusting the actual sample rate used during playback.
The source code is available below. There are three files specific to this tutorial: sample_play.c, sample_record.c, and m25pxx.c. sample_record.c contains functions for recording from a line in (as used in this example) and also writing sample values received from the UART. Using these functions allow samples to be downloaded from a computer.
Downloads: