Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WaveBuffer.h
00001 #ifndef WAVE_BUFFER_H_ 00002 #define WAVE_BUFFER_H_ 00003 00004 #include <cstddef> 00005 00006 namespace snd_wave_generator { 00007 00008 /** 00009 * @brief A class used to hold buffered sound wave data. 00010 * It's basically a vector of floats which can be read in a cyclic way. 00011 */ 00012 class WaveBuffer { 00013 public: 00014 WaveBuffer() : size_(0), capacity_(0), data_(NULL) { } 00015 ~WaveBuffer() { delete[] this->data_; } 00016 00017 void resize(std::size_t size); 00018 00019 void write(std::size_t pos, float v) { 00020 if (pos < this->size_) { 00021 this->data_[pos] = v; 00022 } 00023 } 00024 00025 float read(std::size_t pos) const { 00026 return this->data_[pos % this->size_]; 00027 } 00028 00029 private: 00030 std::size_t size_; 00031 std::size_t capacity_; 00032 float *data_; 00033 }; 00034 00035 } // snd_wave_generator 00036 00037 #endif // WAVE_BUFFER_H_
Generated on Wed Jul 13 2022 16:23:43 by
1.7.2