Skip to content
Snippets Groups Projects
  • Volker Rümelin's avatar
    2f886a34
    audio: remove sw->ratio · 2f886a34
    Volker Rümelin authored
    
    Simplify the resample buffer size calculation.
    
    For audio playback we have
    sw->ratio = ((int64_t)sw->hw->info.freq << 32) / sw->info.freq;
    samples = ((int64_t)sw->HWBUF.size << 32) / sw->ratio;
    
    This can be simplified to
    samples = muldiv64(sw->HWBUF.size, sw->info.freq, sw->hw->info.freq);
    
    For audio recording we have
    sw->ratio = ((int64_t)sw->info.freq << 32) / sw->hw->info.freq;
    samples = (int64_t)sw->HWBUF.size * sw->ratio >> 32;
    
    This can be simplified to
    samples = muldiv64(sw->HWBUF.size, sw->info.freq, sw->hw->info.freq);
    
    With hw = sw->hw this becomes in both cases
    samples = muldiv64(HWBUF.size, sw->info.freq, hw->info.freq);
    
    Now that sw->ratio is no longer needed, remove sw->ratio.
    
    Acked-by: default avatarMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
    Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
    Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
    Message-Id: <20230224190555.7409-15-vr_qemu@t-online.de>
    2f886a34
    History
    audio: remove sw->ratio
    Volker Rümelin authored
    
    Simplify the resample buffer size calculation.
    
    For audio playback we have
    sw->ratio = ((int64_t)sw->hw->info.freq << 32) / sw->info.freq;
    samples = ((int64_t)sw->HWBUF.size << 32) / sw->ratio;
    
    This can be simplified to
    samples = muldiv64(sw->HWBUF.size, sw->info.freq, sw->hw->info.freq);
    
    For audio recording we have
    sw->ratio = ((int64_t)sw->info.freq << 32) / sw->hw->info.freq;
    samples = (int64_t)sw->HWBUF.size * sw->ratio >> 32;
    
    This can be simplified to
    samples = muldiv64(sw->HWBUF.size, sw->info.freq, sw->hw->info.freq);
    
    With hw = sw->hw this becomes in both cases
    samples = muldiv64(HWBUF.size, sw->info.freq, hw->info.freq);
    
    Now that sw->ratio is no longer needed, remove sw->ratio.
    
    Acked-by: default avatarMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
    Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
    Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
    Message-Id: <20230224190555.7409-15-vr_qemu@t-online.de>