|
libpsynth 0.2.1
|
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_IO_INPUT_H_ 00032 #define PSYNTH_IO_INPUT_H_ 00033 00034 #include <cstddef> 00035 00036 #include <psynth/sound/forwards.hpp> 00037 #include <psynth/io/async_base.hpp> 00038 #include <psynth/io/input.tpp> 00039 00040 namespace psynth 00041 { 00042 namespace io 00043 { 00044 00045 const std::size_t default_input_buffer_size = 1024; 00046 00053 template <class Range> 00054 class input 00055 { 00056 public: 00057 typedef Range range; 00058 00059 virtual std::size_t take (const Range& r) = 0; 00060 }; 00061 00065 template <typename Range> 00066 class dummy_input : public input<Range> 00067 { 00068 public: 00069 typedef Range range; 00070 00071 virtual std::size_t take (const range& data) 00072 { 00073 detail::dummy_input_take_impl (); 00074 typename range::value_type zero ( 00075 sound::sample_traits< 00076 typename sound::sample_type<range>::type 00077 >::zero_value ()); 00078 fill_frames (data, zero); 00079 return data.size (); 00080 } 00081 }; 00082 00086 template <typename Range> 00087 class async_input : public input<Range>, 00088 public virtual async_base 00089 { 00090 public: 00091 virtual std::size_t buffer_size () const = 0; 00092 }; 00093 00097 template <typename Range> 00098 class dummy_async_input : public input<Range> 00099 { 00100 public: 00101 typedef Range range; 00102 00103 dummy_async_input (std::size_t buffer_size) 00104 : _buffer_size (buffer_size) 00105 {} 00106 00107 std::size_t buffer_size () const 00108 { return _buffer_size; } 00109 00110 virtual std::size_t take (const range& data) 00111 { 00112 detail::dummy_input_take_impl (); 00113 typename range::value_type zero ( 00114 sound::sample_traits< 00115 typename sound::sample_type<range>::type 00116 >::zero_value ()); 00117 fill_frames (data, zero); 00118 return data.size (); 00119 } 00120 00121 void start () 00122 { 00123 this->check_idle (); 00124 this->set_state (async_state::running); 00125 detail::dummy_input_start_impl (); 00126 } 00127 00128 void stop () 00129 { 00130 this->check_running (); 00131 this->set_state (async_state::idle); 00132 detail::dummy_input_stop_impl (); 00133 } 00134 00135 private: 00136 std::size_t _buffer_size; 00137 }; 00138 00139 00140 } /* namespace io */ 00141 } /* namespace psynth */ 00142 00143 #endif /* PSYNTH_IO_INPUT_H_ */ 00144
1.7.4