12 #include <linux/slab.h>
27 static void change_volume(
struct urb *urb_out,
int volume[],
32 if (volume[0] == 256 && volume[1] == 256)
35 if (bytes_per_frame == 4) {
37 p = (
short *)urb_out->transfer_buffer;
38 buf_end = p + urb_out->transfer_buffer_length /
sizeof(*p);
40 for (; p < buf_end; ++
p) {
41 *p = (*p * volume[chn & 1]) >> 8;
44 }
else if (bytes_per_frame == 6) {
45 unsigned char *
p, *buf_end;
46 p = (
unsigned char *)urb_out->transfer_buffer;
47 buf_end = p + urb_out->transfer_buffer_length;
49 for (; p < buf_end; p += 3) {
51 val = p[0] + (p[1] << 8) + ((
signed char)p[2] << 16);
52 val = (val * volume[chn & 1]) >> 8;
61 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
66 static void create_impulse_test_signal(
struct snd_line6_pcm *line6pcm,
67 struct urb *urb_out,
int bytes_per_frame)
71 if (bytes_per_frame == 4) {
74 short *po = (
short *)urb_out->transfer_buffer;
76 for (i = 0; i < frames; ++
i) {
82 }
else if (bytes_per_frame == 6) {
85 unsigned char *po = urb_out->transfer_buffer;
87 for (i = 0; i < frames; ++
i) {
88 for (j = 0; j < bytes_per_frame / 2; ++
j)
98 if (--line6pcm->impulse_count <= 0) {
99 ((
unsigned char *)(urb_out->transfer_buffer))[bytes_per_frame -
101 line6pcm->impulse_volume;
102 line6pcm->impulse_count = line6pcm->impulse_period;
111 static void add_monitor_signal(
struct urb *urb_out,
unsigned char *signal,
112 int volume,
int bytes_per_frame)
117 if (bytes_per_frame == 4) {
118 short *pi, *po, *buf_end;
119 pi = (
short *)signal;
120 po = (
short *)urb_out->transfer_buffer;
121 buf_end = po + urb_out->transfer_buffer_length /
sizeof(*po);
123 for (; po < buf_end; ++pi, ++po)
124 *po += (*pi * volume) >> 8;
136 static int submit_audio_out_urb(
struct snd_line6_pcm *line6pcm)
140 int i, urb_size, urb_frames;
142 const int bytes_per_frame = line6pcm->
properties->bytes_per_frame;
143 const int frame_increment =
144 line6pcm->
properties->snd_line6_rates.rats[0].num_min;
145 const int frame_factor =
146 line6pcm->
properties->snd_line6_rates.rats[0].den *
156 dev_err(line6pcm->
line6->ifcdev,
"no free URB found\n");
166 struct usb_iso_packet_descriptor *fout =
167 &urb_out->iso_frame_desc[
i];
180 fout->offset = urb_size;
181 fout->length = fsize;
188 dev_err(line6pcm->
line6->ifcdev,
"driver bug: urb_size = 0\n");
193 urb_out->transfer_buffer =
196 urb_out->transfer_buffer_length = urb_size;
197 urb_out->context = line6pcm;
213 memcpy(urb_out->transfer_buffer,
215 line6pcm->
pos_out * bytes_per_frame,
216 len * bytes_per_frame);
217 memcpy(urb_out->transfer_buffer +
218 len * bytes_per_frame, runtime->
dma_area,
219 (urb_frames - len) * bytes_per_frame);
221 dev_err(line6pcm->
line6->ifcdev,
"driver bug: len = %d\n", len);
223 memcpy(urb_out->transfer_buffer,
225 line6pcm->
pos_out * bytes_per_frame,
226 urb_out->transfer_buffer_length);
229 line6pcm->
pos_out += urb_frames;
233 memset(urb_out->transfer_buffer, 0,
234 urb_out->transfer_buffer_length);
240 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
241 if (line6pcm->
flags & LINE6_BITS_PCM_IMPULSE) {
242 create_impulse_test_signal(line6pcm, urb_out,
244 if (line6pcm->
flags & LINE6_BIT_PCM_ALSA_CAPTURE_STREAM) {
246 urb_out->transfer_buffer,
248 transfer_buffer_length);
250 urb_out->transfer_buffer_length);
259 add_monitor_signal(urb_out, line6pcm->
prev_fbuf,
262 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
266 #ifdef CONFIG_LINE6_USB_DUMP_PCM
268 struct usb_iso_packet_descriptor *fout =
269 &urb_out->iso_frame_desc[
i];
270 line6_write_hexdump(line6pcm->
line6,
'P',
271 urb_out->transfer_buffer + fout->offset,
282 "URB out #%d submission failed (%d)\n", index, ret);
296 ret = submit_audio_out_urb(line6pcm);
340 }
while (--timeout > 0);
363 static void audio_out_callback(
struct urb *
urb)
372 #if USE_CLEAR_BUFFER_WORKAROUND
373 memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
386 for (i = LINE6_ISO_PACKETS; i--;)
387 length += urb->iso_frame_desc[i].length;
394 length / line6pcm->
properties->bytes_per_frame;
402 for (i = LINE6_ISO_PACKETS; i--;)
403 if (urb->iso_frame_desc[i].status == -
EXDEV) {
414 submit_audio_out_urb(line6pcm);
439 runtime->
hw = line6pcm->
properties->snd_line6_playback_hw;
458 if (line6pcm ==
NULL) {
461 if (substream->
pcm->private_data ==
NULL)
480 line6pcm->
period_out = params_period_bytes(hw_params);
545 .open = snd_line6_playback_open,
546 .close = snd_line6_playback_close,
548 .hw_params = snd_line6_playback_hw_params,
549 .hw_free = snd_line6_playback_hw_free,
552 .pointer = snd_line6_playback_pointer,
572 urb->dev = line6pcm->
line6->usbdev;
574 usb_sndisocpipe(line6pcm->
line6->usbdev,
577 urb->transfer_flags = URB_ISO_ASAP;
578 urb->start_frame = -1;
581 urb->error_count = 0;
582 urb->complete = audio_out_callback;