Jack2: alsa_driver.h Source File

Jack2 1.9.12

alsa_driver.h
1 /*
2 Copyright (C) 2001 Paul Davis
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 $Id: alsa_driver.h 945 2006-05-04 15:14:45Z pbd $
19 */
20
21 #ifndef __jack_alsa_driver_h__
22 #define __jack_alsa_driver_h__
23
24 #include <alsa/asoundlib.h>
25 #include "bitset.h"
26
27 #if __BYTE_ORDER == __LITTLE_ENDIAN
28 #define IS_LE 0
29 #define IS_BE 1
30 #elif __BYTE_ORDER == __BIG_ENDIAN
31 #define IS_LE 1
32 #define IS_BE 0
33 #endif
34
35 #define TRUE 1
36 #define FALSE 0
37
38 #include "types.h"
39 #include "hardware.h"
40 #include "driver.h"
41 #include "memops.h"
42 #include "alsa_midi.h"
43
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #endif
48
49 typedef void (*ReadCopyFunction) (jack_default_audio_sample_t *dst, char *src,
50 unsigned long src_bytes,
51 unsigned long src_skip_bytes);
52 typedef void (*WriteCopyFunction) (char *dst, jack_default_audio_sample_t *src,
53 unsigned long src_bytes,
54 unsigned long dst_skip_bytes,
55 dither_state_t *state);
56
57 typedef struct _alsa_driver {
58
59 JACK_DRIVER_NT_DECL
60
61 int poll_timeout;
62 jack_time_t poll_last;
63 jack_time_t poll_next;
64 char **playback_addr;
65 char **capture_addr;
66 const snd_pcm_channel_area_t *capture_areas;
67 const snd_pcm_channel_area_t *playback_areas;
68 struct pollfd *pfd;
69 unsigned int playback_nfds;
70 unsigned int capture_nfds;
71 unsigned long interleave_unit;
72 unsigned long *capture_interleave_skip;
73 unsigned long *playback_interleave_skip;
74 channel_t max_nchannels;
75 channel_t user_nchannels;
76 channel_t playback_nchannels;
77 channel_t capture_nchannels;
78 unsigned long playback_sample_bytes;
79 unsigned long capture_sample_bytes;
80
81 jack_nframes_t frame_rate;
82 jack_nframes_t frames_per_cycle;
83 jack_nframes_t capture_frame_latency;
84 jack_nframes_t playback_frame_latency;
85
86 unsigned long *silent;
87 char *alsa_name_playback;
88 char *alsa_name_capture;
89 char *alsa_driver;
90 bitset_t channels_not_done;
91 bitset_t channels_done;
92 snd_pcm_format_t playback_sample_format;
93 snd_pcm_format_t capture_sample_format;
94 float max_sample_val;
95 unsigned long user_nperiods;
96 unsigned int playback_nperiods;
97 unsigned int capture_nperiods;
98 unsigned long last_mask;
99 snd_ctl_t *ctl_handle;
100 snd_pcm_t *playback_handle;
101 snd_pcm_t *capture_handle;
102 snd_pcm_hw_params_t *playback_hw_params;
103 snd_pcm_sw_params_t *playback_sw_params;
104 snd_pcm_hw_params_t *capture_hw_params;
105 snd_pcm_sw_params_t *capture_sw_params;
106 jack_hardware_t *hw;
107 ClockSyncStatus *clock_sync_data;
108 jack_client_t *client;
109 JSList *capture_ports;
110 JSList *playback_ports;
111 JSList *monitor_ports;
112
113 unsigned long input_monitor_mask;
114
115 char soft_mode;
116 char hw_monitoring;
117 char hw_metering;
118 char all_monitor_in;
119 char capture_and_playback_not_synced;
120 char playback_interleaved;
121 char capture_interleaved;
122 char with_monitor_ports;
123 char has_clock_sync_reporting;
124 char has_hw_monitoring;
125 char has_hw_metering;
126 char quirk_bswap;
127
128 ReadCopyFunction read_via_copy;
129 WriteCopyFunction write_via_copy;
130
131 int dither;
132 dither_state_t *dither_state;
133
134 SampleClockMode clock_mode;
135 JSList *clock_sync_listeners;
136 pthread_mutex_t clock_sync_lock;
137 unsigned long next_clock_sync_listener_id;
138
139 int running;
140 int run;
141
142 int poll_late;
143 int xrun_count;
144 int process_count;
145
146 alsa_midi_t *midi;
147 int xrun_recovery;
148
149 } alsa_driver_t;
150
151 static inline void
152 alsa_driver_mark_channel_done (alsa_driver_t *driver, channel_t chn) {
153 bitset_remove (driver->channels_not_done, chn);
154 driver->silent[chn] = 0;
155 }
156
157 static inline void
158 alsa_driver_silence_on_channel (alsa_driver_t *driver, channel_t chn,
159 jack_nframes_t nframes) {
160 if (driver->playback_interleaved) {
161 memset_interleave
162 (driver->playback_addr[chn],
163 0, nframes * driver->playback_sample_bytes,
164 driver->interleave_unit,
165 driver->playback_interleave_skip[chn]);
166 } else {
167 memset (driver->playback_addr[chn], 0,
168 nframes * driver->playback_sample_bytes);
169 }
170 alsa_driver_mark_channel_done (driver,chn);
171 }
172
173 static inline void
174 alsa_driver_silence_on_channel_no_mark (alsa_driver_t *driver, channel_t chn,
175 jack_nframes_t nframes) {
176 if (driver->playback_interleaved) {
177 memset_interleave
178 (driver->playback_addr[chn],
179 0, nframes * driver->playback_sample_bytes,
180 driver->interleave_unit,
181 driver->playback_interleave_skip[chn]);
182 } else {
183 memset (driver->playback_addr[chn], 0,
184 nframes * driver->playback_sample_bytes);
185 }
186 }
187
188 static inline void
189 alsa_driver_read_from_channel (alsa_driver_t *driver,
190 channel_t channel,
191 jack_default_audio_sample_t *buf,
192 jack_nframes_t nsamples)
193 {
194 driver->read_via_copy (buf,
195 driver->capture_addr[channel],
196 nsamples,
197 driver->capture_interleave_skip[channel]);
198 }
199
200 static inline void
201 alsa_driver_write_to_channel (alsa_driver_t *driver,
202 channel_t channel,
203 jack_default_audio_sample_t *buf,
204 jack_nframes_t nsamples)
205 {
206 driver->write_via_copy (driver->playback_addr[channel],
207 buf,
208 nsamples,
209 driver->playback_interleave_skip[channel],
210 driver->dither_state+channel);
211 alsa_driver_mark_channel_done (driver, channel);
212 }
213
214 void alsa_driver_silence_untouched_channels (alsa_driver_t *driver,
215 jack_nframes_t nframes);
216 void alsa_driver_set_clock_sync_status (alsa_driver_t *driver, channel_t chn,
217 ClockSyncStatus status);
218 int alsa_driver_listen_for_clock_sync_status (alsa_driver_t *,
219 ClockSyncListenerFunction,
220 void *arg);
221 int alsa_driver_stop_listen_for_clock_sync_status (alsa_driver_t *,
222 unsigned int);
223 void alsa_driver_clock_sync_notify (alsa_driver_t *, channel_t chn,
224 ClockSyncStatus);
225
226 int
227 alsa_driver_reset_parameters (alsa_driver_t *driver,
228 jack_nframes_t frames_per_cycle,
229 jack_nframes_t user_nperiods,
230 jack_nframes_t rate);
231
232 jack_driver_t *
233 alsa_driver_new (char *name, char *playback_alsa_device,
234 char *capture_alsa_device,
235 jack_client_t *client,
236 jack_nframes_t frames_per_cycle,
237 jack_nframes_t user_nperiods,
238 jack_nframes_t rate,
239 int hw_monitoring,
240 int hw_metering,
241 int capturing,
242 int playing,
243 DitherAlgorithm dither,
244 int soft_mode,
245 int monitor,
246 int user_capture_nchnls,
247 int user_playback_nchnls,
248 int shorts_first,
249 jack_nframes_t capture_latency,
250 jack_nframes_t playback_latency,
251 alsa_midi_t *midi_driver
252 );
253 void
254 alsa_driver_delete (alsa_driver_t *driver);
255
256 int
257 alsa_driver_start (alsa_driver_t *driver);
258
259 int
260 alsa_driver_stop (alsa_driver_t *driver);
261
262 jack_nframes_t
263 alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
264 *delayed_usecs);
265
266 int
267 alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes);
268
269 int
270 alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes);
271
272 jack_time_t jack_get_microseconds(void);
273
274 // Code implemented in JackAlsaDriver.cpp
275
276 void ReadInput(jack_nframes_t orig_nframes, snd_pcm_sframes_t contiguous, snd_pcm_sframes_t nread);
277 void MonitorInput();
278 void ClearOutput();
279 void WriteOutput(jack_nframes_t orig_nframes, snd_pcm_sframes_t contiguous, snd_pcm_sframes_t nwritten);
280 void SetTime(jack_time_t time);
281 int Restart();
282
283 #ifdef __cplusplus
284 }
285 #endif
286
287
288 #endif /* __jack_alsa_driver_h__ */
_jack_hardware
Definition: hardware.h:49
_jack_driver
Definition: driver.h:87
alsa_midi_t
Definition: alsa_midi.h:30
dither_state_t
Definition: memops.h:44
_alsa_driver
Definition: alsa_driver.h:57
_JSList
Definition: linux/alsa/jslist.h:35