Combining code to make a new Program

Hi,

I am hoping someone here will be able to help me with a programming issue I am having.

My hardware set up is a Uno with a Adafruit Arduino Wave Shield attached and an IR sensor attached to the appropriate pins (Ground, 3v, Digital IO 11). I am using DVD remote control to send its commands to the IR sensor.

Both the WaveHC library and Infrared remote library for Arduino are installed and working; Sketches uploaded to the board work as expected. The Wave Shield will play all its .wav files in a loop using the daphc.pde sketch and the IR sensor picks up the remote control commands and prints them to the serial monitor using the IRrecvDemo.pde sketch

Info about the Wave Shield here: Audio Shield for Arduino
Info about Infrared remote library for Arduino here: A Multi-Protocol Infrared Remote Library for the Arduino

What I would like to achieve is a sketch that reads the remote control commands from the DVD remote being picked up by the IR sensor and uses these to make the Wave Shield to play different .wav files.

I am thinking this should be simple enough but I am not having any joy using the 2 libraries to get it to do what i want. It really comes down to my lack of experience and understanding of coding.

If you have any suggestions of how to combine the pieces of code together to make a remotely triggered audio player, I am all ears!!!!

Thanks

Tim

Have you got some code showing how you have tried to combine the functions together ? Do you get any error messages when you try to compile the code ?

The usual problem when combining 2 working programs is that the originals both use the same resources. Sometimes you can change this easily but in other cases the libraries conflict.

Thanks for you reply.

I am really not sure how to combine the code in such a way that it will work. I've included both libraries at the start and I am sure there is no conflict of resources, as far as I can tell... My problem is I do not know how to construct code and I am basically hoping someone here will be able to guide me through the process.

Example of code I've tried...;

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#include <IRremote.h>




SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 100  // button debouncer

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with 6 buttons");
  
   putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);
 
  // enable pull-up resistors on switch pins (analog inputs)
  digitalWrite(11, HIGH);
 int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}

void loop() {
  //putstring(".");            // uncomment this to see if the loop isnt running
  switch (check_switches()) {
    case 1:
      playcomplete("DTMF7.WAV");
      break;


  }
}

byte check_switches()
{
  static byte previous[6];
  static long time[6];
  byte reading;
  byte pressed;
  byte index;
  pressed = 0;

  for (byte index = 0; index < 6; ++index) {
    reading = digitalRead(14 + index);
    if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE)
    {
      // switch pressed
      time[index] = millis();
      pressed = index + 1;
      break;
    }
    previous[index] = reading;
  }
  // return switch number (1 - 6)
  return (pressed);
}


// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
}

Randomly pasting partial functions into source code is never a good strategy.
What happens when you get rid of the partial "freemem" ?

Randomly pasting partial functions into source code is never a good strategy.

Yes, I did kind of know that... still did it though, hoping to learn something...

What happens when you get rid of the partial "freemem" ?

I don't know... could you let me know?

Thanks for the bit of code... how does it relate to reading the IR sensor and playing waves?

Thanks for the bit of code...

It's your code - I just cut it out to highlight that you can't paste partial functions just anywhere.

I don't have your hardware, so I'm not even going to try your code.

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

// CUT OUT AND LOSE FROM HERE...
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 
// ...TO HERE

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {

I see... thanks for putting the comments in.
That part of code is from the Wave shield code and I didn't change it.

Maybe if you or someone who has the time and patience can take a look at the two sketches separately and come up with a way to get the IR senor results to trigger waves.... I am really not fluent in c++ coding at this level to make this work, so please help if you can!

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 5  // button debouncer

// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19};
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'pressed' (the current state
volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  byte i;
  
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with ");
  Serial.print(NUMBUTTONS, DEC);
  putstring_nl("buttons");
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);
 
  // Make input & enable pull-up resistors on switch pins
  for (i=0; i< NUMBUTTONS; i++) {
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH);
  }
  
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
  
  TCCR2A = 0;
  TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;

  //Timer2 Overflow Interrupt Enable
  TIMSK2 |= 1<<TOIE2;


}

SIGNAL(TIMER2_OVF_vect) {
  check_switches();
}

void check_switches()
{
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  byte index;

  for (index = 0; index < NUMBUTTONS; index++) {
    currentstate[index] = digitalRead(buttons[index]);   // read the button
    
    /*     
    Serial.print(index, DEC);
    Serial.print(": cstate=");
    Serial.print(currentstate[index], DEC);
    Serial.print(", pstate=");
    Serial.print(previousstate[index], DEC);
    Serial.print(", press=");
    */
    
    if (currentstate[index] == previousstate[index]) {
      if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
          // just pressed
          justpressed[index] = 1;
      }
      else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
          // just released
          justreleased[index] = 1;
      }
      pressed[index] = !currentstate[index];  // remember, digital HIGH means NOT pressed
    }
    //Serial.println(pressed[index], DEC);
    previousstate[index] = currentstate[index];   // keep a running tally of the buttons
  }
}


void loop() {
  byte i;
  
  if (justpressed[0]) {
      justpressed[0] = 0;
      playcomplete("DO.WAV");
  }
  if (justpressed[1]) {
      justpressed[1] = 0;
      playcomplete("RE.WAV");
  }
  if (justpressed[2]) {
      justpressed[2] = 0;
      playcomplete("MI.WAV");
  }
  if (justpressed[3]) {
      justpressed[3] = 0;
      playcomplete("FA.WAV");
  } 
  if (justpressed[4]) {
      justpressed[4] = 0;
      playcomplete("SO.WAV");
  } 
  if (justpressed[5]) {
      justpressed[5] = 0;
      playcomplete("LA.WAV");
  }
}



// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}
/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

Combining two things you don't understand into a bigger thing you don't understand usually leads to poor results, as you and Dr. Frankenstein have both discovered.

You stated you had the audio part working competently. Do you have the IR stuff working in a testbed of its own? If not, you might find that you understand it well enough after getting it working on its own to figure out how to integrate it into the audio sketch.

In other words, get a firm understanding of the pieces and you'll be better positioned to merge the parts you want. Most people who have trouble at the stage you are in are stuck in denial about needing to understand the code.

-br

Hi, Please see: http://arduino.cc/forum/index.php/topic,159406.0.html

This is a common problem and I'm trying to create good guidelines to make it easier.

Combining two things you don't understand into a bigger thing you don't understand usually leads to poor results, as you and Dr. Frankenstein have both discovered.

Thanks :wink: My plan is to get there and understand how it works...

Thank you too TK, I will read up...

Audio part works fine on its own. So does the IR sensor. It reads the messages from the remote and prints the results to the Serial Monitor window in either Hex or Dec, which ever I choose. Each button gives a different result. I would like the sketch to read these results and if it makes a match, to play a sound file via the wave shield.

My understanding of how this should/could work is that it would run the IR receive loop, read the results, if it receives for example a result of "1261738087" then it would goto the WaveHC part of the sketch to play a sound.

I've had no problems with the simple sketches, understanding the basics and learning the A,B C's of Arduino It is just getting to that next level that has always stumped me. I have no problem understanding and using object based programming like maxMSP. Arduino and c++ really twists my brain.

...so if you still feel that you could help me, could you break it down into easier to handle chunks?

Cheers :slight_smile:

It looks like a little tweaking would get it to compile at least. You appear to have pasted versions of setup and loop into the middle of your freeRam function - move them up above it. Then you'll have the issue of having two versions each of those two functions, so you'll need to combine them. Copy everything from the smaller versions into the larger and delete the original.

Both setups setup the serial port, only need one.

In the remaining loop, just run the decode function for now. Observe what it returns through the serial port when you press a particular button. Test for that & then add the code you have that plays a wave file.

I suspect that this last bit will be a struggle. You should be able to get a lot closer to a compilable program though. Post that version and any errors you get if you get stuck.

Here is the IR Remote program with a slight amendment

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    Serial.println(results.value);
    
    if (results.value == 0xFF00FF)
    {
      Serial.println("!");
    }
    irrecv.resume(); // Receive the next value
  }
}

The only difference is that when the code FF00FF (in HEX) is received it prints an exclamation mark. Not very exciting, but if you look at the other program you posted it plays a particular file when it receives a button press so you should see that it would not be that difficult to do what you want.

Thanks very much UKHeliBob and wildbill, Morning here now so I can jump back into this again

That last bit of code was very helpful. From it I have come up with this;

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
      //Serial.println(results.value, HEX);
    //Serial.println(results.value);
    
    if (results.value == 0x4B3408F7)
    {
      Serial.println("ONE");
       }
       
   if (results.value == 0x4B348877)    
       {
      Serial.println("TWO");
       }
       
        if (results.value == 0x4B3448B7)    
       {
      Serial.println("THREE");
       }
       
        if (results.value == 0x4B34C837)    
       {
      Serial.println("FOUR");
       }
       
        if (results.value == 0x4B3418E7)    
       {
      Serial.println("FIVE");
       }
       
        if (results.value == 0x4B349867)    
       {
      Serial.println("SIX");
       }
       
        if (results.value == 0x4B3458A7)    
       {
      Serial.println("SEVEN");
       }
       
        if (results.value == 0x4B3430CF)    
       {
      Serial.println("EIGHT");
       }
       
        if (results.value == 0x4B34B04F)    
       {
      Serial.println("NINE");
      }
       
       
       
       
    irrecv.resume(); // Receive the next value
  }
}

May not be the most elegant way of doing it, but it works

This sketch outputs the numerals 1 - 9 in the serial monitor corresponding to numerals 1 - 9 being pushed on the remote. I've also commented out the Serial.PrintIn as I no longer need to see the extra data. For me this is a bit of a win in understanding what is going on- Thanks UKHeliBob. Next step is to link these to play individual sound files once.

