ALSA: usb-audio: Fix packet size calculation
PATCH 1/2 ALSA: usb-audio: Fix packet size calculation
Commit f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation") introduced a regression for devices which have playback endpoints with bInterval > 1. Fix this by taking ep->datainterval into account.
Note that frame and fps are actually mean packet and packets per second in the code introduces by the mentioned commit. This will be fixed in a follow-up patch.
--- sound/usb/endpoint.c | 1 + 1 file changed, 1 insertion(+)
sound/usb/endpoint.c +1 -0
@@ -1093,6 +1093,7 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, ep->freqn =get_usb_high_speed_rate (rate); ep->fps =8000 ; } + ep->fps >>= ep->datainterval; ep->sample_rem = rate % ep->fps; ep->framesize[0 ] = rate / ep->fps;
Signature · 1 line
2.26.2
PATCH 2/2 ALSA: usb-audio: Replace s/frame/packet/ where appropriate
Replace several occurences of "frame" with a "packet" where appropriate.
--- sound/usb/card.h | 6 +++--- sound/usb/endpoint.c | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-)
sound/usb/card.h +3 -3
@@ -84,10 +84,10 @@ struct snd_usb_endpoint {dma_addr_t sync_dma;/* DMA address of syncbuf */ unsigned int pipe;/* the data i/o pipe */ -unsigned int framesize[2 ];/* small/large frame sizes in samples */ -unsigned int sample_rem;/* remainder from division fs/fps */ +unsigned int packsize[2 ];/* small/large packet sizes in samples */ +unsigned int sample_rem;/* remainder from division fs/pps */ unsigned int sample_accum;/* sample accumulator */ -unsigned int fps;/* frames per second */ +unsigned int pps;/* packets per second */ unsigned int freqn;/* nominal sampling rate in fs/fps in Q16.16 format */ unsigned int freqm;/* momentary sampling rate in fs/fps in Q16.16 format */ int freqshift;/* how much to shift the feedback value to get Q16.16 */
sound/usb/endpoint.c +9 -10
@@ -159,11 +159,11 @@ int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep)return ep->maxframesize; ep->sample_accum += ep->sample_rem; -if (ep->sample_accum >= ep->fps) { - ep->sample_accum -= ep->fps; - ret = ep->framesize[1 ]; +if (ep->sample_accum >= ep->pps) { + ep->sample_accum -= ep->pps; + ret = ep->packsize[1 ]; }else { - ret = ep->framesize[0 ]; + ret = ep->packsize[0 ]; }return ret;
@@ -1088,16 +1088,15 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,if (snd_usb_get_speed (ep->chip->dev) ==USB_SPEED_FULL ) { ep->freqn =get_usb_full_speed_rate (rate); - ep->fps =1000 ; + ep->pps =1000 >> ep->datainterval; }else { ep->freqn =get_usb_high_speed_rate (rate); - ep->fps =8000 ; + ep->pps =8000 >> ep->datainterval; } - ep->fps >>= ep->datainterval; - ep->sample_rem = rate % ep->fps; - ep->framesize[0 ] = rate / ep->fps; - ep->framesize[1 ] = (rate + (ep->fps -1 )) / ep->fps; + ep->sample_rem = rate % ep->pps; + ep->packsize[0 ] = rate / ep->pps; + ep->packsize[1 ] = (rate + (ep->pps -1 )) / ep->pps;/* calculate the frequency in 16.16 format */ ep->freqm = ep->freqn;
Signature · 1 line
2.26.2
Takashi Iwai
AppliedRe: [PATCH 2/2] ALSA: usb-audio: Replace s/frame/packet/ where appropriate
Quoted 4 lines · Alexander Tsoy
Replace several occurences of "frame" with a "packet" where appropriate.
Signed-off-by Alexander Tsoy <[email protected]>
Applied, thanks.
Takashi
Quoted 5 lines · Alexander Tsoy
Commit
f0bd62b64016("ALSA: usb-audio: Improve frames size computation") introduced a regression for devices which have playback endpoints with bInterval > 1. Fix this by takingep->dataintervalinto account.
Quoted 7 lines
Note that frame and fps are actually mean packet and packets per second in the code introduces by the mentioned commit. This will be fixed in a follow-up patch.
Fixes f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")Signed-off-by Alexander Tsoy <[email protected]>
Applied now. Thanks.
Takashi