/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef INCLUDED_Sound_h
#define INCLUDED_Sound_h

#include "MotionInterface.h"

namespace Motion {

/*------------------------------------------------------------------
CLASS
  WavFile

DESCRIPTION
  Loads wav files and stores the data.
------------------------------------------------------------------*/
class WavFile {
public:
  WavFile();
  ~WavFile();

  bool load(const char *filename);
  ulong getDataSize() {return dataSize;};
  char *getData() {return data;};
private:
  bool parseData();

  static const ulong MaxDataSize = 200000;
  char *data;
  ulong dataSize;
};

/*------------------------------------------------------------------
CLASS
  Sound

DESCRIPTION
  Handling of sounds available to the robot.
------------------------------------------------------------------*/
class Sound {
public:
  Sound();
  void init();
  void setSpeakerSamplingRate(int sample_rate);
  void load();

  void setCommand(MotionCommand &ncmd);
  void getSoundData(char *data,int data_size);
private:
  char sin8[256];
  int sampling_rate;

  int sound_cmd; // one of commands from MotionInterface.h that is currently being executed
  unsigned long  sound_duration;
  unsigned short sound_frequency;
  unsigned short sound_file;
  bool repeat_file;

  unsigned long sound_time;

  bool valid[NUM_SOUND_FILES];
  WavFile sounds[NUM_SOUND_FILES];
};


}

#endif
