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
|
235 | 235 | if (pcm->type == PCM_TYPE_WRITE) period_size = ((period_size + 6)/6)*6; |
236 | 236 | } |
237 | 237 | |
238 | | period_bytes=period_size*uniaud_pcm_format_size(new_format, new_channels); |
| 238 | period_bytes=period_size*samplesize*new_channels; |
239 | 239 | period_bytes_max = ((snd_interval_t*)hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->max; |
240 | 240 | //printf("period_bytes=%i period_bytes_max=%i\n", period_bytes, period_bytes_max); |
241 | 241 | if (period_bytes_max < period_bytes) { |
242 | 242 | 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; |
244 | 244 | } |
245 | 245 | period_bytes_min = ((snd_interval_t*)hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->min; |
246 | 246 | //printf("period_bytes=%i period_size=%i period_bytes_min=%i\n", period_bytes, period_size, period_bytes_min); |
247 | 247 | if (period_bytes < period_bytes_min) { |
248 | 248 | 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; |
250 | 250 | } |
251 | 251 | //buffer_size = period_size*8; |
252 | 252 | buffer_size = ((snd_interval_t*)hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_BUFFER_BYTES))->max; |
… |
… |
int uniaud_pcm_set_params(uniaud_pcm *pcm, int channels, int sample_rate, int pc
|
265 | 265 | periods = periods_min*new_channels; |
266 | 266 | period_bytes = ((snd_interval_t*)hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_BYTES))->min; |
267 | 267 | period_bytes *=4; |
268 | | period_size = period_bytes/uniaud_pcm_format_size(new_format, new_channels); |
| 268 | period_size = period_bytes/samplesize/new_channels; |
269 | 269 | #endif |
270 | 270 | periods &= ~1; |
271 | 271 | if (periods > 3) periods = ((periods - 3) /3) * 3; |
… |
… |
int _uniaud_pcm_reinit(uniaud_pcm *pcm)
|
369 | 369 | if (!pcm) return -10000; |
370 | 370 | |
371 | 371 | 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; |
373 | 373 | |
374 | 374 | err = uniaud_pcm_prepare(pcm); |
375 | 375 | if (err != 0) { |
… |
… |
int _uniaud_pcm_write(uniaud_pcm *pcm, char* buffer, int size)
|
655 | 655 | } |
656 | 656 | } |
657 | 657 | #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; |
660 | 660 | if (pcm->resample_size == 0) { |
661 | 661 | //printf("format: %i, orig format: %i chans: %i, ssize: %i\n",pcm->format, pcm->orig_format, |
662 | 662 | // pcm->channels, samplesize);fflush(stdout); |
diff --git a/tools/rwtest.c b/tools/rwtest.c
index 94db3d9..8208656 100644
a
|
b
|
int main (int argc, char *argv[])
|
244 | 244 | periods_max = ((snd_interval_t*)hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIODS))->max; |
245 | 245 | periods = 2;//periods_min*pcmwrite->channels; |
246 | 246 | 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; |
248 | 248 | printf("format size: %i, format: %i, ch: %i\n", fs, pcmwrite->format, pcmwrite->channels); |
249 | 249 | period_size = period_bytes/fs; |
250 | 250 | |
… |
… |
int main (int argc, char *argv[])
|
341 | 341 | periods_max = ((snd_interval_t*)hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIODS))->max; |
342 | 342 | periods = 2;//periods_min*pcmwrite->channels; |
343 | 343 | period_bytes = 240;//((snd_interval_t*)hw_param_interval((¶ms), 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; |
345 | 345 | //period_size = ((snd_interval_t*)hw_param_interval((¶ms), 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; |
347 | 347 | #if 1 |
348 | 348 | printf("read parameters:\n"); |
349 | 349 | printf("buffer_size = %i\n",period_bytes*periods); |