00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 typedef uint8_t SampleType;
00025
00026 const SampleType SAMPLE_TYPE_NONE = 0;
00027
00028 const SampleType SAMPLE_TYPE_FILE = 1;
00029
00030 const SampleType SAMPLE_TYPE_MEM = 2;
00031
00032 class AudioSample
00033 {
00034 public:
00035 AudioSample (void);
00036 AudioSample (const player_audio_wav_t *source);
00037 AudioSample (const uint8_t *source, uint32_t length, uint16_t channels, uint32_t sr, uint16_t bps);
00038 ~AudioSample (void);
00039
00040
00041 void SetDataPosition (uint32_t newPosition);
00042 uint32_t GetDataPosition (void) const;
00043 uint32_t GetDataLength (void) const;
00044 int GetData (int frameCount, uint8_t *buffer);
00045 void ClearSample (void);
00046 bool FillSilence (uint32_t time);
00047
00048
00049 bool ToPlayer (player_audio_wav_t *dest);
00050 bool FromPlayer (const player_audio_wav_t *source);
00051
00052
00053 bool LoadFile (const char *fileName);
00054 void CloseFile (void);
00055 const char* GetFilePath (void) const { return filePath; }
00056
00057
00058 SampleType GetType (void) const { return type; }
00059 void SetType (SampleType val) { type = val; }
00060 uint16_t GetNumChannels (void) const { return numChannels; }
00061 void SetNumChannels (uint16_t val) { numChannels = val; }
00062 uint32_t GetSampleRate (void) const { return sampleRate; }
00063 void SetSampleRate (uint32_t val) { sampleRate = val; byteRate = blockAlign * sampleRate; }
00064 uint32_t GetByteRate (void) const { return byteRate; }
00065 uint16_t GetBlockAlign (void) const { return blockAlign; }
00066 void SetBlockAlign (uint16_t val) { blockAlign = val; byteRate = blockAlign * sampleRate; }
00067 uint16_t GetBitsPerSample (void) const { return bitsPerSample; }
00068 void SetBitsPerSample (uint16_t val) { bitsPerSample = val; }
00069 uint32_t GetNumFrames (void) const { return numFrames; }
00070 bool SameFormat (const AudioSample *rhs);
00071 void CopyFormat (const AudioSample *rhs);
00072
00073
00074 void PrintWaveInfo (void);
00075
00076 private:
00077 SampleType type;
00078
00079
00080 uint16_t numChannels;
00081 uint32_t sampleRate;
00082 uint32_t byteRate;
00083 uint16_t blockAlign;
00084 uint16_t bitsPerSample;
00085 uint32_t numFrames;
00086
00087
00088 uint32_t position;
00089
00090
00091 FILE *waveFile;
00092 char *filePath;
00093 uint32_t headerSize;
00094
00095
00096 uint32_t dataLength;
00097 uint8_t *data;
00098 };