171
171
static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
172
struct snd_pcm_hw_params *hw_params)
172
struct snd_pcm_hw_params *hw_params)
174
174
debug("%s(%p)\n", __func__, sub);
175
175
return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
191
191
static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
192
48000, 64000, 88200, 96000, 176400, 192000 };
192
48000, 64000, 88200, 96000, 176400, 192000 };
194
194
static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
201
201
debug("%s(%p)\n", __func__, substream);
203
203
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
204
dev->period_out_count[index] = BYTES_PER_SAMPLE + 1;
205
dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
206
switch (dev->spec.data_alignment) {
209
out_pos = BYTES_PER_SAMPLE + 1;
217
dev->period_out_count[index] = out_pos;
218
dev->audio_out_buf_pos[index] = out_pos;
207
int in_pos = (dev->spec.data_alignment == 2) ? 0 : 2;
208
dev->period_in_count[index] = BYTES_PER_SAMPLE + in_pos;
209
dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE + in_pos;
222
switch (dev->spec.data_alignment) {
224
in_pos = BYTES_PER_SAMPLE + 2;
227
in_pos = BYTES_PER_SAMPLE;
235
dev->period_in_count[index] = in_pos;
236
dev->audio_in_buf_pos[index] = in_pos;
212
239
if (dev->streaming)
221
248
snd_pcm_limit_hw_rates(runtime);
223
250
bytes_per_sample = BYTES_PER_SAMPLE;
224
if (dev->spec.data_alignment == 2)
251
if (dev->spec.data_alignment >= 2)
225
252
bytes_per_sample++;
227
254
bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
254
281
struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
283
debug("%s(%p) cmd %d\n", __func__, sub, cmd);
257
286
case SNDRV_PCM_TRIGGER_START:
258
287
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
434
static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
435
const struct urb *urb,
436
const struct usb_iso_packet_descriptor *iso)
438
unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
442
if (iso->actual_length % (BYTES_PER_SAMPLE_USB * CHANNELS_PER_STREAM))
445
for (i = 0; i < iso->actual_length;) {
446
for (stream = 0; stream < dev->n_streams; stream++) {
447
struct snd_pcm_substream *sub = dev->sub_capture[stream];
448
char *audio_buf = NULL;
451
if (sub && !dev->input_panic) {
452
struct snd_pcm_runtime *rt = sub->runtime;
453
audio_buf = rt->dma_area;
454
sz = frames_to_bytes(rt, rt->buffer_size);
457
for (c = 0; c < CHANNELS_PER_STREAM; c++) {
458
/* 3 audio data bytes, followed by 1 check byte */
460
for (n = 0; n < BYTES_PER_SAMPLE; n++) {
461
audio_buf[dev->audio_in_buf_pos[stream]++] = usb_buf[i+n];
463
if (dev->audio_in_buf_pos[stream] == sz)
464
dev->audio_in_buf_pos[stream] = 0;
467
dev->period_in_count[stream] += BYTES_PER_SAMPLE;
470
i += BYTES_PER_SAMPLE;
472
if (usb_buf[i] != ((stream << 1) | c) &&
473
!dev->first_packet) {
474
if (!dev->input_panic)
475
printk(" EXPECTED: %02x got %02x, c %d, stream %d, i %d\n",
476
((stream << 1) | c), usb_buf[i], c, stream, i);
477
dev->input_panic = 1;
485
if (dev->first_packet > 0)
405
489
static void read_in_urb(struct snd_usb_caiaqdev *dev,
406
490
const struct urb *urb,
407
491
const struct usb_iso_packet_descriptor *iso)
420
504
read_in_urb_mode2(dev, urb, iso);
507
read_in_urb_mode3(dev, urb, iso);
424
511
if ((dev->input_panic || dev->output_panic) && !dev->warned) {
432
static void fill_out_urb(struct snd_usb_caiaqdev *dev,
434
const struct usb_iso_packet_descriptor *iso)
519
static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *dev,
521
const struct usb_iso_packet_descriptor *iso)
436
523
unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
437
524
struct snd_pcm_substream *sub;
457
544
/* fill in the check bytes */
458
545
if (dev->spec.data_alignment == 2 &&
459
546
i % (dev->n_streams * BYTES_PER_SAMPLE_USB) ==
460
(dev->n_streams * CHANNELS_PER_STREAM))
461
for (stream = 0; stream < dev->n_streams; stream++, i++)
462
usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
547
(dev->n_streams * CHANNELS_PER_STREAM))
548
for (stream = 0; stream < dev->n_streams; stream++, i++)
549
usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
553
static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
555
const struct usb_iso_packet_descriptor *iso)
557
unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
560
for (i = 0; i < iso->length;) {
561
for (stream = 0; stream < dev->n_streams; stream++) {
562
struct snd_pcm_substream *sub = dev->sub_playback[stream];
563
char *audio_buf = NULL;
567
struct snd_pcm_runtime *rt = sub->runtime;
568
audio_buf = rt->dma_area;
569
sz = frames_to_bytes(rt, rt->buffer_size);
572
for (c = 0; c < CHANNELS_PER_STREAM; c++) {
573
for (n = 0; n < BYTES_PER_SAMPLE; n++) {
575
usb_buf[i+n] = audio_buf[dev->audio_out_buf_pos[stream]++];
577
if (dev->audio_out_buf_pos[stream] == sz)
578
dev->audio_out_buf_pos[stream] = 0;
585
dev->period_out_count[stream] += BYTES_PER_SAMPLE;
587
i += BYTES_PER_SAMPLE;
589
/* fill in the check byte pattern */
590
usb_buf[i++] = (stream << 1) | c;
596
static inline void fill_out_urb(struct snd_usb_caiaqdev *dev,
598
const struct usb_iso_packet_descriptor *iso)
600
switch (dev->spec.data_alignment) {
603
fill_out_urb_mode_0(dev, urb, iso);
606
fill_out_urb_mode_3(dev, urb, iso);