Add linux-next specific files for 20110801
[linux-2.6/next.git] / drivers / staging / line6 / pcm.h
blob77055b3724ad1dac63379aca7b60cc891f305ac2
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
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
57 enum {
58 /* individual bits: */
59 BIT_PCM_ALSA_PLAYBACK,
60 BIT_PCM_ALSA_CAPTURE,
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,
66 #endif
67 BIT_PAUSE_PLAYBACK,
68 BIT_PREPARED,
70 /* individual masks: */
71 /* *INDENT-OFF* */
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,
79 #endif
80 MASK_PAUSE_PLAYBACK = 1 << BIT_PAUSE_PLAYBACK,
81 MASK_PREPARED = 1 << BIT_PREPARED,
82 /* *INDENT-ON* */
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,
89 #endif
91 /* combined masks (by direction): */
92 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
93 MASK_PLAYBACK =
94 MASK_PCM_ALSA_PLAYBACK | MASK_PCM_MONITOR_PLAYBACK |
95 MASK_PCM_IMPULSE_PLAYBACK,
96 MASK_CAPTURE =
97 MASK_PCM_ALSA_CAPTURE | MASK_PCM_MONITOR_CAPTURE |
98 MASK_PCM_IMPULSE_CAPTURE
99 #else
100 MASK_PLAYBACK = MASK_PCM_ALSA_PLAYBACK | MASK_PCM_MONITOR_PLAYBACK,
101 MASK_CAPTURE = MASK_PCM_ALSA_CAPTURE | MASK_PCM_MONITOR_CAPTURE
102 #endif
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;
108 int bytes_per_frame;
111 struct snd_line6_pcm {
113 Pointer back to the Line6 driver data structure.
115 struct usb_line6 *line6;
118 Properties.
120 struct line6_pcm_properties *properties;
123 ALSA pcm stream
125 struct snd_pcm *pcm;
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.
154 int index_out;
157 Previously captured frame (for software monitoring).
159 unsigned char *prev_fbuf;
162 Size of previously captured frame (for software monitoring).
164 int prev_fsize;
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
174 finished).
176 unsigned bytes_out;
179 Counter to create desired playback sample rate.
181 unsigned count_out;
184 Playback period size in bytes
186 unsigned period_out;
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
192 position.
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
199 finished).
201 unsigned bytes_in;
204 Counter to create desired capture sample rate.
206 unsigned count_in;
209 Capture period size in bytes
211 unsigned period_in;
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
217 position.
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.
229 int max_packet_size;
232 USB endpoint for listening to audio data.
234 int ep_audio_read;
237 USB endpoint for writing audio data.
239 int ep_audio_write;
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
258 contents!)
260 spinlock_t lock_audio_out;
263 Spin lock to protect updates of the capture buffer positions (not
264 contents!)
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];
279 PCM monitor volume.
281 int volume_monitor;
283 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
285 Volume of impulse response test signal (if zero, test is disabled).
287 int impulse_volume;
290 Period of impulse response test signal.
292 int impulse_period;
295 Counter for impulse response test signal.
297 int impulse_count;
298 #endif
301 Several status bits (see BIT_*).
303 unsigned long flags;
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); \
321 diff_prev = diff; \
325 #endif