• Daniel Mack's avatar
    usb: gadget: f_uac2: send reasonably sized packets · 9bb87f16
    Daniel Mack authored
    The UAC2 function driver currently responds to all packets at all times
    with wMaxPacketSize packets. That results in way too fast audio
    playback as the function driver (which is in fact supposed to define
    the audio stream pace) delivers as fast as it can.
    
    Fix this by sizing each packet correctly with the following steps:
    
     a) Set the packet's size by dividing the nominal data rate by the
        playback endpoint's interval.
    
     b) If there is a residual value from the calculation in a), add
        it to a accumulator to keep track of it across packets.
    
     c) If the accumulator has gathered at least the number of bytes
        that are needed for one sample frame, increase the packet size.
    
    This way, the packet size calculation will get rid of any kind of
    imprecision that would otherwise occur with a simple division over
    time.
    
    Some of the variables that are needed while processing each packet
    are pre-computed for performance reasons.
    Signed-off-by: default avatarDaniel Mack <zonque@gmail.com>
    Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
    9bb87f16
f_uac2.c 40.1 KB