|
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_ALSA_RAW_OUTPUT_H_ 00032 #define PSYNTH_IO_ALSA_RAW_OUTPUT_H_ 00033 00034 #define ALSA_PCM_NEW_HW_PARAMS_API 00035 #include <alsa/asoundlib.h> 00036 00037 #include <psynth/io/thread_async.hpp> 00038 00039 namespace psynth 00040 { 00041 namespace io 00042 { 00043 00044 PSYNTH_DECLARE_ERROR (error, alsa_error); 00045 PSYNTH_DECLARE_ERROR (alsa_error, alsa_open_error); 00046 PSYNTH_DECLARE_ERROR (alsa_error, alsa_start_error); 00047 PSYNTH_DECLARE_ERROR (alsa_error, alsa_param_error); 00048 00049 class alsa_raw_output : public thread_async, 00050 public boost::noncopyable 00051 { 00052 public: 00053 typedef thread_async::callback_type callback_type; 00054 00055 alsa_raw_output (const char* device, 00056 snd_pcm_format_t format, 00057 snd_pcm_uframes_t buffer_size, 00058 snd_pcm_access_t access, 00059 unsigned int rate, 00060 unsigned int channels, 00061 callback_type cb = callback_type ()); 00062 00063 ~alsa_raw_output (); 00064 00065 std::size_t put_i (const void* data, std::size_t frames); 00066 std::size_t put_n (const void* const* data, std::size_t frames); 00067 00068 std::size_t buffer_size () const 00069 { return _buffer_size; } 00070 00071 void start (); 00072 void stop (); 00073 00074 protected: 00075 void iterate (); 00076 00077 private: 00078 snd_pcm_uframes_t _buffer_size; 00079 snd_pcm_t* _handle; 00080 snd_pcm_hw_params_t* _hw_params; 00081 snd_pcm_sw_params_t* _sw_params; 00082 }; 00083 00084 } /* namespace io */ 00085 } /* namespace psynth */ 00086 00087 #endif /* PSYNTH_IO_ALSA_RAW_OUTPUT_H_ */ 00088
1.7.4