Ticket #250: 0001-Fix-wrong-usage-of-uniaud_pcm_format_size.patch

File 0001-Fix-wrong-usage-of-uniaud_pcm_format_size.patch, 4.7 KB (added by KO Myung-Hun, 3 days ago)
  • lib/unipcm.c

    From 46d8c11db033c0f6e8caf12e8b86d578fa1c481b Mon Sep 17 00:00:00 2001
    From: KO Myung-Hun <komh78@gmail.com>
    Date: Fri, 31 Jan 2025 21:37:54 +0900
    Subject: [PATCH] Fix wrong usage of uniaud_pcm_format_size()
    
    The second arg of uniaud_pcm_format_size() is a sample count not a
    channel count.
    ---
     lib/unipcm.c   | 14 +++++++-------
     tools/rwtest.c |  6 +++---
     2 files changed, 10 insertions(+), 10 deletions(-)
    
    diff --git a/lib/unipcm.c b/lib/unipcm.c
    index 46e0377..8d0081f 100644
    a b int uniaud_pcm_set_params(uniaud_pcm *pcm, int channels, int sample_rate, int pc  
    235235                if (pcm->type == PCM_TYPE_WRITE) period_size = ((period_size + 6)/6)*6;
    236236        }
    237237
    238         period_bytes=period_size*uniaud_pcm_format_size(new_format, new_channels);
     238        period_bytes=period_size*samplesize*new_channels;
    239239        period_bytes_max = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->max;
    240240        //printf("period_bytes=%i period_bytes_max=%i\n", period_bytes, period_bytes_max);
    241241        if (period_bytes_max <  period_bytes) {
    242242                period_bytes = period_bytes_max;
    243                 period_size = period_bytes/uniaud_pcm_format_size(new_format, new_channels);
     243                period_size = period_bytes/samplesize/new_channels;
    244244        }
    245245        period_bytes_min = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->min;
    246246        //printf("period_bytes=%i period_size=%i period_bytes_min=%i\n", period_bytes, period_size, period_bytes_min);
    247247        if (period_bytes <      period_bytes_min) {
    248248                period_bytes =  period_bytes_min;
    249                 period_size = period_bytes/uniaud_pcm_format_size(new_format, new_channels);
     249                period_size = period_bytes/samplesize/new_channels;
    250250        }
    251251        //buffer_size = period_size*8;
    252252        buffer_size = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_BUFFER_BYTES))->max;
    int uniaud_pcm_set_params(uniaud_pcm *pcm, int channels, int sample_rate, int pc  
    265265        periods = periods_min*new_channels;
    266266        period_bytes = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->min;
    267267        period_bytes *=4;
    268         period_size = period_bytes/uniaud_pcm_format_size(new_format, new_channels);
     268        period_size = period_bytes/samplesize/new_channels;
    269269#endif
    270270        periods &= ~1;
    271271        if (periods > 3) periods = ((periods - 3) /3) * 3;
    int _uniaud_pcm_reinit(uniaud_pcm *pcm)  
    369369        if (!pcm) return -10000;
    370370
    371371        samplesize = uniaud_pcm_format_size(pcm->format, 1);
    372         period_size = pcm->period_size/uniaud_pcm_format_size(pcm->format, pcm->channels);
     372        period_size = pcm->period_size/samplesize/pcm->channels;
    373373
    374374        err = uniaud_pcm_prepare(pcm);
    375375        if (err != 0) {
    int _uniaud_pcm_write(uniaud_pcm *pcm, char* buffer, int size)  
    655655                        }
    656656                }
    657657#endif
    658                 orig_samplesize = uniaud_pcm_format_size(pcm->format, pcm->orig_channels);
    659                 samplesize = uniaud_pcm_format_size(pcm->format, pcm->channels);
     658                orig_samplesize = uniaud_pcm_format_size(pcm->format, 1) * pcm->orig_channels;
     659                samplesize = uniaud_pcm_format_size(pcm->format, 1) * pcm->channels;
    660660                if (pcm->resample_size == 0) {
    661661                        //printf("format: %i, orig format: %i chans: %i, ssize: %i\n",pcm->format, pcm->orig_format,
    662662                        //               pcm->channels, samplesize);fflush(stdout);
  • tools/rwtest.c

    diff --git a/tools/rwtest.c b/tools/rwtest.c
    index 94db3d9..8208656 100644
    a b int main (int argc, char *argv[])  
    244244    periods_max = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIODS))->max;
    245245    periods = 2;//periods_min*pcmwrite->channels;
    246246    period_bytes = 480*4;
    247     fs = uniaud_pcm_format_size(pcmwrite->format, pcmwrite->channels);
     247    fs = uniaud_pcm_format_size(pcmwrite->format, 1) * pcmwrite->channels;
    248248    printf("format size: %i, format: %i, ch: %i\n", fs, pcmwrite->format, pcmwrite->channels);
    249249    period_size = period_bytes/fs;
    250250
    int main (int argc, char *argv[])  
    341341    periods_max = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIODS))->max;
    342342    periods = 2;//periods_min*pcmwrite->channels;
    343343    period_bytes = 240;//((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->min;
    344     period_size = period_bytes/uniaud_pcm_format_size(pcmread->format, pcmread->channels);
     344    period_size = period_bytes/uniaud_pcm_format_size(pcmread->format, 1)/pcmread->channels;
    345345    //period_size = ((snd_interval_t*)hw_param_interval((&params), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->min;
    346     //period_bytes = period_size*uniaud_pcm_format_size(pcmread->format, pcmread->channels);
     346    //period_bytes = period_size*uniaud_pcm_format_size(pcmread->format, 1)*pcmread->channels;
    347347#if 1
    348348    printf("read parameters:\n");
    349349    printf("buffer_size = %i\n",period_bytes*periods);