WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Audio/SOMO14D.h

The SOMO14D is an audio file playback device.
Manufactured by 4D Systems see http://www.4dsystems.com.au/prod.php?id=73 but available from other outlets such as SparkFun.
somo14d.jpg
The micro sdCard (up to 2Gb) can hold up to 512 audio tracks in 'ad4' format. Check their website for a free utility to convert from other audio file formats. Each file name must be a 4 digit number, with leading zeroes', and an extension of '.ad4' ie '0000.ad4' to '0511.ad4'. This allows the files to be accessed by number rather than by name.
The device requires a 3.3v VCC supply as well as a common GND. Their data sheet shows how it can be powered from a 5v supply by the addition of some diodes to reduce the voltage.
The device is controlled by connecting two pins from your micro controller to the CLK and DATA pins. NB if your micro controller output pins are 5V then you need to add a 100 ohm resistor in series with each of these lines to allow for the fact that the SOMO is running at 3.3V.
An optional third wire can be connected from the BUSY output to your micro controller (no extra resistor need) so that your program can sense whether a sound file is still being played.
A loudspeaker can be connected directly to the SPK+ and SPK- outputs or the AUDIO output can be used with an external amplifier - see the data sheet.
You could use this device for playing background music, sound effects, speaking sentences, or you could store individual words as individual files and then play one after another to make up sentences on the fly.
Here is a very simple example that just plays a sound when the Axon is powered up:
#include <sys/axon.h>
#include <Audio/SOMO14D.h>
 
// Define the SOMO device
SOMO14D audio = MAKE_SOMO14D(F6,F5,NULL);
 
// Initialise the hardware
void appInitHardware(void) {
    // Initialise the SOMO
    somo14D_init(&audio);
}
 
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
// Play file '0000.ad4'
somo14D_play(&audio,0);
return 0;
}
 
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
// Nothing to do
return 0;
}
Here is another example that strings individual sounds together into a sequence so that they are played as single effect. Because we need to know when each individual sound has finished, so that we can start the next one in the sequence, then we need to use the third parameter of the MAKE_SOMO14 command.
#include <sys/axon.h>
#include <Audio/SOMO14D.h>
 
SOMO14D audio = MAKE_SOMO14D(F6,F5,F7);
 
// Sequence of sound numbers ending in -1
int16_t effect1[] = { 1, 20, 15, 6, -1 };
int16_t effect2[] = { 1, 4, 5, -1 };
 
// Current sequence being played,
// initial value is NULL
int16_t* seqPos;
 
// Initialise the hardware
void appInitHardware(void) {
    // Initialise the SOMO
    somo14D_init(&audio);
}
 
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
    return 0;
}
 
// Start playing a sequence of sounds
void play(int16_t* effect){
    // Stop any current playback
    somo14D_stop(&audio);
    seqPos = effect;
 
    // Start playing the first
    // sound in the sequence
    somo14D_play(&audio,*seqPos);
}
 
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
    // If we are playing a sequence
    if(seqPos){
        // And the current sound has finished
        if(!somo14D_isBusy(&audio)){
            // Move to next sound in sequence
            seqPos ++;
            if(*seqPos==-1){
                // Sequence has finished
                seqPos = NULL;
            }else{
                // Play next sound in sequence
                somo14D_play(&audio, *seqPos);
            }
        }
    }
 
    // All your other code goes here ie reading sensors,
    // controlling motors, servos etc.
 
    // Pseudo code
    if( robot has hit something){
        play(effect1); // Say "I banged my head"
    }else if( robot has fallen over){
        play(effect2); // Say "Ouch. What happened"
    }
 
    return 0;
}

 

Function

 


MAKE_SOMO14D(const IOPin* clk,const IOPin* data,const IOPin* busy)

Create a SOMO14D device.
The first two parameters are compulsory and specified the digital output pins to use to connect to the CLK and DATA pins of the SOMO14D. Note that if your micro controller has a Vcc of more than 3.3V then you will need to add a 100 ohm resistor on each of these lines.
The third parameter is optional and can either be NULL or a digital input pin to connect to the BUSY pin on the SOMO14D. This pin is only required if you want to use the somo14D_isBusy command.

somo14D_init(const SOMO14D* device)

Initialise the SOMO14D device.
This must be called from appInitHardware before any other somo14d functions can be used.

boolean somo14D_isBusy(const SOMO14D* device)

Returns TRUE if the device is currently playing a file.
To use this command you must have specified a IO pin in the third parameter of your MAKE_SOMO14D command and connect this to the BUSY output of the device.

somo14D_play(const SOMO14D* device, uint16_t fileNum)

Start playing the specified file number, in the range 0 to 511, on the device.
If another sound is currently being played then it will be stopped before playing the new file.

somo14D_stop(const SOMO14D* device)

Stop playing any current sound file.

somo14D_volume(const SOMO14D* device, uint8_t volume)

Set the volume level on the device to value between 0 (quietest) and 7 (loudest).

Valid XHTML 1.0 Transitional