Arduino audio shield keeps crashing


i used have no problems playing audio off waveshield + diecimila. i.e. play different audio files off of card , have audio re-triggered etc.

then hooked arduino via i2c , had play preset filename based on receiving specific single character command. worked well.

now have reading in filename , getting crashes.

it play audio file once , needs restarted.

any idea wrong?

here code pieces:

filename variable:

code: [select]
char audiofilename[12];

my i2c receive function:
code: [select]
/ function executes whenever data received master
// function registered event, see setup()
void receiveevent(int howmany)
{
 char command;
 byte i=0;
 while (true)
 {
   if (wire.available())
   {
     command = wire.receive();
     break; // exit loop when sentinel arrives
   }
 }
 
 switch (command)
 {
   case play_audio:
       memset(audiofilename, 0, sizeof(audiofilename));
       while (true)
       {
         if (wire.available())
         {
           byte c  = wire.receive();
           audiofilename[i++] = c;
           if (c == 0) break; // exit loop when sentinel arrives
         }
        }
       busy = 1;
       //playcomplete(audiofilename);
       playfile(audiofilename);
       busy = 0;
       break;
      // print integer
 }
}  


playback functions:
code: [select]
void playcomplete(char *name)
{
 playfile(name);
 while (wave.isplaying);
 card.close_file(f);
}


void playfile(char *name)
{
 // stop file playing
   if (wave.isplaying) {
     wave.stop();
   }
   // close file if open
   if (f) {
     card.close_file(f);
   }
   // play specified file
   f = card.open_file(name);
   if (f && wave.create(f)) {
     wave.play();
   }
}


when arduino starts up, can play audio files no problem (i have play startup sound).

but later when call functions have problems.

if call 'playcomplete" play tiny chunk of audio , freeze.

if call playfile play whole thing , freeze.

do need declare "audiofilename" being volatile?
can see wrong???

i wonder if having ram problems??

there non stop problems. wonder if including wiring.h library?

i further debug returning original sample code , no i2c connections confirm there nothing wrong hardware.

i try re-formatting sd card, using different 1 , trying other programs convert files (i used sound forge , saw note somewhere else said had issues sf conversions in comparison using audacity).

here current code, if can see suspicious appreciative!

code: [select]
#include <avr/pgmspace.h>
#include <af_wave.h>
#include <wire.h>
#include "util.h"
#include "wave.h"

//commands received via i2c
#define play_audio                'p'
#define terminating_character      0

#define audio_filename_size  13

#define audio_board_i2c_address 3

volatile byte busy = 0;


af_wave card;
file f;
wavefile wave;
char audiofilename[13];    //buffer filename received via i2c




void setup()
{
 // set audioshield pins
   for (byte = 2; <= 5; ++i)
   {
     pinmode(i, output);
   }
   
   // open memory card
 if (!card.init_card())
 {
   putstring_nl("card init failed!"); return;
 }
 if (!card.open_partition())
 {
   putstring_nl("no partition!"); return;
 }
 if (!card.open_filesys())
 {
   putstring_nl("couldn't open filesys"); return;
 }
 if (!card.open_rootdir())
 {
   putstring_nl("couldn't open dir"); return;
 }
 
 //delay(10);
 playcomplete("r2d2.wav");
 
 
 wire.begin(audio_board_i2c_address);                // join i2c bus address
 wire.onreceive(receiveevent); // register event
 wire.onrequest(requestevent);
 
}
 
void loop()
{
}
   
// function executes whenever data received master
// function registered event, see setup()
void receiveevent(int howmany)
{
 char command;
 byte i=0;
 while (true)
 {
   if (wire.available())
   {
     command = wire.receive();
     break; // exit loop when sentinel arrives
   }
 }
 
 switch (command)
 {
   case play_audio:
       memset(audiofilename, 0, sizeof(audiofilename));
       while (true)
       {
         if (wire.available())
         {
           byte c  = wire.receive();
           audiofilename[i++] = c;
           if (i == audio_filename_size && c != 0)  //if 13th charcter received not null received filename bigger allowed
           {
             audiofilename[i-1] = 0;   //replace last character of array null array terminated
             break;
           }
           if (c == 0) break; // exit loop when sentinel arrives
         }
        }
       busy = 1;
       playcomplete(audiofilename);
       //playfile(audiofilename);
       busy = 0;
       break;
 }
}  

void playcomplete(char *name)
{
 playfile(name);
 while (wave.isplaying);
 card.close_file(f);
}


void playfile(char *name)
{
 // stop file playing
   if (wave.isplaying) {
     wave.stop();
   }
   // close file if open
   if (f) {
     card.close_file(f);
   }
   // play specified file
   f = card.open_file(name);
   if (f && wave.create(f)) {
     wave.play();
   }
}


/////////////////////////////////////////////////////////////
//  returns 1 master if audio functions complete (not busy)
/////////////////////////////////////////////////////////////
void requestevent()
{
 if (busy)
   wire.send(0); // respond message of 1 byte
   else wire.send(1);
                      // expected master tos ignify command completion
}


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Arduino audio shield keeps crashing


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums