Skip to contentSkip to conversation

Question about snd_dma_buffer bytes field

DISCUSSION Troy Kisky 2 participants 3 messages May 25, 2009

lore
Share & tools
lore

Troy Kisky

author
#0 lore raw

Does

(substream->dma_buffer.bytes) need to equal (snd_pcm_lib_period_bytes(substream) * runtime->periods) ?

When this is not true, it seems like the buffer is not being filled correctly.

for testing, this works

	.buffer_bytes_max = 16 * 7 * 512,
	.period_bytes_min = 32,
	.period_bytes_max = 7 * 512,	/* This is size of ping + pong buffer*/

and this doesn't.

	.buffer_bytes_max = 16 * 7 * 512 + 512,
	.period_bytes_min = 32,
	.period_bytes_max = 7 * 512,	/* This is size of ping + pong buffer*/

When playing back a sine wave, I can hear breaks.

Thanks
Troy

#1 lore raw

At Sun, 24 May 2009 19:26:42 -0700,

Quoted 13 lines · Troy Kisky

Does

(substream->dma_buffer.bytes) need to equal (snd_pcm_lib_period_bytes(substream) * runtime->periods) ?

When this is not true, it seems like the buffer is not being filled correctly.

for testing, this works

	.buffer_bytes_max = 16 * 7 * 512,
	.period_bytes_min = 32,
	.period_bytes_max = 7 * 512,	/* This is size of ping + pong buffer*/
Quoted 7 lines

and this doesn't.

	.buffer_bytes_max = 16 * 7 * 512 + 512,
	.period_bytes_min = 32,
	.period_bytes_max = 7 * 512,	/* This is size of ping + pong buffer*/

When playing back a sine wave, I can hear breaks.

Well, there are two misunderstandings here:

- substream->dma_buffer.bytes doesn't define the actual buffer size. It's substream->runtime->buffer_size (in frames). The former is the allocated buffer size which can be larger.

- The buffer size doesn't have to be aligned to period_size as default, i.e. it's not always equal with period_size * periods, and periods isn't always an integer.

To align the buffer size to period size, call below in the open callback

	snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);

HTH,

Takashi

author
#2 lore raw
Quoted 32 lines · Takashi Iwai

At Sun, 24 May 2009 19:26:42 -0700,

Quoted 12 lines · Troy Kisky

Does

(substream->dma_buffer.bytes) need to equal (snd_pcm_lib_period_bytes(substream) * runtime->periods) ?

When this is not true, it seems like the buffer is not being filled correctly.

for testing, this works

	.buffer_bytes_max = 16 * 7 * 512,
	.period_bytes_min = 32,
	.period_bytes_max = 7 * 512,	/* This is size of ping + pong buffer*/
Quoted 7 lines

and this doesn't.

	.buffer_bytes_max = 16 * 7 * 512 + 512,
	.period_bytes_min = 32,
	.period_bytes_max = 7 * 512,	/* This is size of ping + pong buffer*/

When playing back a sine wave, I can hear breaks.

Well, there are two misunderstandings here:

- substream->dma_buffer.bytes doesn't define the actual buffer size. It's substream->runtime->buffer_size (in frames). The former is the allocated buffer size which can be larger.

- The buffer size doesn't have to be aligned to period_size as default, i.e. it's not always equal with period_size * periods, and periods isn't always an integer.

Quoted 9 lines

To align the buffer size to period size, call below in the open callback

	snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);

HTH,

Takashi

Yes, that fixed my problem.

Thanks you
Troy