28 static const int rates_in_packet_size[] = { 228, 228, 420, 420, 404, 404 };
29 static const int rates_out_packet_size[] = { 228, 228, 420, 420, 604, 604 };
30 static const int rates[] = { 44100, 48000, 88200, 96000, 176400, 192000 };
31 static const int rates_alsaid[] = {
74 static int usb6fire_pcm_set_rate(
struct pcm_runtime *rt)
83 "setting samplerate %d.\n", rates[rt->
rate]);
98 "while setting samplerate %d.\n",
107 "setting samplerate %d.\n", rates[rt->
rate]);
132 static void usb6fire_pcm_stream_stop(
struct pcm_runtime *rt)
149 static int usb6fire_pcm_stream_start(
struct pcm_runtime *rt)
154 struct usb_iso_packet_descriptor *
packet;
165 packet->actual_length = 0;
171 usb6fire_pcm_stream_stop(rt);
182 usb6fire_pcm_stream_stop(rt);
195 unsigned int total_length = 0;
208 if (urb->
packets[i].actual_length > 4)
209 frame_count = (urb->
packets[
i].actual_length - 4)
215 src = (
u32 *) (urb->
buffer + total_length);
217 src = (
u32 *) (urb->
buffer - 1 + total_length);
221 total_length += urb->
packets[
i].length;
223 memcpy(dest, src, bytes_per_frame);
228 if (dest == dest_end) {
250 int bytes_per_frame = alsa_rt->
channels << 2;
264 if (urb->
packets[i].length > 4)
265 frame_count = (urb->
packets[
i].length - 4)
271 memcpy(dest, src, bytes_per_frame);
276 if (src == src_end) {
284 static void usb6fire_pcm_in_urb_handler(
struct urb *usb_urb)
286 struct pcm_urb *in_urb = usb_urb->context;
291 int total_length = 0;
301 if (in_urb->
packets[i].status) {
308 "stream disabled in in-urb handler.\n");
316 usb6fire_pcm_capture(sub, in_urb);
319 spin_unlock_irqrestore(&sub->
lock, flags);
322 spin_unlock_irqrestore(&sub->
lock, flags);
324 spin_unlock_irqrestore(&sub->
lock, flags);
328 out_urb->
packets[
i].offset = total_length;
333 total_length += out_urb->
packets[
i].length;
341 usb6fire_pcm_playback(sub, out_urb);
344 spin_unlock_irqrestore(&sub->
lock, flags);
347 spin_unlock_irqrestore(&sub->
lock, flags);
349 spin_unlock_irqrestore(&sub->
lock, flags);
354 if (out_urb->
packets[i].length >= 4) {
355 frame_count = (out_urb->
packets[
i].length - 4)
359 *(dest++) = frame_count;
373 static void usb6fire_pcm_out_urb_handler(
struct urb *usb_urb)
375 struct pcm_urb *urb = usb_urb->context;
394 alsa_rt->
hw = pcm_hw;
398 alsa_rt->
hw.rates = rates_alsaid[rt->
rate];
403 alsa_rt->
hw.rates = rates_alsaid[rt->
rate];
423 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
435 spin_unlock_irqrestore(&sub->
lock, flags);
439 usb6fire_pcm_stream_stop(rt);
462 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
477 if (alsa_rt->
rate == rates[rt->
rate])
486 ret = usb6fire_pcm_set_rate(rt);
491 ret = usb6fire_pcm_stream_start(rt);
495 "could not start pcm stream.\n");
505 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
519 spin_unlock_irqrestore(&sub->
lock, flags);
526 spin_unlock_irqrestore(&sub->
lock, flags);
537 struct pcm_substream *sub = usb6fire_pcm_get_substream(alsa_sub);
542 if (rt->
panic || !sub)
547 spin_unlock_irqrestore(&sub->
lock, flags);
552 .open = usb6fire_pcm_open,
553 .close = usb6fire_pcm_close,
555 .hw_params = usb6fire_pcm_hw_params,
556 .hw_free = usb6fire_pcm_hw_free,
557 .prepare = usb6fire_pcm_prepare,
558 .trigger = usb6fire_pcm_trigger,
559 .pointer = usb6fire_pcm_pointer,
564 void (*handler)(
struct urb *))
569 urb->
instance.transfer_buffer_length =
572 urb->
instance.pipe = in ? usb_rcvisocpipe(chip->
dev, ep)
573 : usb_sndisocpipe(chip->
dev, ep);
575 urb->
instance.transfer_flags = URB_ISO_ASAP;
602 usb6fire_pcm_init_urb(&rt->
in_urbs[i], chip,
true,
IN_EP,
603 usb6fire_pcm_in_urb_handler);
605 usb6fire_pcm_out_urb_handler);
630 "error preallocating pcm buffers.\n");