src/test/sysdep/linux/sound.c
static int start_capture(void)
{
    /* Convenience macro for checking ALSA function return codes. */
    #define CHECK_ALSA(call)  do {                       \
        int result;                                      \
        if ((result = (call)) < 0) {                     \
            FAIL("%s: %s", #call, snd_strerror(result)); \
        }                                                \
    } while (0)

    /* Open the playback side of the loopback device.  This is done first
     * so that the loopback device takes its parameters from those set by
     * the playback code. */
    CHECK_TRUE(sound_open_device(LOOPBACK_PLAYBACK_DEVICE, 1));

    /* Make sure failures close the capture device. */
    #undef FAIL_ACTION
    #define FAIL_ACTION  goto error

    /* Open the capture side of the loopback device. */
    CHECK_ALSA(snd_pcm_open(&pcm_handle, LOOPBACK_CAPTURE_DEVICE,
                            SND_PCM_STREAM_CAPTURE, 0));
    snd_pcm_hw_params_t *hwparams;
    snd_pcm_hw_params_alloca(&hwparams);
    CHECK_ALSA(snd_pcm_hw_params_any(pcm_handle, hwparams));
    CHECK_ALSA(snd_pcm_hw_params_set_access(
                   pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED));
    CHECK_ALSA(snd_pcm_hw_params_set_format(
                   pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE));
    CHECK_ALSA(snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2));
    CHECK_ALSA(snd_pcm_hw_params(pcm_handle, hwparams));
    int dummy;
    CHECK_ALSA(snd_pcm_hw_params_get_rate(
                   hwparams, (unsigned int *)&pcm_rate, &dummy));
    snd_pcm_uframes_t buffer_size;
    CHECK_ALSA(snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size));
    pcm_buffer_size = (int)buffer_size;

    return 1;

  error:
    if (pcm_handle) {
        snd_pcm_close(pcm_handle);
        pcm_handle = NULL;
    }
    sys_sound_cleanup();
    return 0;

    #undef CHECK_ALSA
    #undef FAIL_ACTION
    #define FAIL_ACTION  return 0
}
/**
 * start_capture:  Start capturing PCM data on the ALSA loopback device.
 *
 * [Return value]
 *     True on success, false on failure.
 */
Start capturing PCM data on the ALSA loopback device.
[Return value]
True on success, false on failure.
Start capturing PCM data on the ALSA loopback device . [ Return value ] True on success false on failure .
static int start_capture(void)
{
    #define CHECK_ALSA(call)  do {                       \
        int result;                                      \
        if ((result = (call)) < 0) {                     \
            FAIL("%s: %s", #call, snd_strerror(result)); \
        }                                                \
    } while (0)
    CHECK_TRUE(sound_open_device(LOOPBACK_PLAYBACK_DEVICE, 1));
    #undef FAIL_ACTION
    #define FAIL_ACTION  goto error
    CHECK_ALSA(snd_pcm_open(&pcm_handle, LOOPBACK_CAPTURE_DEVICE,
                            SND_PCM_STREAM_CAPTURE, 0));
    snd_pcm_hw_params_t *hwparams;
    snd_pcm_hw_params_alloca(&hwparams);
    CHECK_ALSA(snd_pcm_hw_params_any(pcm_handle, hwparams));
    CHECK_ALSA(snd_pcm_hw_params_set_access(
                   pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED));
    CHECK_ALSA(snd_pcm_hw_params_set_format(
                   pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE));
    CHECK_ALSA(snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2));
    CHECK_ALSA(snd_pcm_hw_params(pcm_handle, hwparams));
    int dummy;
    CHECK_ALSA(snd_pcm_hw_params_get_rate(
                   hwparams, (unsigned int *)&pcm_rate, &dummy));
    snd_pcm_uframes_t buffer_size;
    CHECK_ALSA(snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size));
    pcm_buffer_size = (int)buffer_size;
    return 1;
  error:
    if (pcm_handle) {
        snd_pcm_close(pcm_handle);
        pcm_handle = NULL;
    }
    sys_sound_cleanup();
    return 0;
    #undef CHECK_ALSA
    #undef FAIL_ACTION
    #define FAIL_ACTION  return 0
}
static int start_capture ( void ) { #define CHECK_ALSA ( call )   do {                       \
        int result;                                      \
        if ((result = (call)) < 0) {                     \
            FAIL("%s: %s", #call, snd_strerror(result)); \
        }                                                \
    } while (0) CHECK_TRUE ( sound_open_device ( LOOPBACK_PLAYBACK_DEVICE , 1 ) ) ; #undef  FAIL_ACTION #define FAIL_ACTION   goto error CHECK_ALSA ( snd_pcm_open ( & pcm_handle , LOOPBACK_CAPTURE_DEVICE , SND_PCM_STREAM_CAPTURE , 0 ) ) ; snd_pcm_hw_params_t * hwparams ; snd_pcm_hw_params_alloca ( & hwparams ) ; CHECK_ALSA ( snd_pcm_hw_params_any ( pcm_handle , hwparams ) ) ; CHECK_ALSA ( snd_pcm_hw_params_set_access ( pcm_handle , hwparams , SND_PCM_ACCESS_RW_INTERLEAVED ) ) ; CHECK_ALSA ( snd_pcm_hw_params_set_format ( pcm_handle , hwparams , SND_PCM_FORMAT_S16_LE ) ) ; CHECK_ALSA ( snd_pcm_hw_params_set_channels ( pcm_handle , hwparams , 2 ) ) ; CHECK_ALSA ( snd_pcm_hw_params ( pcm_handle , hwparams ) ) ; int dummy ; CHECK_ALSA ( snd_pcm_hw_params_get_rate ( hwparams , ( unsigned int * ) & pcm_rate , & dummy ) ) ; snd_pcm_uframes_t buffer_size ; CHECK_ALSA ( snd_pcm_hw_params_get_buffer_size ( hwparams , & buffer_size ) ) ; pcm_buffer_size = ( int ) buffer_size ; return 1 ; error : if ( pcm_handle ) { snd_pcm_close ( pcm_handle ) ; pcm_handle = NULL ; } sys_sound_cleanup ( ) ; return 0 ; #undef  CHECK_ALSA #undef  FAIL_ACTION #define FAIL_ACTION   return 0 }
start_capture:  Start capturing PCM data on the ALSA loopback device.
start_capture : Start capturing PCM data on the ALSA loopback device .
/* Convenience macro for checking ALSA function return codes. */ /* Open the playback side of the loopback device.  This is done first
     * so that the loopback device takes its parameters from those set by
     * the playback code. */ /* Make sure failures close the capture device. */ /* Open the capture side of the loopback device. */