wildbill, Your suggestion seems logical, however I am having trouble understanding the parts of the WaveHC code. I am not sure where each function really starts and ends. I will hack away at in some more as things are getting slightly clearer...

Any suggestions on where exactly to insert each part would be greatly appreciated!

Cheers

Got it working thanks to the very helpful people at Artifactory http://artifactory.org.au/ who helped me through the coding.

This is how it ended up...

#include <IRremote.h>

#include "WaveUtil.h"
#include "WaveHC.h"


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time


int RECV_PIN = 6;

IRrecv irrecv(RECV_PIN);

decode_results results;

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}


void setup()
{
  Serial.begin(9600);
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  

// enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }


  irrecv.enableIRIn(); // Start the receiver

  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}

void loop() {
    //putstring_nl("Playing DO.WAV");
     // playcomplete("DO.WAV"); 


    if (irrecv.decode(&results)) {
     //Serial.println(results.value, HEX);
     //Serial.println(results.value);

     switch(results.value) {
       case 0x4B3408F7: Serial.println("1");  playfile("CUE01.WAV"); break;
       case 0x4B348877: Serial.println("2");  playfile("CUE02.WAV"); break;
       case 0x4B3448B7: Serial.println("3");  playfile("CUE09.WAV"); break;
       case 0x4B34C837: Serial.println("4");  playfile("CUE04.WAV"); break;
       case 0x4B3418E7: Serial.println("5");  playfile("CUE05.WAV"); break;
       case 0x4B349867: Serial.println("6");  playfile("CUE06.WAV"); break;
       case 0x4B3458A7: Serial.println("7");  playfile("CUE07.WAV"); break;
       case 0x4B3430CF: Serial.println("8");  playfile("CUE08.WAV"); break;
       case 0x4B34B04F: Serial.println("9");  playfile("CUE10.WAV"); break;
     }
        
     irrecv.resume(); // Receive the next value
  }
  
}


// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file ");
    putstring(":");
    Serial.print(name);
    putstring_nl(":");
    return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}

Hi, Glad you got it working!

In the spirit of helping other people with the difficult task of combining sketches, I have reorganized and commented your example in the way I usually organize examples.

I think it's important to show where the libraries came from; Newbies are often stuck on that.

It verifies OK but I don't have the hardware to test it. Try it if you can.

Here's the way I would organize and comment a combined sketch:

/* YourDuinoStarter Example: Sketch Template
 - WAVEHR_IR_Control
 - WHAT IT DOES: Plays wave files on Wave shield, Controlled by IR REmote
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
   - IR Reciever on Pin 6
   - Wave Shield
 - V1.00 04/11/13
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
// IR Remote Library: https://github.com/shirriff/Arduino-IRremote
#include <IRremote.h>
// WaveHC Library: https://code.google.com/p/wavehc/
#include "WaveUtil.h"
#include "WaveHC.h" 

/*-----( Declare Constants and Pin Numbers )-----*/
int RECV_PIN = 6;

/*-----( Declare objects )-----*/
SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we'll play
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time
IRrecv irrecv(RECV_PIN);
decode_results results;

/*-----( Declare Variables )-----*/


void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  

// enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }


  irrecv.enableIRIn(); // Start the receiver

  // Whew! We got past the tough parts.
  putstring_nl("Ready!");

}//--(end setup )---



void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
    //putstring_nl("Playing DO.WAV");
     // playcomplete("DO.WAV"); 


    if (irrecv.decode(&results)) {
     //Serial.println(results.value, HEX);
     //Serial.println(results.value);

     switch(results.value) {
       case 0x4B3408F7: Serial.println("1");  playfile("CUE01.WAV"); break;
       case 0x4B348877: Serial.println("2");  playfile("CUE02.WAV"); break;
       case 0x4B3448B7: Serial.println("3");  playfile("CUE09.WAV"); break;
       case 0x4B34C837: Serial.println("4");  playfile("CUE04.WAV"); break;
       case 0x4B3418E7: Serial.println("5");  playfile("CUE05.WAV"); break;
       case 0x4B349867: Serial.println("6");  playfile("CUE06.WAV"); break;
       case 0x4B3458A7: Serial.println("7");  playfile("CUE07.WAV"); break;
       case 0x4B3430CF: Serial.println("8");  playfile("CUE08.WAV"); break;
       case 0x4B34B04F: Serial.println("9");  playfile("CUE10.WAV"); break;
     }
        
     irrecv.resume(); // Receive the next value
  }

}//--(end main loop )---


/*-----( Declare User-written Functions )-----*/


//----------------( freeRam )------------------------------------------------------------------
// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

//----------------( sdErrorCheck )------------------------------------------------------------------

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

//----------------( playcomplete )------------------------------------------------------------------
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}


//----------------( playfile)------------------------------------------------------------------
void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file ");
    putstring(":");
    Serial.print(name);
    putstring_nl(":");
    return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}

//*********( THE END )***********