Linux 声音编程。如何确定帧中的缓冲区大小?

Linux sound programming. How to determine a buffer size in frames?

我正在尝试使用 ALSA 并在此 howto, Section 2 中遇到以下配置参数:

The unit of the buffersize depends on the function. Sometimes it is given in bytes, sometimes the number of frames has to be specified. One frame is the sample data vector for all channels. For 16 Bit stereo data, one frame has a length of four bytes.

/* Set buffer size (in frames). The resulting latency is given by */
/* latency = periodsize * periods / (rate * bytes_per_frame)     */
if (snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, (periodsize * periods)>>2) < 0) {
  fprintf(stderr, "Error setting buffersize.\n");
  return(-1);
}

I don't understand this For 16 Bit stereo data, one frame has a length of four bytes

为什么是四个?它是否跟随着通道数:2?我的意思是早些时候他们配置如下:

/* Set number of channels */
if (snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2) < 0) {
  fprintf(stderr, "Error setting channels.\n");
  return(-1);
}

如果我的声学系统包含 4 个输出怎么办?还是6个?是不是说我必须相应地配置成16 Bit * 4和16 Bit * 6?

Why is it four? Does it follow by the number of channels: 2?

是的,根据前面提到的:

One frame is the sample data vector for all channels.

所以对于立体声 16 位数据,有两个(左和右)通道,每个 16 位(=2 字节),因此每帧总计 4 字节。