【ALSA】【USBAudio】【PCMDUMP】
基本原理
通过ALSA Capture 提供的接口,在kernel实现Audioloop.
Kernel实现
1. 实现AudioCapture节点操作集
在sound/usb/pcm.c加入如下代码:
struct usb_dummy_capture{
struct snd_pcm_substream *pcm_substream;
snd_pcm_format_t pcm_format; /* current audio format (for hw_params callback) */
unsigned int channels; /* current number of channels (for hw_params callback) */
unsigned int cur_rate; /* current rate (for hw_params callback) */
unsigned int period_bytes; /* current period bytes (for hw_params callback) */
unsigned int running: 1; /* running status */
unsigned int hwptr_done; /* processed byte position in the buffer */
unsigned int transfer_done; /* processed frames since last period update */
};
static struct usb_dummy_capture g_dummy_capture;
static struct snd_pcm_hardware snd_usb_dummy_hardware =
{
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_BATCH |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_PAUSE,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_48000,
.rate_min = 48000,
.rate_max = 48000,
.channels_min = 2,
.channels_max = 2,
.buffer_bytes_max = 1024 * 1024,
.period_bytes_min = 64,
.period_bytes_max = 512 * 1024,
.periods_min = 2,
.periods_max = 1024,
};
static int snd_usb_dummy_open(struct snd_pcm_substream *substream)
{
g_dummy_capture.pcm_substream = substream;
struct snd_pcm_runtime *runtime = substream->runtime;
runtime->hw