libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/graph/node_noise.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   PSYCHOSYNTH                                                           *
00004  *   ===========                                                           *
00005  *                                                                         *
00006  *   Copyright (C) Juan Pedro Bolivar Puente 2008                          *
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_OBJECTNOISE_H
00024 #define PSYNTH_OBJECTNOISE_H
00025 
00026 #include <psynth/graph/node.hpp>
00027 #include <psynth/graph/node_types.hpp>
00028 #include <psynth/graph/node_factory.hpp>
00029 
00030 namespace psynth
00031 {
00032 namespace graph
00033 {
00034 
00035 class node_noise : public node
00036 {               
00037 public: 
00038     enum in_audio_socket_id {
00039         N_IN_A_SOCKETS
00040     };
00041         
00042     enum in_control_socket_id {
00043         IN_C_AMPLITUDE,
00044         IN_C_TRIGGER,
00045         N_IN_C_SOCKETS
00046     };
00047 
00048     enum type {
00049         NOISE_WHITE,
00050         NOISE_PINK,
00051         N_TYPES
00052     };
00053     
00054     enum param_id {
00055         PARAM_TYPE = node::N_COMMON_PARAMS,
00056         PARAM_AMPLITUDE,
00057         N_PARAM
00058     };
00059 
00060     static constexpr float DEFAULT_AMPL = 0.3f;
00061     
00062 protected:
00063     sample update_pink ();
00064     sample update_white ();
00065     void update_noise (sample* buf);
00066     
00067 private:
00068     int   m_param_type;
00069     float m_param_ampl;
00070     
00071     /* Pink noise factors. */
00072     sample m_b0;
00073     sample m_b1;
00074     sample m_b2;
00075     sample m_b3;
00076     sample m_b4;
00077     sample m_b5;
00078     sample m_b6;
00079     
00080     //bool  m_restart;
00081     
00082 public:
00083     node_noise (const audio_info& prop,
00084                 int obj_type,
00085                 const std::string& name,
00086                 int n_audio_out,
00087                 int n_control_out);
00088     
00089     ~node_noise ();
00090 };
00091 
00092 class node_audio_noise : public node_noise
00093 {
00094 public:
00095     enum out_audio_socket_id {
00096         OUT_A_OUTPUT,
00097         N_OUT_A_SOCKETS
00098     };
00099 
00100 private:
00101     void do_update (const node* caller, int caller_port_type, int caller_port);
00102     void do_advance () {}
00103     void on_info_change () {}
00104 
00105 public:
00106     node_audio_noise (const audio_info& prop) :
00107         node_noise (prop,
00108                    NODE_AUDIONOISE,
00109                    "audio_noise",
00110                    N_OUT_A_SOCKETS,
00111                    0)
00112         {};
00113 };
00114 
00115 class node_control_noise : public node_noise
00116 {
00117 public: 
00118     enum out_control_socket_id {
00119         OUT_C_OUTPUT,
00120         N_OUT_C_SOCKETS
00121     };
00122 
00123 private:
00124     void do_update (const node* caller, int caller_port_type, int caller_port);
00125     void do_advance () {}
00126     void on_info_change () {}
00127     
00128 public:
00129     node_control_noise (const audio_info& prop) :
00130         node_noise (prop,
00131                     NODE_CONTROLNOISE,
00132                     "control_noise",
00133                     0,
00134                     N_OUT_C_SOCKETS)
00135         {};
00136 };
00137 
00138 PSYNTH_DECLARE_NODE_FACTORY (node_control_noise, "control_noise");
00139 PSYNTH_DECLARE_NODE_FACTORY (node_audio_noise,   "audio_noise");
00140 
00141 } /* namespace graph */
00142 } /* namespace psynth */
00143 
00144 #endif /* PSYNTH_OBJECTNOISE_H */
00145