|
libpsynth 0.2.1
|
00001 00011 /* 00012 * Copyright (C) 2008, 2011 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_SCALERST_H 00032 #define PSYNTH_SCALERST_H 00033 00034 #include <soundtouch/SoundTouch.h> 00035 #include <cstddef> 00036 #include <psynth/sound/forwards.hpp> 00037 00038 namespace psynth 00039 { 00040 namespace synth 00041 { 00042 00043 template <class Range> 00044 class scaler_support; 00045 00051 template <class Range> 00052 class scaler 00053 { 00054 public: 00055 static_assert (std::is_same<soundtouch::SAMPLETYPE, float>::value, 00056 "Soundtouch SAMPLETYPE must be flaot."); 00057 00058 static_assert (scaler_support<Range>::is_supported::value, 00059 "Soundtouch supports only interleaved bits32sf ranges."); 00060 00061 typedef Range range; 00062 00064 scaler (std::size_t frame_rate) 00065 { 00066 _st.clear (); 00067 _st.setChannels (sound::num_samples<Range>::value); 00068 set_frame_rate (frame_rate); 00069 } 00070 00075 void set_tempo (float tempo) 00076 { 00077 _tempo = tempo; 00078 _st.setTempo(tempo); 00079 } 00080 00085 void set_rate (float rate) 00086 { 00087 _rate = rate; 00088 _st.setRate(rate); 00089 } 00090 00095 void set_pitch (float pitch) 00096 { 00097 _pitch = pitch; 00098 _st.setPitch (pitch); 00099 } 00100 00105 void set_frame_rate (int samplerate) 00106 { 00107 _st.setSampleRate (samplerate); 00108 } 00109 00113 float tempo () 00114 { return _tempo; } 00115 00119 float rate () 00120 { return _rate; } 00121 00125 float pitch () 00126 { return _pitch; } 00127 00131 std::size_t available () 00132 { return _st.numSamples(); } 00133 00141 std::size_t receive (const Range& data) 00142 { return _st.receiveSamples ( 00143 (soundtouch::SAMPLETYPE*) &data[0][0], data.size ()); } 00144 00150 void update (const Range& data) 00151 { _st.putSamples ((soundtouch::SAMPLETYPE*) &data[0][0], data.size ()); } 00152 00156 void clear () 00157 { 00158 _st.clear(); 00159 } 00160 00161 public: 00162 float _tempo; 00163 float _rate; 00164 float _pitch; 00165 00166 soundtouch::SoundTouch _st; 00167 }; 00168 00169 } /* namespace synth */ 00170 } /* namespace psynth */ 00171 00172 #include <psynth/synth/scaler.tpp> 00173 00174 #endif /* PSYNTH_SCALERST_H */
1.7.4