2 * Line6 Linux USB driver - 0.9.1beta
4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
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.
13 PCM interface to POD series devices.
19 #include <sound/pcm.h>
25 #define LINE6_ISO_BUFFERS 2
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.
33 #define LINE6_ISO_PACKETS 1
35 /* in a "full speed" device (such as the PODxt Pro) this means 1ms */
36 #define LINE6_ISO_INTERVAL 1
38 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
39 #define LINE6_IMPULSE_DEFAULT_PERIOD 100
43 Get substream from Line6 PCM data structure
45 #define get_substream(line6pcm, stream) \
46 (line6pcm->pcm->streams[stream].substream)
49 PCM mode bits and masks.
50 "ALSA": operations triggered by applications via ALSA
51 "MONITOR": software monitoring
52 "IMPULSE": optional impulse response operation
55 /* individual bits: */
56 BIT_PCM_ALSA_PLAYBACK
,
58 BIT_PCM_MONITOR_PLAYBACK
,
59 BIT_PCM_MONITOR_CAPTURE
,
60 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
61 BIT_PCM_IMPULSE_PLAYBACK
,
62 BIT_PCM_IMPULSE_CAPTURE
,
67 /* individual masks: */
69 MASK_PCM_ALSA_PLAYBACK
= 1 << BIT_PCM_ALSA_PLAYBACK
,
70 MASK_PCM_ALSA_CAPTURE
= 1 << BIT_PCM_ALSA_CAPTURE
,
71 MASK_PCM_MONITOR_PLAYBACK
= 1 << BIT_PCM_MONITOR_PLAYBACK
,
72 MASK_PCM_MONITOR_CAPTURE
= 1 << BIT_PCM_MONITOR_CAPTURE
,
73 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
74 MASK_PCM_IMPULSE_PLAYBACK
= 1 << BIT_PCM_IMPULSE_PLAYBACK
,
75 MASK_PCM_IMPULSE_CAPTURE
= 1 << BIT_PCM_IMPULSE_CAPTURE
,
77 MASK_PAUSE_PLAYBACK
= 1 << BIT_PAUSE_PLAYBACK
,
78 MASK_PREPARED
= 1 << BIT_PREPARED
,
81 /* combined masks (by operation): */
82 MASK_PCM_ALSA
= MASK_PCM_ALSA_PLAYBACK
| MASK_PCM_ALSA_CAPTURE
,
83 MASK_PCM_MONITOR
= MASK_PCM_MONITOR_PLAYBACK
| MASK_PCM_MONITOR_CAPTURE
,
84 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
85 MASK_PCM_IMPULSE
= MASK_PCM_IMPULSE_PLAYBACK
| MASK_PCM_IMPULSE_CAPTURE
,
88 /* combined masks (by direction): */
89 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
91 MASK_PCM_ALSA_PLAYBACK
| MASK_PCM_MONITOR_PLAYBACK
|
92 MASK_PCM_IMPULSE_PLAYBACK
,
94 MASK_PCM_ALSA_CAPTURE
| MASK_PCM_MONITOR_CAPTURE
|
95 MASK_PCM_IMPULSE_CAPTURE
97 MASK_PLAYBACK
= MASK_PCM_ALSA_PLAYBACK
| MASK_PCM_MONITOR_PLAYBACK
,
98 MASK_CAPTURE
= MASK_PCM_ALSA_CAPTURE
| MASK_PCM_MONITOR_CAPTURE
102 struct line6_pcm_properties
{
103 struct snd_pcm_hardware snd_line6_playback_hw
, snd_line6_capture_hw
;
104 struct snd_pcm_hw_constraint_ratdens snd_line6_rates
;
108 struct snd_line6_pcm
{
110 Pointer back to the Line6 driver data structure.
112 struct usb_line6
*line6
;
117 struct line6_pcm_properties
*properties
;
125 URBs for audio playback.
127 struct urb
*urb_audio_out
[LINE6_ISO_BUFFERS
];
130 URBs for audio capture.
132 struct urb
*urb_audio_in
[LINE6_ISO_BUFFERS
];
135 Temporary buffer for playback.
136 Since the packet size is not known in advance, this buffer is
137 large enough to store maximum size packets.
139 unsigned char *buffer_out
;
142 Temporary buffer for capture.
143 Since the packet size is not known in advance, this buffer is
144 large enough to store maximum size packets.
146 unsigned char *buffer_in
;
149 Previously captured frame (for software monitoring).
151 unsigned char *prev_fbuf
;
154 Size of previously captured frame (for software monitoring).
159 Free frame position in the playback buffer.
161 snd_pcm_uframes_t pos_out
;
164 Count processed bytes for playback.
165 This is modulo period size (to determine when a period is
171 Counter to create desired playback sample rate.
176 Playback period size in bytes
181 Processed frame position in the playback buffer.
182 The contents of the output ring buffer have been consumed by
183 the USB subsystem (i.e., sent to the USB device) up to this
186 snd_pcm_uframes_t pos_out_done
;
189 Count processed bytes for capture.
190 This is modulo period size (to determine when a period is
196 Counter to create desired capture sample rate.
201 Capture period size in bytes
206 Processed frame position in the capture buffer.
207 The contents of the output ring buffer have been consumed by
208 the USB subsystem (i.e., sent to the USB device) up to this
211 snd_pcm_uframes_t pos_in_done
;
214 Bit mask of active playback URBs.
216 unsigned long active_urb_out
;
219 Maximum size of USB packet.
224 USB endpoint for listening to audio data.
229 USB endpoint for writing audio data.
234 Bit mask of active capture URBs.
236 unsigned long active_urb_in
;
239 Bit mask of playback URBs currently being unlinked.
241 unsigned long unlink_urb_out
;
244 Bit mask of capture URBs currently being unlinked.
246 unsigned long unlink_urb_in
;
249 Spin lock to protect updates of the playback buffer positions (not
252 spinlock_t lock_audio_out
;
255 Spin lock to protect updates of the capture buffer positions (not
258 spinlock_t lock_audio_in
;
261 Spin lock to protect trigger.
263 spinlock_t lock_trigger
;
266 PCM playback volume (left and right).
268 int volume_playback
[2];
275 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
277 Volume of impulse response test signal (if zero, test is disabled).
282 Period of impulse response test signal.
287 Counter for impulse response test signal.
293 Several status bits (see BIT_*).
297 int last_frame_in
, last_frame_out
;
300 extern int line6_init_pcm(struct usb_line6
*line6
,
301 struct line6_pcm_properties
*properties
);
302 extern int snd_line6_trigger(struct snd_pcm_substream
*substream
, int cmd
);
303 extern int snd_line6_prepare(struct snd_pcm_substream
*substream
);
304 extern void line6_pcm_disconnect(struct snd_line6_pcm
*line6pcm
);
305 extern int line6_pcm_start(struct snd_line6_pcm
*line6pcm
, int channels
);
306 extern int line6_pcm_stop(struct snd_line6_pcm
*line6pcm
, int channels
);
308 #define PRINT_FRAME_DIFF(op) { \
309 static int diff_prev = 1000; \
310 int diff = line6pcm->last_frame_out - line6pcm->last_frame_in; \
311 if ((diff != diff_prev) && (abs(diff) < 100)) { \
312 printk(KERN_INFO "%s frame diff = %d\n", op, diff); \