1 // components.h - description. -*- C++ -*-
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
13 #include <sidcomputil.h>
14 #include <sidattrutil.h>
15 #include <sidpinutil.h>
16 #include <sidbusutil.h>
17 #include <sidmiscutil.h>
18 #include <sidschedutil.h>
31 #include <sys/ioctl.h>
33 #ifdef HAVE_SYS_AUDIOIO_H
34 #include <sys/audioio.h>
36 #ifdef HAVE_SYS_SOUNDCARD_H
37 #include <sys/soundcard.h>
42 #ifdef HAVE_MMSYSTEM_H
63 using sid::host_int_1;
64 using sid::host_int_2;
65 using sid::host_int_4;
68 using sid::component_library;
69 using sid::COMPONENT_LIBRARY_MAGIC;
71 using sidutil::fixed_attribute_map_component;
72 using sidutil::no_relation_component;
73 using sidutil::no_accessor_component;
74 using sidutil::fixed_pin_map_component;
75 using sidutil::fixed_bus_map_component;
76 using sidutil::no_bus_component;
77 using sidutil::make_attribute;
78 using sidutil::make_numeric_attribute;
79 using sidutil::parse_attribute;
80 using sidutil::callback_pin;
81 using sidutil::output_pin;
82 using sidutil::input_pin;
83 using sidutil::std_error_string;
84 using sidutil::callback_word_bus;
87 // ----------------------------------------------------------------------------
91 class basic_codec: public virtual component,
92 protected fixed_attribute_map_component,
93 protected no_relation_component,
94 protected fixed_pin_map_component,
95 protected no_accessor_component,
96 protected fixed_bus_map_component
103 friend class callback_word_bus<basic_codec,big_int_4>;
104 callback_word_bus<basic_codec,big_int_4> registers;
106 friend class callback_pin<basic_codec>;
107 callback_pin<basic_codec> rx_sample_pin;
108 output_pin tx_sample_pin;
109 output_pin tx_mode_pin, rx_mode_pin;
110 input_pin tx_pending_pin, rx_pending_pin;
111 output_pin config_set_pin;
117 host_int_4 rx_offset;
122 bus::status reg_write (host_int_4 idx, big_int_4 mask, big_int_4 data);
123 bus::status reg_read (host_int_4 idx, big_int_4 mask, big_int_4& data);
124 void rx_sample_pin_handler (host_int_4);
126 void update_txrx_mode_pins ();
131 // ----------------------------------------------------------------------------
136 host_int_2 num_bits_per_sample;
137 enum encoding_t { ulaw, alaw, pcm } encoding;
138 host_int_2 num_channels;
139 host_int_2 sampling_frequency;
141 // Initialize to default
144 // Encode/decode config state for sid::pin transmission
145 audio_config (host_int_4);
146 host_int_4 encode () const;
150 // ----------------------------------------------------------------------------
153 class generic_audio: public virtual component,
154 protected fixed_attribute_map_component,
155 protected no_relation_component,
156 protected fixed_pin_map_component,
157 protected no_accessor_component,
158 protected no_bus_component
165 virtual bool begin_tx (const audio_config&) = 0;
166 virtual bool pending_tx_p ();
167 virtual void end_tx () = 0;
168 virtual bool begin_rx (const audio_config&) = 0;
169 virtual void end_rx () = 0;
170 virtual string poll_tx (const string&) = 0;
171 virtual string poll_rx () = 0;
174 friend class callback_pin<generic_audio>;
176 callback_pin<generic_audio> tx_mode_pin;
177 callback_pin<generic_audio> tx_sample_pin;
180 output_pin tx_pending_pin;
182 callback_pin<generic_audio> rx_mode_pin;
183 output_pin rx_sample_pin;
186 output_pin rx_pending_pin;
189 callback_pin<generic_audio> config_set_pin;
191 callback_pin<generic_audio> reset_pin;
192 callback_pin<generic_audio> poll_pin;
194 host_int_4 poll_count;
195 host_int_4 tx_samples_count;
196 host_int_4 tx_blocks_count;
197 host_int_4 rx_samples_count;
198 host_int_4 rx_blocks_count;
200 void tx_mode_pin_handler (host_int_4);
201 void tx_sample_pin_handler (host_int_4);
202 void rx_mode_pin_handler (host_int_4);
203 void config_set_pin_handler (host_int_4);
204 void reset_pin_handler (host_int_4);
205 void poll_pin_handler (host_int_4);
207 void update_txrx_pending_pins ();
211 // ----------------------------------------------------------------------------
214 class nop_audio: public generic_audio
221 // The inherited virtual functions
222 bool begin_tx (const audio_config&) { return false; }
224 bool begin_rx (const audio_config&) { return false; }
226 string poll_tx (const string&) { return string(); }
227 string poll_rx () { return string(); }
231 // ----------------------------------------------------------------------------
234 class fd_audio: public generic_audio
241 virtual bool set_audio_config (int, const audio_config&) = 0;
248 // The inherited virtual functions
249 bool begin_tx (const audio_config&);
251 bool begin_rx (const audio_config&);
253 string poll_tx (const string&);
258 class linux_audio: public fd_audio
266 bool set_audio_config (int, const audio_config&) { return true; }
269 class solaris_audio: public fd_audio
276 bool set_audio_config (int, const audio_config&) { return true; }
280 // ----------------------------------------------------------------------------
283 #if defined(SOUND_CYGWIN)
285 struct win32_audio_buf
291 win32_audio_buf (host_int_4 size);
292 virtual ~win32_audio_buf ();
299 // Disposable, variable-size transmit buffer
300 struct win32_audio_tx_buf: public win32_audio_buf
304 win32_audio_tx_buf (HWAVEOUT dev, const string& buf);
305 ~win32_audio_tx_buf ();
309 // Reusable, fixed-size receive buffer
310 struct win32_audio_rx_buf: public win32_audio_buf
314 win32_audio_rx_buf (HWAVEIN dev, host_int_4 size);
315 ~win32_audio_rx_buf ();
322 class cygwin_audio: public generic_audio
329 host_int_2 rx_buffer_size;
330 host_int_1 rx_buffer_count;
333 typedef deque<win32_audio_tx_buf*> tx_bufs_t;
337 typedef deque<win32_audio_rx_buf*> rx_bufs_t;
340 // The inherited virtual functions
341 bool begin_tx (const audio_config&);
342 bool pending_tx_p ();
344 bool begin_rx (const audio_config&);
346 string poll_tx (const string&);
353 // ----------------------------------------------------------------------------
356 #endif // COMPONENTS_H