Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcm.h
Go to the documentation of this file.
1 /*
2  * Line6 Linux USB driver - 0.9.1beta
3  *
4  * Copyright (C) 2004-2010 Markus Grabner ([email protected])
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 
19 #include <sound/pcm.h>
20 
21 #include "driver.h"
22 #include "usbdefs.h"
23 
24 /* number of URBs */
25 #define LINE6_ISO_BUFFERS 2
26 
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
34 
35 /* in a "full speed" device (such as the PODxt Pro) this means 1ms */
36 #define LINE6_ISO_INTERVAL 1
37 
38 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
39 #define LINE6_IMPULSE_DEFAULT_PERIOD 100
40 #endif
41 
42 /*
43  Get substream from Line6 PCM data structure
44 */
45 #define get_substream(line6pcm, stream) \
46  (line6pcm->pcm->streams[stream].substream)
47 
48 /*
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).
81 */
82 enum {
83  /* individual bit indices: */
92 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
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,
97 #endif
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),
110 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
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),
115 #endif
116  LINE6_BIT(PAUSE_PLAYBACK),
117  LINE6_BIT(PREPARED),
118 
119  /* combined bit masks (by operation): */
121  LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER |
122  LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER,
123 
125  LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM |
126  LINE6_BIT_PCM_ALSA_CAPTURE_STREAM,
127 
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): */
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 
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 
158 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
159  LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER |
160 #endif
161  LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER |
162  LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER ,
163 
165 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
166  LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM |
167 #endif
168  LINE6_BIT_PCM_ALSA_CAPTURE_STREAM |
169  LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM,
170 
174 };
175 
177  struct snd_pcm_hardware snd_line6_playback_hw, snd_line6_capture_hw;
180 };
181 
186  struct usb_line6 *line6;
187 
192 
196  struct snd_pcm *pcm;
197 
202 
207 
213  unsigned char *buffer_out;
214 
220  unsigned char *buffer_in;
221 
225  unsigned char *prev_fbuf;
226 
231 
236 
242  unsigned bytes_out;
243 
247  unsigned count_out;
248 
252  unsigned period_out;
253 
261 
267  unsigned bytes_in;
268 
272  unsigned count_in;
273 
277  unsigned period_in;
278 
286 
290  unsigned long active_urb_out;
291 
296 
301 
306 
310  unsigned long active_urb_in;
311 
315  unsigned long unlink_urb_out;
316 
320  unsigned long unlink_urb_in;
321 
327 
333 
338 
343 
348 
349 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
350 
353  int impulse_volume;
354 
358  int impulse_period;
359 
363  int impulse_count;
364 #endif
365 
369  unsigned long flags;
370 
372 };
373 
374 extern int line6_init_pcm(struct usb_line6 *line6,
375  struct line6_pcm_properties *properties);
376 extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
377 extern int snd_line6_prepare(struct snd_pcm_substream *substream);
378 extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
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);
381 
382 #endif