|
libpsynth 0.2.1
|
00001 /*************************************************************************** 00002 * * 00003 * PSYCHOSYNTH * 00004 * =========== * 00005 * * 00006 * Copyright (C) Juan Pedro Bolivar Puente 2007 * 00007 * * 00008 * This program is free software: you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation, either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00020 * * 00021 ***************************************************************************/ 00022 00023 #ifndef PSYNTH_OBJECTSAMPLER_H 00024 #define PSYNTH_OBJECTSAMPLER_H 00025 00026 #include <mutex> 00027 00028 #include <psynth/graph/node.hpp> 00029 #include <psynth/io/file_input.hpp> 00030 #include <psynth/io/caching_file_input.hpp> 00031 #include <psynth/graph/node_factory.hpp> 00032 #include <psynth/synth/scaler.hpp> 00033 00034 namespace psynth 00035 { 00036 namespace graph 00037 { 00038 00039 class mutex; 00040 00041 class node_sampler : public node 00042 { 00043 public: 00044 enum in_audio_socket_id { 00045 N_IN_A_SOCKETS 00046 }; 00047 00048 enum in_control_socket_id { 00049 IN_C_RATE, 00050 IN_C_TRIGGER, 00051 N_IN_C_SOCKETS 00052 }; 00053 00054 enum param_id { 00055 PARAM_FILE = node::N_COMMON_PARAMS, 00056 PARAM_AMPLITUDE, 00057 PARAM_RATE, 00058 PARAM_TEMPO, 00059 PARAM_PITCH, 00060 N_PARAM 00061 }; 00062 00063 enum out_audio_socket_id { 00064 OUT_A_OUTPUT, 00065 N_OUT_A_SOCKETS 00066 }; 00067 00068 enum out_control_socket_id { 00069 N_OUT_C_SOCKETS 00070 }; 00071 00072 private: 00073 typedef sound::stereo32sf_range interleaved_range; 00074 typedef sound::stereo32sf_buffer interleaved_buffer; 00075 00076 io::file_input_ptr<interleaved_range> m_reader; 00077 io::caching_file_input_adapter<interleaved_range, 00078 decltype (m_reader)> m_fetcher; 00079 00080 interleaved_buffer m_inbuf;; 00081 synth::scaler<interleaved_range> m_scaler; 00082 00083 float m_ctrl_pos; 00084 00085 float m_param_ampl; 00086 float m_param_rate; 00087 float m_param_tempo; 00088 float m_param_pitch; 00089 00090 bool m_restart; 00091 00092 std::string m_param_file; 00093 00094 std::mutex m_update_mutex; 00095 00096 void on_file_change (node_param& par); 00097 void read (audio_buffer& buf, int start, int end); 00098 void restart(); 00099 00100 void do_update (const node* caller, int caller_port_type, int caller_port); 00101 void do_advance (); 00102 void on_info_change (); 00103 00104 public: 00105 node_sampler (const audio_info& info); 00106 ~node_sampler (); 00107 }; 00108 00109 PSYNTH_DECLARE_NODE_FACTORY (node_sampler, "sampler"); 00110 00111 } /* namespacce graph */ 00112 } /* namespace psynth */ 00113 00114 #endif /* PSYNTH_OBJECTSAMPLER_H */
1.7.4