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
42 #define LINE6_BACKUP_MONITOR_SIGNAL 0
43 #define LINE6_REUSE_DMA_AREA_FOR_PLAYBACK 0
46 Get substream from Line6 PCM data structure
48 #define get_substream(line6pcm, stream) \
49 (line6pcm->pcm->streams[stream].substream)
52 PCM mode bits and masks.
53 "ALSA": operations triggered by applications via ALSA
54 "MONITOR": software monitoring
55 "IMPULSE": optional impulse response operation
58 /* individual bits: */
59 BIT_PCM_ALSA_PLAYBACK
,
61 BIT_PCM_MONITOR_PLAYBACK
,
62 BIT_PCM_MONITOR_CAPTURE
,
63 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
64 BIT_PCM_IMPULSE_PLAYBACK
,
65 BIT_PCM_IMPULSE_CAPTURE
,
70 /* individual masks: */
72 MASK_PCM_ALSA_PLAYBACK
= 1 << BIT_PCM_ALSA_PLAYBACK
,
73 MASK_PCM_ALSA_CAPTURE
= 1 << BIT_PCM_ALSA_CAPTURE
,
74 MASK_PCM_MONITOR_PLAYBACK
= 1 << BIT_PCM_MONITOR_PLAYBACK
,
75 MASK_PCM_MONITOR_CAPTURE
= 1 << BIT_PCM_MONITOR_CAPTURE
,
76 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
77 MASK_PCM_IMPULSE_PLAYBACK
= 1 << BIT_PCM_IMPULSE_PLAYBACK
,
78 MASK_PCM_IMPULSE_CAPTURE
= 1 << BIT_PCM_IMPULSE_CAPTURE
,
80 MASK_PAUSE_PLAYBACK
= 1 << BIT_PAUSE_PLAYBACK
,
81 MASK_PREPARED
= 1 << BIT_PREPARED
,
84 /* combined masks (by operation): */
85 MASK_PCM_ALSA
= MASK_PCM_ALSA_PLAYBACK
| MASK_PCM_ALSA_CAPTURE
,
86 MASK_PCM_MONITOR
= MASK_PCM_MONITOR_PLAYBACK
| MASK_PCM_MONITOR_CAPTURE
,
87 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
88 MASK_PCM_IMPULSE
= MASK_PCM_IMPULSE_PLAYBACK
| MASK_PCM_IMPULSE_CAPTURE
,
91 /* combined masks (by direction): */
92 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
94 MASK_PCM_ALSA_PLAYBACK
| MASK_PCM_MONITOR_PLAYBACK
|
95 MASK_PCM_IMPULSE_PLAYBACK
,
97 MASK_PCM_ALSA_CAPTURE
| MASK_PCM_MONITOR_CAPTURE
|
98 MASK_PCM_IMPULSE_CAPTURE
100 MASK_PLAYBACK
= MASK_PCM_ALSA_PLAYBACK
| MASK_PCM_MONITOR_PLAYBACK
,
101 MASK_CAPTURE
= MASK_PCM_ALSA_CAPTURE
| MASK_PCM_MONITOR_CAPTURE
105 struct line6_pcm_properties
{
106 struct snd_pcm_hardware snd_line6_playback_hw
, snd_line6_capture_hw
;
107 struct snd_pcm_hw_constraint_ratdens snd_line6_rates
;
111 struct snd_line6_pcm
{
113 Pointer back to the Line6 driver data structure.
115 struct usb_line6
*line6
;
120 struct line6_pcm_properties
*properties
;
128 URBs for audio playback.
130 struct urb
*urb_audio_out
[LINE6_ISO_BUFFERS
];
133 URBs for audio capture.
135 struct urb
*urb_audio_in
[LINE6_ISO_BUFFERS
];
138 Temporary buffer for playback.
139 Since the packet size is not known in advance, this buffer is
140 large enough to store maximum size packets.
142 unsigned char *buffer_out
;
145 Temporary buffer for capture.
146 Since the packet size is not known in advance, this buffer is
147 large enough to store maximum size packets.
149 unsigned char *buffer_in
;
152 Temporary buffer index for playback.
157 Previously captured frame (for software monitoring).
159 unsigned char *prev_fbuf
;
162 Size of previously captured frame (for software monitoring).
167 Free frame position in the playback buffer.
169 snd_pcm_uframes_t pos_out
;
172 Count processed bytes for playback.
173 This is modulo period size (to determine when a period is
179 Counter to create desired playback sample rate.
184 Playback period size in bytes
189 Processed frame position in the playback buffer.
190 The contents of the output ring buffer have been consumed by
191 the USB subsystem (i.e., sent to the USB device) up to this
194 snd_pcm_uframes_t pos_out_done
;
197 Count processed bytes for capture.
198 This is modulo period size (to determine when a period is
204 Counter to create desired capture sample rate.
209 Capture period size in bytes
214 Processed frame position in the capture buffer.
215 The contents of the output ring buffer have been consumed by
216 the USB subsystem (i.e., sent to the USB device) up to this
219 snd_pcm_uframes_t pos_in_done
;
222 Bit mask of active playback URBs.
224 unsigned long active_urb_out
;
227 Maximum size of USB packet.
232 USB endpoint for listening to audio data.
237 USB endpoint for writing audio data.
242 Bit mask of active capture URBs.
244 unsigned long active_urb_in
;
247 Bit mask of playback URBs currently being unlinked.
249 unsigned long unlink_urb_out
;
252 Bit mask of capture URBs currently being unlinked.
254 unsigned long unlink_urb_in
;
257 Spin lock to protect updates of the playback buffer positions (not
260 spinlock_t lock_audio_out
;
263 Spin lock to protect updates of the capture buffer positions (not
266 spinlock_t lock_audio_in
;
269 Spin lock to protect trigger.
271 spinlock_t lock_trigger
;
274 PCM playback volume (left and right).
276 int volume_playback
[2];
283 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
285 Volume of impulse response test signal (if zero, test is disabled).
290 Period of impulse response test signal.
295 Counter for impulse response test signal.
301 Several status bits (see BIT_*).
305 int last_frame_in
, last_frame_out
;
308 extern int line6_init_pcm(struct usb_line6
*line6
,
309 struct line6_pcm_properties
*properties
);
310 extern int snd_line6_trigger(struct snd_pcm_substream
*substream
, int cmd
);
311 extern int snd_line6_prepare(struct snd_pcm_substream
*substream
);
312 extern void line6_pcm_disconnect(struct snd_line6_pcm
*line6pcm
);
313 extern int line6_pcm_start(struct snd_line6_pcm
*line6pcm
, int channels
);
314 extern int line6_pcm_stop(struct snd_line6_pcm
*line6pcm
, int channels
);
316 #define PRINT_FRAME_DIFF(op) { \
317 static int diff_prev = 1000; \
318 int diff = line6pcm->last_frame_out - line6pcm->last_frame_in; \
319 if ((diff != diff_prev) && (abs(diff) < 100)) { \
320 printk(KERN_INFO "%s frame diff = %d\n", op, diff); \