summaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2006-01-12 08:19:21 +0100
committerJaroslav Kysela <perex@suse.cz>2006-03-22 10:22:27 +0100
commit9568f461e50c023e45ec702027bb1a5f60e443dc (patch)
tree5c38356197de86514be184244eabc6f86a0154e5 /sound/usb
parent7c79b7682ee6318a8e47173b158846ed0edd8f1a (diff)
downloadop-kernel-dev-9568f461e50c023e45ec702027bb1a5f60e443dc.zip
op-kernel-dev-9568f461e50c023e45ec702027bb1a5f60e443dc.tar.gz
[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')
-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 d501338..f5aadb0 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,
return 0;
}
+/* determine the number of frames in the next packet */
+static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
+{
+ if (subs->fill_max)
+ return subs->maxframesize;
+ else {
+ subs->phase = (subs->phase & 0xffff)
+ + (subs->freqm << subs->datainterval);
+ return min(subs->phase >> 16, subs->maxframesize);
+ }
+}
+
/*
* Prepare urb for streaming before playback starts.
*
@@ -492,16 +504,7 @@ static int prepare_startup_playback_urb(struct snd_usb_substream *subs,
urb->dev = ctx->subs->dev;
urb->number_of_packets = subs->packs_per_ms;
for (i = 0; i < subs->packs_per_ms; ++i) {
- /* calculate the size of a packet */
- if (subs->fill_max)
- counts = subs->maxframesize; /* fixed */
- else {
- subs->phase = (subs->phase & 0xffff)
- + (subs->freqm << subs->datainterval);
- counts = subs->phase >> 16;
- if (counts > subs->maxframesize)
- counts = subs->maxframesize;
- }
+ counts = snd_usb_audio_next_packet_size(subs);
urb->iso_frame_desc[i].offset = offs * stride;
urb->iso_frame_desc[i].length = counts * stride;
offs += counts;
@@ -538,16 +541,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
urb->number_of_packets = 0;
spin_lock_irqsave(&subs->lock, flags);
for (i = 0; i < ctx->packets; i++) {
- /* calculate the size of a packet */
- if (subs->fill_max)
- counts = subs->maxframesize; /* fixed */
- else {
- subs->phase = (subs->phase & 0xffff)
- + (subs->freqm << subs->datainterval);
- counts = subs->phase >> 16;
- if (counts > subs->maxframesize)
- counts = subs->maxframesize;
- }
+ counts = snd_usb_audio_next_packet_size(subs);
/* set up descriptor */
urb->iso_frame_desc[i].offset = offs * stride;
urb->iso_frame_desc[i].length = counts * stride;
OpenPOWER on IntegriCloud