libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/synth/wave_table.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 2007 Juan Pedro BolĂ­var Puente
00013  *
00014  *  This file is part of Psychosynth.
00015  *   
00016  *  Psychosynth is free software: you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation, either version 3 of the License, or
00019  *  (at your option) any later version.
00020  *
00021  *  Psychosynth is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  You should have received a copy of the GNU General Public License
00027  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028  *
00029  */
00030 
00031 #ifndef PSYNTH_SYNTH_WAVETABLE_H
00032 #define PSYNTH_SYNTH_WAVETABLE_H
00033 
00034 #include <cmath>
00035 
00036 #include <psynth/sound/buffer.hpp>
00037 #include <psynth/base/misc.hpp>
00038 
00039 namespace psynth
00040 {
00041 namespace synth
00042 {
00043 
00044 template <class Buffer>
00045 class wave_table
00046 {
00047 public:
00048     typedef typename Buffer::range::value_type frame_type;
00049     
00050     wave_table () = default;
00051     wave_table (const wave_table&) = default;
00052     wave_table (wave_table&&) = default;
00053     wave_table& operator= (const wave_table&) = default;
00054     
00055     wave_table (std::size_t size)
00056         : _table (size) {}
00057 
00058     template <typename Func>
00059     wave_table (std::size_t size, Func func)
00060         : _table (size)
00061     {
00062         fill (func);
00063     }
00064 
00065     frame_type get (float x) const;
00066     
00067     template <class Func>
00068     void fill (std::size_t new_size, Func func)
00069     {
00070         _table.recreate (new_size);
00071         fill(func);
00072     }
00073 
00074     template <class Func>
00075     void fill (Func func);
00076 
00077 private:
00078     Buffer _table;
00079 };
00080 
00081 } /* namespace synth */
00082 } /* namespace psynth */
00083 
00084 #include <psynth/synth/wave_table.tpp>
00085 
00086 #endif /* PSYNTH_SYNTH_WAVETABLE_H */