3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_AUDIO_ALSA_SINK_H
24 #define INCLUDED_AUDIO_ALSA_SINK_H
27 #define ALSA_PCM_NEW_HW_PARAMS_API
28 #define ALSA_PCM_NEW_SW_PARAMS_API
30 #include <gr_sync_block.h>
32 #include <alsa/asoundlib.h>
36 class audio_alsa_sink;
37 typedef boost::shared_ptr<audio_alsa_sink> audio_alsa_sink_sptr;
40 * \brief make an alsa audio sink.
42 * \param sampling_rate sampling rate in Hz
43 * \param device_name ALSA pcm device name, e.g., "hw:0,0"
44 * \param ok_to_block (currently ignored)
47 audio_alsa_make_sink (int sampling_rate,
48 const std::string device_name = "",
49 bool ok_to_block = true);
52 * \brief audio sink using ALSA
54 * The sink has N input streams of floats, where N depends
55 * on the hardware characteristics of the selected device.
57 * Input samples must be in the range [-1,1].
59 class audio_alsa_sink : public gr_sync_block {
60 friend audio_alsa_sink_sptr
61 audio_alsa_make_sink (int sampling_rate, const std::string device_name,
64 // typedef for pointer to class work method
65 typedef int (audio_alsa_sink::*work_t)(int noutput_items,
66 gr_vector_const_void_star &input_items,
67 gr_vector_void_star &output_items);
69 unsigned int d_sampling_rate;
70 std::string d_device_name;
71 snd_pcm_t *d_pcm_handle;
72 snd_pcm_hw_params_t *d_hw_params;
73 snd_pcm_sw_params_t *d_sw_params;
74 snd_pcm_format_t d_format;
75 unsigned int d_nperiods;
76 unsigned int d_period_time_us; // microseconds
77 snd_pcm_uframes_t d_period_size; // in frames
78 unsigned int d_buffer_size_bytes; // sizeof of d_buffer
80 work_t d_worker; // the work method to use
81 bool d_special_case_mono_to_stereo;
84 int d_nunderuns; // count of underruns
85 int d_nsuspends; // count of suspends
86 bool d_ok_to_block; // defaults to "true", controls blocking/non-block I/O
88 void output_error_msg (const char *msg, int err);
89 void bail (const char *msg, int err) throw (std::runtime_error);
92 audio_alsa_sink (int sampling_rate, const std::string device_name,
98 bool check_topology (int ninputs, int noutputs);
100 int work (int noutput_items,
101 gr_vector_const_void_star &input_items,
102 gr_vector_void_star &output_items);
106 bool write_buffer (const void *buffer, unsigned nframes, unsigned sizeof_frame);
108 int work_s16 (int noutput_items,
109 gr_vector_const_void_star &input_items,
110 gr_vector_void_star &output_items);
112 int work_s16_1x2 (int noutput_items,
113 gr_vector_const_void_star &input_items,
114 gr_vector_void_star &output_items);
116 int work_s32 (int noutput_items,
117 gr_vector_const_void_star &input_items,
118 gr_vector_void_star &output_items);
120 int work_s32_1x2 (int noutput_items,
121 gr_vector_const_void_star &input_items,
122 gr_vector_void_star &output_items);
125 #endif /* INCLUDED_AUDIO_ALSA_SINK_H */