Olivier Smeesters
/
DtmfKit
A DTMF sequence editor and player for HAM radio equipment command & control.
Diff: SoundWaveGenerator/snd_wave_generator/WaveBuffer.h
- Revision:
- 0:1324e7d9d471
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SoundWaveGenerator/snd_wave_generator/WaveBuffer.h Mon Mar 07 22:51:19 2011 +0000 @@ -0,0 +1,37 @@ +#ifndef WAVE_BUFFER_H_ +#define WAVE_BUFFER_H_ + +#include <cstddef> + +namespace snd_wave_generator { + +/** + * @brief A class used to hold buffered sound wave data. + * It's basically a vector of floats which can be read in a cyclic way. + */ +class WaveBuffer { +public: + WaveBuffer() : size_(0), capacity_(0), data_(NULL) { } + ~WaveBuffer() { delete[] this->data_; } + + void resize(std::size_t size); + + void write(std::size_t pos, float v) { + if (pos < this->size_) { + this->data_[pos] = v; + } + } + + float read(std::size_t pos) const { + return this->data_[pos % this->size_]; + } + +private: + std::size_t size_; + std::size_t capacity_; + float *data_; +}; + +} // snd_wave_generator + +#endif // WAVE_BUFFER_H_ \ No newline at end of file