c. Loading and Playing Audio Files (TO BE VERIFIED)

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 11 - Audio Primitives >

c. Loading and Playing Audio Files (TO BE VERIFIED)

This section shows how to play the WAV (Waveform Audio File Format) files using the AudioPlay() command.

 

 

Command Prototype

 

uint16_t AudioPlay(const char* Filename,int16_t Mode);

 

Parameters

Description

Filename

Complete path of the WAV file

Mode

0 - PLAY_WAIT, 1 - PLAY_ONCE and 2 - PLAY_LOOP

 

 

Code

 

 

void setup()

{

 /* Initialize CleO - needs to be done only once */

   CleO.begin();

 

 /* Get handles to icons */

   icon_play = CleO.LoadIcon("@Icons/m48.ftico", ICON_PLAY_CIRCLE_FILLED);

   icon_loop = CleO.LoadIcon("@Icons/m48.ftico", ICON_REPLAY);

   icon_stop = CleO.LoadIcon("@Icons/m48.ftico", ICON_STOP);

 

  /* Start building a screen frame */

   CleO.Start();

   CleO.BitmapJustification(MM);

 

  /* Display and tag play icon */

   CleO.Tag(100);

   CleO.Bitmap(icon_play, 160, 100);

 

  /* Display and tag loop icon */

   CleO.Tag(101);

   CleO.Bitmap(icon_loop, 160, 200);

 

 /* Display and tag stop icon */

   CleO.Tag(102);

   CleO.Bitmap(icon_stop, 160, 300);

 

  /* Display completed screen frame */

   CleO.Show();

}

 

void loop()

{

   int16_t x, y, dur, tag;

 

  /* Check for screen touch */

   CleO.TouchCoordinates(x, y, dur, tag);

  /* Pen down */

   if (previousDur == 0 && dur != 0)

   {

       previousTag = tag;

       previousDur = 1;

   }

 /* pen up */

   else if (previousDur != 0 && dur == 0)

   {

       previousDur = 0;

       switch (tag)

   {

      /* upon play icon press event */

       case 100:

            CleO.AudioPlay("@Music/stinger.wav", PLAY_ONCE);

            break;

      /* upon loop icon press event */

       case 101:

           CleO.AudioPlay("@Music/stinger.wav", PLAY_LOOP);

           break;

      /* upon stop icon press event */

       case 102:

           CleO.AudioStop();

           break;

       }

   }

}

 

 

Description

 

In the above code snippet, the Setup() routine loads the icons which are used for touch to play, loop and stop the sound.

The bitmaps are then drawn at (160,100),(160,200) and (160,300).

The loop routine checks for the touch coordinates using the TouchCoordinates() command.

Based on the user touch, the tag will hold the corresponding bitmap tag value.

Users will be able to know which bitmap was affected using this tag value.

The AudioPlay() command is used to play the sound with the WAV file and the play mode passed as an argument.

Use the @ symbol only when performing the file operation from the eFlash and not from the SD Card.