• Oswald Buddenhagen's avatar
    ALSA: emu10k1: fix wavetable playback position and caching, take 2 · d0440680
    Oswald Buddenhagen authored
    Compensate for the cache lag of 64 frames, and actually populate the
    cache. Without these, the playback would start with garbage (which
    would be (mostly?) masqueraded by the note's attack phase).
    
    Note that we set the starting address only 61 frames ahead, to
    compensate for the interpolator's epsilon. Unlike for PCM playback, we
    don't even need to manually silence-fill the first frames in the cache,
    because we insert some silence in front of each sample anyway.
    
    A challenge are extremely short samples with a loop end below the cache
    size, because a) we'd have to wrap the current address to be within the
    loop and b) automatic pre-filling of the cache with the right data does
    not work in this case.
    
    We could pre-fill the cache manually, but that's slow, requires
    additional code for each sample width, and is made even more complex by
    the driver's virtual address space having no contiguous mapping for the
    CPU.
    
    We could have the engine fill the cache piece-wise (which is really what
    happens when playback is running), but that would also be complex, and
    we'd need to wait for the engine to handle each piece, so it wouldn't be
    that much faster than the manual fill.
    
    For the case of requiring only one loop iteration prior to reaching the
    cache size, we could leverage the engine's looping mechanism around
    CCR_CACHELOOPFLAG, but this special case doesn't seem worth the
    complexity.
    
    So we just unroll the loop as far as necessary to be able to play back
    the sample without any fiddling.
    
    Pedantically, this would be incorrect for loop-until-release samples
    with a low loop end which are released very quickly, but that would be
    relatively harmless, is not a plausible use case in the first place, and
    SoundFont sample mode 3 isn't actually implemented anyway (it's
    conflated with mode 1, infinite looping).
    Signed-off-by: default avatarOswald Buddenhagen <oswald.buddenhagen@gmx.de>
    Message-ID: <20240406064830.1029573-16-oswald.buddenhagen@gmx.de>
    Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
    d0440680
emu10k1_callback.c 12.1 KB