libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/new_graph/core/async_output.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 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_GRAPH_CORE_ASYNC_OUTPUT_NODE_HPP_
00032 #define PSYNTH_GRAPH_CORE_ASYNC_OUTPUT_NODE_HPP_
00033 
00034 #include <psynth/io/output_fwd.hpp>
00035 
00036 #include <psynth/new_graph/control.hpp>
00037 #include <psynth/new_graph/buffer_port.hpp>
00038 #include <psynth/new_graph/sink_node.hpp>
00039 #include <psynth/new_graph/process_node.hpp>
00040 
00041 #include <psynth/new_graph/core/async_output_fwd.hpp>
00042 
00043 namespace psynth
00044 {
00045 namespace graph
00046 {
00047 namespace core
00048 {
00049 
00050 PSYNTH_DECLARE_ERROR (error, async_output_not_bound_error);
00051 
00060 class async_output : public sink_node
00061                    , public process_node
00062 {
00063 public:
00064     typedef io::async_output_ptr<audio_range> device_ptr;
00065     
00066     async_output (device_ptr out = device_ptr ());
00067     void set_output (device_ptr out = device_ptr ());
00068     
00069     void start ();
00070     void stop ();
00071 
00072 protected:
00073     void rt_do_update_context (rt_process_context& ctx);
00074     void rt_do_process (rt_process_context& ctx);
00075     
00076 private:
00077     void _output_callback (std::size_t nframes);
00078 
00079     defaulting_audio_in_port _in_input;
00080     
00081     // FIXME: Actually there is unnecesary buffering here, because we
00082     // buffer first to accumulate the output, then to convert it.
00083     
00084     device_ptr         _output;
00085     audio_ring_buffer  _buffer;
00086     audio_ring_buffer::range::position _pos;
00087 };
00088 
00089 } /* namespace core */
00090 } /* namespace graph */
00091 } /* namespace psynth */
00092 
00093 #endif /* PSYNTH_GRAPH_CORE_ASYNC_OUTPUT_NODE_HPP_ */
00094