SIM800L - Play wave file from Arduino DAC to microphone

Telephone quality audio is sampled at 8 kHz, and each sample is 8 bits.

So every second of audio is 64 kilobits, or 8 kilobytes. Ten seconds is 80 kB.

On my microcontroller, I use the SIM cell tower ID to get the device's longitude and latitude, and then I compose a sentence like:

I am located at 51.5007° north and 0.1246° west.

I then use a text-to-speech engine to convert this sentence into an 8-Bit mono 8kHz wave file. The wave file will be about 10 seconds long, for a total of 80 kilobytes. I store these 80 kilobytes in a global array:

char unsigned samples[8000ul * 10ul];  /* 10 seconds of 8-Bit at 8 kHz */

So next I wait for a phone call to come in on the SIM800L, and my microcontroller sees the "RINGING" message come in. My microcontroller answers the call. I have DAC pin on my microcontroller connected to the "MIC" pin on the SIM800L.

So here's what I'm thinking I'll do:

(Step 1) Set a global pointer to the beginning of the array:

char unsigned const *ps;

void PlayAudio(void)
{
    ps = samples;
}

(Step 2) Enable an timer interrupt that fires at a frequency of 8 kHz (i.e. once every 125 microseconds)

char unsigned const *ps;

void PlayAudio(void)
{
    ps = samples;
    timerAlarm(mytimer, 125u, true, false);
}

(Step 3) Inside the interrupt routine, write the current sample to the DAC pin:

void InterruptRoutine(void)
{
    // Write an 8-Bit audio sample as a
    // voltage to the DAC output pin
    dacWrite( DAC_CH1,  *ps++ );

    // The next line brings the pointer back to
    // the beginning if it goes past the end
    // (so the audio repeats forever)
    if ( ps >= samples[sizeof samples] ) ps = samples;
}

I haven't coded this yet but I think it should work. The output voltage range of the DAC might not match the input voltage range of the MIC pin, but I can use a resistor ladder to match them.

Has anyone already tried this and gotten it working? Anyone got any thoughts to share?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.