Commit | Line | Data |
---|---|---|
705ececd | 1 | /* |
e1a164d7 | 2 | * Line6 Linux USB driver - 0.9.1beta |
705ececd | 3 | * |
1027f476 | 4 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
705ececd MG |
5 | * |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License as | |
8 | * published by the Free Software Foundation, version 2. | |
9 | * | |
10 | */ | |
11 | ||
12 | /* | |
13 | PCM interface to POD series devices. | |
14 | */ | |
15 | ||
16 | #ifndef PCM_H | |
17 | #define PCM_H | |
18 | ||
705ececd MG |
19 | #include <sound/pcm.h> |
20 | ||
21 | #include "driver.h" | |
22 | #include "usbdefs.h" | |
23 | ||
a49e4838 | 24 | /* number of URBs */ |
1027f476 | 25 | #define LINE6_ISO_BUFFERS 2 |
a49e4838 | 26 | |
1027f476 MG |
27 | /* |
28 | number of USB frames per URB | |
29 | The Line6 Windows driver always transmits two frames per packet, but | |
30 | the Linux driver performs significantly better (i.e., lower latency) | |
31 | with only one frame per packet. | |
32 | */ | |
33 | #define LINE6_ISO_PACKETS 1 | |
a49e4838 GKH |
34 | |
35 | /* in a "full speed" device (such as the PODxt Pro) this means 1ms */ | |
36 | #define LINE6_ISO_INTERVAL 1 | |
37 | ||
1027f476 MG |
38 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE |
39 | #define LINE6_IMPULSE_DEFAULT_PERIOD 100 | |
40 | #endif | |
41 | ||
705ececd | 42 | /* |
1027f476 | 43 | Get substream from Line6 PCM data structure |
705ececd | 44 | */ |
027360c5 GKH |
45 | #define get_substream(line6pcm, stream) \ |
46 | (line6pcm->pcm->streams[stream].substream) | |
705ececd | 47 | |
1027f476 | 48 | /* |
0ca54888 MG |
49 | PCM mode bits. |
50 | ||
51 | There are several features of the Line6 USB driver which require PCM | |
52 | data to be exchanged with the device: | |
53 | *) PCM playback and capture via ALSA | |
54 | *) software monitoring (for devices without hardware monitoring) | |
55 | *) optional impulse response measurement | |
56 | However, from the device's point of view, there is just a single | |
57 | capture and playback stream, which must be shared between these | |
58 | subsystems. It is therefore necessary to maintain the state of the | |
59 | subsystems with respect to PCM usage. We define several constants of | |
60 | the form LINE6_BIT_PCM_<subsystem>_<direction>_<resource> with the | |
61 | following meanings: | |
62 | *) <subsystem> is one of | |
63 | -) ALSA: PCM playback and capture via ALSA | |
64 | -) MONITOR: software monitoring | |
65 | -) IMPULSE: optional impulse response measurement | |
66 | *) <direction> is one of | |
67 | -) PLAYBACK: audio output (from host to device) | |
68 | -) CAPTURE: audio input (from device to host) | |
69 | *) <resource> is one of | |
70 | -) BUFFER: buffer required by PCM data stream | |
71 | -) STREAM: actual PCM data stream | |
72 | ||
73 | The subsystems call line6_pcm_acquire() to acquire the (shared) | |
74 | resources needed for a particular operation (e.g., allocate the buffer | |
75 | for ALSA playback or start the capture stream for software monitoring). | |
76 | When a resource is no longer needed, it is released by calling | |
77 | line6_pcm_release(). Buffer allocation and stream startup are handled | |
78 | separately to allow the ALSA kernel driver to perform them at | |
79 | appropriate places (since the callback which starts a PCM stream is not | |
80 | allowed to sleep). | |
1027f476 | 81 | */ |
705ececd | 82 | enum { |
0ca54888 MG |
83 | /* individual bit indices: */ |
84 | LINE6_INDEX_PCM_ALSA_PLAYBACK_BUFFER, | |
85 | LINE6_INDEX_PCM_ALSA_PLAYBACK_STREAM, | |
86 | LINE6_INDEX_PCM_ALSA_CAPTURE_BUFFER, | |
87 | LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM, | |
88 | LINE6_INDEX_PCM_MONITOR_PLAYBACK_BUFFER, | |
89 | LINE6_INDEX_PCM_MONITOR_PLAYBACK_STREAM, | |
90 | LINE6_INDEX_PCM_MONITOR_CAPTURE_BUFFER, | |
91 | LINE6_INDEX_PCM_MONITOR_CAPTURE_STREAM, | |
1027f476 | 92 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE |
0ca54888 MG |
93 | LINE6_INDEX_PCM_IMPULSE_PLAYBACK_BUFFER, |
94 | LINE6_INDEX_PCM_IMPULSE_PLAYBACK_STREAM, | |
95 | LINE6_INDEX_PCM_IMPULSE_CAPTURE_BUFFER, | |
96 | LINE6_INDEX_PCM_IMPULSE_CAPTURE_STREAM, | |
1027f476 | 97 | #endif |
0ca54888 MG |
98 | LINE6_INDEX_PAUSE_PLAYBACK, |
99 | LINE6_INDEX_PREPARED, | |
100 | ||
101 | /* individual bit masks: */ | |
102 | LINE6_BIT(PCM_ALSA_PLAYBACK_BUFFER), | |
103 | LINE6_BIT(PCM_ALSA_PLAYBACK_STREAM), | |
104 | LINE6_BIT(PCM_ALSA_CAPTURE_BUFFER), | |
105 | LINE6_BIT(PCM_ALSA_CAPTURE_STREAM), | |
106 | LINE6_BIT(PCM_MONITOR_PLAYBACK_BUFFER), | |
107 | LINE6_BIT(PCM_MONITOR_PLAYBACK_STREAM), | |
108 | LINE6_BIT(PCM_MONITOR_CAPTURE_BUFFER), | |
109 | LINE6_BIT(PCM_MONITOR_CAPTURE_STREAM), | |
1027f476 | 110 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE |
0ca54888 MG |
111 | LINE6_BIT(PCM_IMPULSE_PLAYBACK_BUFFER), |
112 | LINE6_BIT(PCM_IMPULSE_PLAYBACK_STREAM), | |
113 | LINE6_BIT(PCM_IMPULSE_CAPTURE_BUFFER), | |
114 | LINE6_BIT(PCM_IMPULSE_CAPTURE_STREAM), | |
1027f476 | 115 | #endif |
0ca54888 MG |
116 | LINE6_BIT(PAUSE_PLAYBACK), |
117 | LINE6_BIT(PREPARED), | |
1027f476 | 118 | |
0ca54888 MG |
119 | /* combined bit masks (by operation): */ |
120 | LINE6_BITS_PCM_ALSA_BUFFER = | |
121 | LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER | | |
122 | LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER, | |
123 | ||
124 | LINE6_BITS_PCM_ALSA_STREAM = | |
125 | LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM | | |
126 | LINE6_BIT_PCM_ALSA_CAPTURE_STREAM, | |
127 | ||
128 | LINE6_BITS_PCM_MONITOR = | |
129 | LINE6_BIT_PCM_MONITOR_PLAYBACK_BUFFER | | |
130 | LINE6_BIT_PCM_MONITOR_PLAYBACK_STREAM | | |
131 | LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER | | |
132 | LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM, | |
133 | ||
134 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE | |
135 | LINE6_BITS_PCM_IMPULSE = | |
136 | LINE6_BIT_PCM_IMPULSE_PLAYBACK_BUFFER | | |
137 | LINE6_BIT_PCM_IMPULSE_PLAYBACK_STREAM | | |
138 | LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER | | |
139 | LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM, | |
140 | #endif | |
141 | ||
142 | /* combined bit masks (by direction): */ | |
143 | LINE6_BITS_PLAYBACK_BUFFER = | |
144 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE | |
145 | LINE6_BIT_PCM_IMPULSE_PLAYBACK_BUFFER | | |
146 | #endif | |
147 | LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER | | |
148 | LINE6_BIT_PCM_MONITOR_PLAYBACK_BUFFER , | |
149 | ||
150 | LINE6_BITS_PLAYBACK_STREAM = | |
151 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE | |
152 | LINE6_BIT_PCM_IMPULSE_PLAYBACK_STREAM | | |
153 | #endif | |
154 | LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM | | |
155 | LINE6_BIT_PCM_MONITOR_PLAYBACK_STREAM , | |
156 | ||
157 | LINE6_BITS_CAPTURE_BUFFER = | |
1027f476 | 158 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE |
0ca54888 | 159 | LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER | |
1027f476 | 160 | #endif |
0ca54888 MG |
161 | LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER | |
162 | LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER , | |
1027f476 | 163 | |
0ca54888 | 164 | LINE6_BITS_CAPTURE_STREAM = |
1027f476 | 165 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE |
0ca54888 | 166 | LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM | |
1027f476 | 167 | #endif |
0ca54888 MG |
168 | LINE6_BIT_PCM_ALSA_CAPTURE_STREAM | |
169 | LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM, | |
170 | ||
171 | LINE6_BITS_STREAM = | |
172 | LINE6_BITS_PLAYBACK_STREAM | | |
173 | LINE6_BITS_CAPTURE_STREAM | |
705ececd MG |
174 | }; |
175 | ||
176 | struct line6_pcm_properties { | |
177 | struct snd_pcm_hardware snd_line6_playback_hw, snd_line6_capture_hw; | |
178 | struct snd_pcm_hw_constraint_ratdens snd_line6_rates; | |
179 | int bytes_per_frame; | |
180 | }; | |
181 | ||
a49e4838 | 182 | struct snd_line6_pcm { |
705ececd MG |
183 | /** |
184 | Pointer back to the Line6 driver data structure. | |
185 | */ | |
186 | struct usb_line6 *line6; | |
187 | ||
188 | /** | |
189 | Properties. | |
190 | */ | |
191 | struct line6_pcm_properties *properties; | |
192 | ||
193 | /** | |
194 | ALSA pcm stream | |
195 | */ | |
196 | struct snd_pcm *pcm; | |
197 | ||
198 | /** | |
199 | URBs for audio playback. | |
200 | */ | |
201 | struct urb *urb_audio_out[LINE6_ISO_BUFFERS]; | |
202 | ||
203 | /** | |
204 | URBs for audio capture. | |
205 | */ | |
206 | struct urb *urb_audio_in[LINE6_ISO_BUFFERS]; | |
207 | ||
208 | /** | |
1027f476 MG |
209 | Temporary buffer for playback. |
210 | Since the packet size is not known in advance, this buffer is | |
211 | large enough to store maximum size packets. | |
705ececd | 212 | */ |
1027f476 | 213 | unsigned char *buffer_out; |
705ececd MG |
214 | |
215 | /** | |
216 | Temporary buffer for capture. | |
a49e4838 GKH |
217 | Since the packet size is not known in advance, this buffer is |
218 | large enough to store maximum size packets. | |
705ececd MG |
219 | */ |
220 | unsigned char *buffer_in; | |
221 | ||
1027f476 MG |
222 | /** |
223 | Previously captured frame (for software monitoring). | |
224 | */ | |
225 | unsigned char *prev_fbuf; | |
226 | ||
227 | /** | |
228 | Size of previously captured frame (for software monitoring). | |
229 | */ | |
230 | int prev_fsize; | |
231 | ||
705ececd MG |
232 | /** |
233 | Free frame position in the playback buffer. | |
234 | */ | |
235 | snd_pcm_uframes_t pos_out; | |
236 | ||
237 | /** | |
238 | Count processed bytes for playback. | |
a49e4838 GKH |
239 | This is modulo period size (to determine when a period is |
240 | finished). | |
705ececd MG |
241 | */ |
242 | unsigned bytes_out; | |
243 | ||
244 | /** | |
245 | Counter to create desired playback sample rate. | |
246 | */ | |
247 | unsigned count_out; | |
248 | ||
249 | /** | |
250 | Playback period size in bytes | |
251 | */ | |
252 | unsigned period_out; | |
253 | ||
254 | /** | |
255 | Processed frame position in the playback buffer. | |
a49e4838 GKH |
256 | The contents of the output ring buffer have been consumed by |
257 | the USB subsystem (i.e., sent to the USB device) up to this | |
258 | position. | |
705ececd MG |
259 | */ |
260 | snd_pcm_uframes_t pos_out_done; | |
261 | ||
262 | /** | |
263 | Count processed bytes for capture. | |
a49e4838 GKH |
264 | This is modulo period size (to determine when a period is |
265 | finished). | |
705ececd MG |
266 | */ |
267 | unsigned bytes_in; | |
268 | ||
269 | /** | |
270 | Counter to create desired capture sample rate. | |
271 | */ | |
272 | unsigned count_in; | |
273 | ||
274 | /** | |
275 | Capture period size in bytes | |
276 | */ | |
277 | unsigned period_in; | |
278 | ||
279 | /** | |
280 | Processed frame position in the capture buffer. | |
a49e4838 GKH |
281 | The contents of the output ring buffer have been consumed by |
282 | the USB subsystem (i.e., sent to the USB device) up to this | |
283 | position. | |
705ececd MG |
284 | */ |
285 | snd_pcm_uframes_t pos_in_done; | |
286 | ||
287 | /** | |
288 | Bit mask of active playback URBs. | |
289 | */ | |
290 | unsigned long active_urb_out; | |
291 | ||
292 | /** | |
293 | Maximum size of USB packet. | |
294 | */ | |
295 | int max_packet_size; | |
296 | ||
297 | /** | |
298 | USB endpoint for listening to audio data. | |
299 | */ | |
300 | int ep_audio_read; | |
301 | ||
302 | /** | |
303 | USB endpoint for writing audio data. | |
304 | */ | |
305 | int ep_audio_write; | |
306 | ||
307 | /** | |
308 | Bit mask of active capture URBs. | |
309 | */ | |
310 | unsigned long active_urb_in; | |
311 | ||
312 | /** | |
313 | Bit mask of playback URBs currently being unlinked. | |
314 | */ | |
315 | unsigned long unlink_urb_out; | |
316 | ||
317 | /** | |
318 | Bit mask of capture URBs currently being unlinked. | |
319 | */ | |
320 | unsigned long unlink_urb_in; | |
321 | ||
322 | /** | |
323 | Spin lock to protect updates of the playback buffer positions (not | |
324 | contents!) | |
325 | */ | |
326 | spinlock_t lock_audio_out; | |
327 | ||
328 | /** | |
329 | Spin lock to protect updates of the capture buffer positions (not | |
330 | contents!) | |
331 | */ | |
332 | spinlock_t lock_audio_in; | |
333 | ||
334 | /** | |
335 | Spin lock to protect trigger. | |
336 | */ | |
337 | spinlock_t lock_trigger; | |
338 | ||
339 | /** | |
340 | PCM playback volume (left and right). | |
341 | */ | |
1027f476 MG |
342 | int volume_playback[2]; |
343 | ||
344 | /** | |
345 | PCM monitor volume. | |
346 | */ | |
347 | int volume_monitor; | |
348 | ||
349 | #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE | |
350 | /** | |
351 | Volume of impulse response test signal (if zero, test is disabled). | |
352 | */ | |
353 | int impulse_volume; | |
354 | ||
355 | /** | |
356 | Period of impulse response test signal. | |
357 | */ | |
358 | int impulse_period; | |
359 | ||
360 | /** | |
361 | Counter for impulse response test signal. | |
362 | */ | |
363 | int impulse_count; | |
364 | #endif | |
705ececd MG |
365 | |
366 | /** | |
0ca54888 | 367 | Several status bits (see LINE6_BIT_*). |
705ececd MG |
368 | */ |
369 | unsigned long flags; | |
1027f476 MG |
370 | |
371 | int last_frame_in, last_frame_out; | |
705ececd MG |
372 | }; |
373 | ||
a49e4838 GKH |
374 | extern int line6_init_pcm(struct usb_line6 *line6, |
375 | struct line6_pcm_properties *properties); | |
705ececd MG |
376 | extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd); |
377 | extern int snd_line6_prepare(struct snd_pcm_substream *substream); | |
1027f476 | 378 | extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm); |
0ca54888 MG |
379 | extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels); |
380 | extern int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels); | |
1027f476 | 381 | |
705ececd | 382 | #endif |