#define PERIOD 6000
#define PLAYBACK_BUFFERS 4
unsigned char buffer_p[PERIOD*4*4]; unsigned char buffer_c[PERIOD*4*4];
I don't understand why you hard coded PERIOD and PLAYBACK_BUFFERS when you use snd_pcm_set_params
Thanks for pointing this out. I have no idea what this is still there, i
think the idea was to use a fixed-size buffer to make sure the timing is predictable, it's been that way for 2+ years. Will fix.
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pc...
Seem you assume hda controller support arbitrary period size since 6000 frames is not a multiple of 32 frames
If your intel hda controller support arbritary period size , the difference between two successive audio time in your example 1 should be 125 ms as same as example 3 when using usb audio in [alsa-devel] [PATCH RFC 5/9] ALSA: core: selection of audio_tstamp type and accuracy reports
Refer to US 20100131783 System and Method of Dynamically Switching Queue Threshold
2. Description of the Prior Art
The DMA 150 has a queue, such as a first-in first-out buffer (“FIFO”) for maintaining the stream on the HDA link 16 by storing sufficient amount of data, such that no data under run or overrun occurs. Before sending out data to the HDA link 16, the HDAC 15 will issue a bus master cycle to request next stream data from the system memory 13 whenever the amount of the stream data in the FIFO is less than a threshold value. The FIFO threshold value and the burst length are associated with the FIFO size, as shown in Table 1, where h represents a hexadecimal number, and DW represents a double word (or 4-byte data).
TABLE 1
FIFO size FIFO threshold Burst length
40h DW 31h DW 10h DW 30h DW 21h DW 10h DW 20h DW 19h DW 8h DW 10h DW dh DW 4h DW 8h DW 7h DW 2h DW 4h DW 4h DW 1h DW Others 4h DW 1h DW
This look like period size should be multiple of brust length
since period size and buffer size can be obtained by snd_pcm_get_params() after calling snd_pcm_set_params()
if ((err = snd_pcm_set_params(handle_p, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_RW_INTERLEAVED, 2, 48000, 0, 500000)) < 0) { /* 0.5sec */
http://lists.freedesktop.org/archives/pulseaudio-discuss/2014-October/021898...
Not all distrubtion use 4Mb buffer, this mean that most ubuntu users only have 64k