Sorry for the long post. More information obtained after insert the first code below at beginning of m1sdr_Init() and the second at before "snd_pcm_hw_params_free(hwparams);"
unsigned int periodsperbuffer, periodtime, buffertime;
snd_pcm_uframes_t buffsize, periodsize;
snd_pcm_hw_params_get_periods(hwparams, &periodsperbuffer, 0);
printf("Approximate periods per buffer is %d.\n", periodsperbuffer);
snd_pcm_hw_params_get_period_size(hwparams, &periodsize, 0);
printf("Approximate period size is %d frames.\n", periodsize);
snd_pcm_hw_params_get_period_time(hwparams, &periodtime, 0);
printf("Approximate period duration is %d useconds.\n", periodtime);
snd_pcm_hw_params_get_buffer_size(hwparams, &buffsize);
printf("Buffer size is %d frames.\n", buffsize);
snd_pcm_hw_params_get_buffer_time(hwparams, &buffertime, 0);
printf("Buffer time is %d useconds.\n", buffertime);
1) Default of release 4 (sound plays with distortion):
Approximate periods per buffer is 1024.
Approximate period size is 16 frames.
Approximate period duration is 362 useconds.
Buffer size is 16384 frames.
Buffer time is 1 useconds.
Buffer size and periods per buffer ratio is 16:1.
2) After insert only buffer size setting of release 3 (still distortions):
Approximate periods per buffer is 512.
Approximate period size is 16 frames.
Approximate period duration is 362 useconds.
Buffer size is 8192 frames.
Buffer time is 1 useconds.
Periods per buffer automatically decreases to 512 (ratio 16:1).
3) After remove buffer size setting and insert only periods per buffer of release 3 (slow emulation):
Approximate periods per buffer is 4.
Approximate period size is 16 frames.
Approximate period duration is 362 useconds.
Buffer size is 64 frames.
Buffer time is 1451 useconds.
Buffer size automatically decreases to 64 (ratio 16:1), buffer time increases.
4) Default of release 3 (sound plays fine):
Approximate periods per buffer is 4.
Approximate period size is 2048 frames.
Approximate period duration is 46438 useconds.
Buffer size is 8192 frames.
Buffer time is 1 useconds.
Buffer size and periods per buffer ratio is 2048:1, period duration increases.
5) If I set buffer size to 8192 frames and start to decrement periods per buffer from 512 to 256, 128, 64, 32, 16, distortion is still present and emulation speed increases, but when it reaches 8 (ratio 1024:1), speed is normal and distortion disappears.
- Periods per buffer = 16, emulation too fast:
Approximate periods per buffer is 16.
Approximate period size is 512 frames.
Approximate period duration is 11609 useconds.
Buffer size is 8192 frames.
Buffer time is 1 useconds.
- Periods per buffer = 8, everything is fine like preview 3, which uses periods = 4:
Approximate periods per buffer is 8.
Approximate period size is 1024 frames.
Approximate period duration is 23219 useconds.
Buffer size is 8192 frames.
Buffer time is 1 useconds.
6) If buffer size is set to 16384 frames (default), but I change periods per buffer from 1024 to 16 (ratio 1024:1), sound plays without distortion and with normal emulation speed.
Approximate periods per buffer is 16.
Approximate period size is 1024 frames.
Approximate period duration is 23219 useconds.
Buffer size is 16384 frames.
Buffer time is 1 useconds.
7) I changed attention to period size. Settings of buffer size and periods per buffer were removed and only a call to set period size was inserted, using 1024 frames and decreasing later. It's very difficult to distinguish sound quality, but distortions seems to appear when period size is minor than 735. This size gives a interesting period duration:
Approximate periods per buffer is 22.
Approximate period size is 735 frames.
Approximate period duration is 16666 useconds.
Buffer size is 16384 frames.
Buffer time is 1 useconds.
The call to set period size was changed to snd_pcm_hw_params_set_period_time_near() and I got similar results, but time based (fine when 16666us or more).
Maybe a call to set period size to 735 or more (around 1024), or to set period time to 16666 or more (around 20000us) would be a solution to everyone. Comments? What are the numbers used by your sound setup, Arbee?