2 * Line 6 Linux USB driver
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>
24 #define LINE6_ISO_BUFFERS 2
27 number of USB frames per URB
28 The Line 6 Windows driver always transmits two frames per packet, but
29 the Linux driver performs significantly better (i.e., lower latency)
30 with only one frame per packet.
32 #define LINE6_ISO_PACKETS 1
34 /* in a "full speed" device (such as the PODxt Pro) this means 1ms */
35 #define LINE6_ISO_INTERVAL 1
37 #define LINE6_IMPULSE_DEFAULT_PERIOD 100
40 Get substream from Line 6 PCM data structure
42 #define get_substream(line6pcm, stream) \
43 (line6pcm->pcm->streams[stream].substream)
48 There are several features of the Line 6 USB driver which require PCM
49 data to be exchanged with the device:
50 *) PCM playback and capture via ALSA
51 *) software monitoring (for devices without hardware monitoring)
52 *) optional impulse response measurement
53 However, from the device's point of view, there is just a single
54 capture and playback stream, which must be shared between these
55 subsystems. It is therefore necessary to maintain the state of the
56 subsystems with respect to PCM usage.
58 We define two bit flags, "opened" and "running", for each playback
59 or capture stream. Both can contain the bit flag corresponding to
61 LINE6_STREAM_PCM = ALSA PCM playback or capture
62 LINE6_STREAM_MONITOR = software monitoring
63 IMPULSE = optional impulse response measurement
64 The opened flag indicates whether the buffer is allocated while
65 the running flag indicates whether the stream is running.
67 For monitor or impulse operations, the driver needs to call
68 line6_pcm_acquire() or line6_pcm_release() with the appropriate
79 /* misc bit flags for PCM operation */
81 LINE6_FLAG_PAUSE_PLAYBACK
,
85 struct line6_pcm_properties
{
86 struct snd_pcm_hardware playback_hw
, capture_hw
;
87 struct snd_pcm_hw_constraint_ratdens rates
;
91 struct line6_pcm_stream
{
93 struct urb
*urbs
[LINE6_ISO_BUFFERS
];
96 * Since the packet size is not known in advance, this buffer is
97 * large enough to store maximum size packets.
99 unsigned char *buffer
;
101 /* Free frame position in the buffer. */
102 snd_pcm_uframes_t pos
;
104 /* Count processed bytes;
105 * This is modulo period size (to determine when a period is finished).
109 /* Counter to create desired sample rate */
112 /* period size in bytes */
115 /* Processed frame position in the buffer;
116 * The contents of the ring buffer have been consumed by the USB
117 * subsystem (i.e., sent to the USB device) up to this position.
119 snd_pcm_uframes_t pos_done
;
121 /* Bit mask of active URBs */
122 unsigned long active_urbs
;
124 /* Bit mask of URBs currently being unlinked */
125 unsigned long unlink_urbs
;
127 /* Spin lock to protect updates of the buffer positions (not contents)
131 /* Bit flags for operational stream types */
132 unsigned long opened
;
134 /* Bit flags for running stream types */
135 unsigned long running
;
140 struct snd_line6_pcm
{
141 /* Pointer back to the Line 6 driver data structure */
142 struct usb_line6
*line6
;
145 struct line6_pcm_properties
*properties
;
147 /* ALSA pcm stream */
150 /* protection to state changes of in/out streams */
151 struct mutex state_mutex
;
153 /* Capture and playback streams */
154 struct line6_pcm_stream in
;
155 struct line6_pcm_stream out
;
157 /* Previously captured frame (for software monitoring) */
158 unsigned char *prev_fbuf
;
160 /* Size of previously captured frame (for software monitoring) */
163 /* Maximum size of USB packet */
166 /* PCM playback volume (left and right) */
167 int volume_playback
[2];
169 /* PCM monitor volume */
172 /* Volume of impulse response test signal (if zero, test is disabled) */
175 /* Period of impulse response test signal */
178 /* Counter for impulse response test signal */
181 /* Several status bits (see LINE6_FLAG_*) */
185 extern int line6_init_pcm(struct usb_line6
*line6
,
186 struct line6_pcm_properties
*properties
);
187 extern int snd_line6_trigger(struct snd_pcm_substream
*substream
, int cmd
);
188 extern int snd_line6_prepare(struct snd_pcm_substream
*substream
);
189 extern int snd_line6_hw_params(struct snd_pcm_substream
*substream
,
190 struct snd_pcm_hw_params
*hw_params
);
191 extern int snd_line6_hw_free(struct snd_pcm_substream
*substream
);
192 extern snd_pcm_uframes_t
snd_line6_pointer(struct snd_pcm_substream
*substream
);
193 extern void line6_pcm_disconnect(struct snd_line6_pcm
*line6pcm
);
194 extern int line6_pcm_acquire(struct snd_line6_pcm
*line6pcm
, int type
);
195 extern void line6_pcm_release(struct snd_line6_pcm
*line6pcm
, int type
);