00001 #ifndef _WAVEPLAYER_H_
00002 #define _WAVEPLAYER_H_
00003
00004 #include <system.hpp>
00005 #include <mmsystem.h>
00006 #include "Speaker.h"
00007 #include "HiddenWindow.h"
00008 #include "WaveFile.h"
00009
00010 class TWavePlayer;
00011
00012 class TWavePlayerWindow : public THiddenWindow
00013 {
00014 protected:
00015 TWavePlayer *WavePlayer;
00016 public:
00017 TWavePlayerWindow(TWavePlayer *);
00018 void WndProc(UINT, WPARAM, LPARAM);
00019 };
00020
00026 class TWavePlayer : public TWaveFile, public Speaker
00027 {
00028 friend TWavePlayerWindow;
00029 protected:
00030 WAVEFORMATEX waveFormat;
00031 HWAVEIN waveIn;
00032 HWAVEOUT waveOut;
00033 WAVEHDR waveInHdr[3], waveOutHdr[3];
00034 int bufferSize, bufferTotal, recordBufferCount, playBufferCount, firstEchoBufferIndex;
00035 int mode, bytesPerBuffer;
00036 float duration;
00037 TWavePlayerWindow *HiddenWindow;
00038 bool echoOn, firstEcho;
00039
00040 void Resample(int);
00041 bool OpenRecordDevice(void);
00042 void CloseRecordDevice(void);
00043 bool OpenPlayDevice(void);
00044 void ClosePlayDevice(void);
00045 void RecordComplete(void);
00046 void PlayComplete(void);
00047 public:
00048 enum
00049 {
00051 EVENT_RECORD_BUFFER,
00053 EVENT_PLAY_BUFFER,
00055 EVENT_RECORD_COMPLETE,
00057 EVENT_PLAY_COMPLETE
00058 };
00059
00060 enum
00061 {
00062 IDLE,
00063 RECORDING,
00064 PLAYING
00065 };
00066
00068 int *wave;
00070 int waveSize;
00072 int echoVolume;
00073
00079 TWavePlayer(int sampleRate = 11025, int bitRate = 8);
00081 ~TWavePlayer();
00086 int GetMode(void);
00087
00091 int GetSampleRate(void);
00092
00096 int GetBitRate(void);
00097
00103 void SetFormat(int newSampleRate, int newBitRate);
00108 float GetDuration(void);
00113 bool IsEchoOn(void);
00114
00118 int GetBufferSize(void);
00119
00123 void SetBufferSize(int);
00130 void SetWave(int *w, int size);
00135 void SetWave(TWaveFile *WaveFile);
00143 bool Record(int maxDuration);
00147 void StopRecord(void);
00148
00152 bool Play(void);
00156 void StopPlay(void);
00157
00160 void EchoOn(void);
00161
00164 void EchoOff(void);
00165
00169 float GetTimeCode(void);
00170
00174 void Seek(int percent);
00175
00176
00177
00178
00179
00180 bool Load(char *name);
00186 bool Save(char *name);
00187
00188 void Clear(void);
00189
00194 void Trim(int from, int to);
00195
00196 void RecordABuffer(void);
00197 void PlayABuffer(void);
00198 };
00199
00200 #endif
00201