aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/usbaudio.c
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2006-01-12 02:19:21 -0500
committerJaroslav Kysela <perex@suse.cz>2006-03-22 04:22:27 -0500
commit9568f461e50c023e45ec702027bb1a5f60e443dc (patch)
tree5c38356197de86514be184244eabc6f86a0154e5 /sound/usb/usbaudio.c
parent7c79b7682ee6318a8e47173b158846ed0edd8f1a (diff)
[ALSA] usb-audio: factor out packet size calculation code
Modules: USB generic driver Move the common packet size calculation code from prepare_startup_playback_urb() and prepare_playback_urb() to a new function. Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'sound/usb/usbaudio.c')
-rw-r--r--sound/usb/usbaudio.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index d5013383fad7..f5aadb001986 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -475,6 +475,18 @@ static int retire_playback_sync_urb_hs(struct snd_usb_substream *subs,
475 return 0; 475 return 0;
476} 476}
477 477
478/* determine the number of frames in the next packet */
479static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
480{
481 if (subs->fill_max)
482 return subs->maxframesize;
483 else {
484 subs->phase = (subs->phase & 0xffff)
485 + (subs->freqm << subs->datainterval);
486 return min(subs->phase >> 16, subs->maxframesize);
487 }
488}
489
478/* 490/*
479 * Prepare urb for streaming before playback starts. 491 * Prepare urb for streaming before playback starts.
480 * 492 *
@@ -492,16 +504,7 @@ static int prepare_startup_playback_urb(struct snd_usb_substream *subs,
492 urb->dev = ctx->subs->dev; 504 urb->dev = ctx->subs->dev;
493 urb->number_of_packets = subs->packs_per_ms; 505 urb->number_of_packets = subs->packs_per_ms;
494 for (i = 0; i < subs->packs_per_ms; ++i) { 506 for (i = 0; i < subs->packs_per_ms; ++i) {
495 /* calculate the size of a packet */ 507 counts = snd_usb_audio_next_packet_size(subs);
496 if (subs->fill_max)
497 counts = subs->maxframesize; /* fixed */
498 else {
499 subs->phase = (subs->phase & 0xffff)
500 + (subs->freqm << subs->datainterval);
501 counts = subs->phase >> 16;
502 if (counts > subs->maxframesize)
503 counts = subs->maxframesize;
504 }
505 urb->iso_frame_desc[i].offset = offs * stride; 508 urb->iso_frame_desc[i].offset = offs * stride;
506 urb->iso_frame_desc[i].length = counts * stride; 509 urb->iso_frame_desc[i].length = counts * stride;
507 offs += counts; 510 offs += counts;
@@ -538,16 +541,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
538 urb->number_of_packets = 0; 541 urb->number_of_packets = 0;
539 spin_lock_irqsave(&subs->lock, flags); 542 spin_lock_irqsave(&subs->lock, flags);
540 for (i = 0; i < ctx->packets; i++) { 543 for (i = 0; i < ctx->packets; i++) {
541 /* calculate the size of a packet */ 544 counts = snd_usb_audio_next_packet_size(subs);
542 if (subs->fill_max)
543 counts = subs->maxframesize; /* fixed */
544 else {
545 subs->phase = (subs->phase & 0xffff)
546 + (subs->freqm << subs->datainterval);
547 counts = subs->phase >> 16;
548 if (counts > subs->maxframesize)
549 counts = subs->maxframesize;
550 }
551 /* set up descriptor */ 545 /* set up descriptor */
552 urb->iso_frame_desc[i].offset = offs * stride; 546 urb->iso_frame_desc[i].offset = offs * stride;
553 urb->iso_frame_desc[i].length = counts * stride; 547 urb->iso_frame_desc[i].length = counts * stride;