Buffer size/periods (Layla3G)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am investigating problems I'm having with recording over long periods. I'm using a Layla3G and tested various ALSA versions including 1.0.14 and 1.0.16 on different machines.

I've noticed that when I open the first pair of subdevices, my request for 1000ms buffer size is handled differently to other devices:

  $ ./test_buffers "hw:Layla3G,0,0" 1000
  buffer_size=16384 period_size=128

  $ ./test_buffers "hw:Layla3G,0,2" 1000
  buffer_size=32768 period_size=256

  $ ./test_buffers "hw:Layla3G,0,4" 1000
  buffer_size=32768 period_size=256

  $ ./test_buffers "hw:Layla3G,0,6" 1000
  buffer_size=32768 period_size=256

If I try other buffer sizes, I can see is a limit to buffer size of 16384 samples on the ,0 subdevice, which is also affecting the chosen period size. But only on the first subdevice. Is there a reason, or is this a bug?

Also, there seem to be failures at certain buffer sizes:

  $ ./test_buffers "hw:Layla3G,0,2" 429
  buffer_size=18912 period_size=96

  $ ./test_buffers "hw:Layla3G,0,2" 430
  set_buffer_time_near: Invalid argument

  $ ./test_buffers "hw:Layla3G,0,2" 431
  buffer_size=19008 period_size=96

Can anyone explain to me what's going on here, or is this also a bug?

The overall problem I'm investigating is snd_pcm_readi() returning incomplete buffers after running for long periods until another snd_pcm_prepare(). It seems possible that this is related.

Any help is greatly appreciated.

Thanks,

Mark
#include <stdio.h>
#include <alsa/asoundlib.h>

#define RATE 44100
#define CHANNELS 2

#define CHK(msg, r) \
{ \
	if ((r) < 0) { \
		fprintf(stderr, "%s: %s\n", msg, snd_strerror(r)); \
		return -1; \
	} \
}

int main(int argc, char *argv[])
{
	int r, dir;
	unsigned int p;
	snd_pcm_t *pcm;
	snd_pcm_hw_params_t *hw_params;
	snd_pcm_uframes_t buffer_size, period_size;

	r = snd_pcm_open(&pcm, argv[1], SND_PCM_STREAM_CAPTURE, 0);
	CHK("open", r);

	r = snd_pcm_hw_params_malloc(&hw_params);
	CHK("params_malloc", r);

	r = snd_pcm_hw_params_any(pcm, hw_params);
	CHK("params_any", r);

	r = snd_pcm_hw_params_set_access(pcm, hw_params,
					 SND_PCM_ACCESS_RW_INTERLEAVED);
	CHK("params_set_access", r);

	r = snd_pcm_hw_params_set_format(pcm, hw_params, SND_PCM_FORMAT_S32);
	CHK("set_format", r);

	r = snd_pcm_hw_params_set_rate(pcm, hw_params, RATE, 0);
	CHK("set_rate", r);

	r = snd_pcm_hw_params_set_channels(pcm, hw_params, CHANNELS);
	CHK("set_channels",r);

	if (argc > 2) {
	        p = atoi(argv[2]) * 1000;
		r = snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params,
							   &p, &dir);
		CHK("set_buffer_time_near", r);
	}

	if (argc > 3) {
		p = atoi(argv[3]) * 1000;
		r = snd_pcm_hw_params_set_period_time_near(pcm, hw_params,
							   &p, &dir);
		CHK("set_period_time_near", r);
	}

	r = snd_pcm_hw_params(pcm, hw_params);
	CHK("hw_params", r);

	r = snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
	CHK("get_buffer_size", r);

	r = snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir);
	CHK("get_period_size", r);

	printf("buffer_size=%d period_size=%d\n",
	       (int)buffer_size, (int)period_size);

	r = snd_pcm_close(pcm);
	CHK("pcm_close", r);

	return 0;
}
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux