Avoid beyond bounds copy while caching ACL
[zen-stable.git] / drivers / staging / line6 / pcm.h
blob55d8297dd3d9c5ff70572feb72e85e9a44b420d7
1 /*
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.
16 #ifndef PCM_H
17 #define PCM_H
19 #include <sound/pcm.h>
21 #include "driver.h"
22 #include "usbdefs.h"
24 /* number of URBs */
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
40 #endif
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
54 enum {
55 /* individual bits: */
56 BIT_PCM_ALSA_PLAYBACK,
57 BIT_PCM_ALSA_CAPTURE,
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,
63 #endif
64 BIT_PAUSE_PLAYBACK,
65 BIT_PREPARED,
67 /* individual masks: */
68 /* *INDENT-OFF* */
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,
76 #endif
77 MASK_PAUSE_PLAYBACK = 1 << BIT_PAUSE_PLAYBACK,
78 MASK_PREPARED = 1 << BIT_PREPARED,
79 /* *INDENT-ON* */
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,
86 #endif
88 /* combined masks (by direction): */
89 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
90 MASK_PLAYBACK =
91 MASK_PCM_ALSA_PLAYBACK | MASK_PCM_MONITOR_PLAYBACK |
92 MASK_PCM_IMPULSE_PLAYBACK,
93 MASK_CAPTURE =
94 MASK_PCM_ALSA_CAPTURE | MASK_PCM_MONITOR_CAPTURE |
95 MASK_PCM_IMPULSE_CAPTURE
96 #else
97 MASK_PLAYBACK = MASK_PCM_ALSA_PLAYBACK | MASK_PCM_MONITOR_PLAYBACK,
98 MASK_CAPTURE = MASK_PCM_ALSA_CAPTURE | MASK_PCM_MONITOR_CAPTURE
99 #endif
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;
105 int bytes_per_frame;
108 struct snd_line6_pcm {
110 Pointer back to the Line6 driver data structure.
112 struct usb_line6 *line6;
115 Properties.
117 struct line6_pcm_properties *properties;
120 ALSA pcm stream
122 struct snd_pcm *pcm;
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).
156 int prev_fsize;
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
166 finished).
168 unsigned bytes_out;
171 Counter to create desired playback sample rate.
173 unsigned count_out;
176 Playback period size in bytes
178 unsigned period_out;
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
184 position.
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
191 finished).
193 unsigned bytes_in;
196 Counter to create desired capture sample rate.
198 unsigned count_in;
201 Capture period size in bytes
203 unsigned period_in;
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
209 position.
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.
221 int max_packet_size;
224 USB endpoint for listening to audio data.
226 int ep_audio_read;
229 USB endpoint for writing audio data.
231 int ep_audio_write;
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
250 contents!)
252 spinlock_t lock_audio_out;
255 Spin lock to protect updates of the capture buffer positions (not
256 contents!)
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];
271 PCM monitor volume.
273 int volume_monitor;
275 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
277 Volume of impulse response test signal (if zero, test is disabled).
279 int impulse_volume;
282 Period of impulse response test signal.
284 int impulse_period;
287 Counter for impulse response test signal.
289 int impulse_count;
290 #endif
293 Several status bits (see BIT_*).
295 unsigned long flags;
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); \
313 diff_prev = diff; \
317 #endif