2017 March [DRAFT]
Created at 2017-03-07T20:53:52.000Z

2017-03-04T10:55:54+09:00, 2017-03-05T12:43:29+09:00

2017-03-06T22:38:21+09:00

  • Follow alsa-lib's pcm test (simplest application ?)
$ ./test/.libs/pcm -v -D 'hw:CARD=0,DEV=0,SUBDEV=-1' -c 2
Playback device is hw:CARD=0,DEV=0,SUBDEV=-1
Stream parameters are 44100Hz, S16_LE, 2 channels
Sine wave rate is 440.0000Hz
Using transfer method: write
Hardware PCM card 0 'HDA Intel PCH' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 8192
  period_time  : 185759
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 8192
  period_event : 0
  start_threshold  : 16384
  stop_threshold   : 16384
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0
  C-c C-c

# data structure

snd_pcm_t (aka struct _snd_pcm)
'-' snd_pcm_hw_t (as private_data)
    '-' card, device, subdevice
    '-' struct pollfd

snd_pcm_hw_params_t
snd_pcm_sw_params_t
snd_pcm_channel_area_t


# code path

- main =>
  - snd_pcm_open ?
  - set_hwparams =>
    - snd_pcm_hw_params_set_xxx
    - snd_pcm_hw_params ?
  - set_swparams =>
    - snd_pcm_sw_params_set_xxx
    - snd_pcm_sw_params ?
  - snd_pcm_dump
  - signed short *samples = malloc
  - snd_pcm_channel_area_t *areas = calloc
  - write_loop => while(1)
    - generate_sine(samples)
    - cptr = period_size
      - while (cptr > 0): snd_pcm_writei ?

# alsa-lib implementation
- snd_pcm_open("hw:CARD=0,DEV=0,SUBDEV=-1") =>
  - snd_pcm_open_noupdate => snd_pcm_open_conf =>
    - __snd_pcm_hw_open (as buildin open_func ?) =>
      - snd_pcm_hw_open =>
        - snd_ctl_hw_open
        - snd_open_device
        - snd_pcm_hw_open_fd =>
          - ioctl(SNDRV_PCM_IOCTL_INFO)
          - calloc(1, sizeof(snd_pcm_hw_t))
          - snd_pcm_new(SND_PCM_TYPE_HW)

# configuration

[/usr/share/alsa/alsa.conf]
pcm.hw {
    @args [ CARD DEV SUBDEV ]
        ...
    type hw
    card $CARD
    device $DEV
    subdevice $SUBDEV
}

2017-03-08T14:53:44+09:00