Set snd_pcm_sw_params_set_stop_threshold to boundary, still getting underrun on snd_pcm_writei

  alsa, c++

The question says it all. I am going in circles here. I set snd_pcm_sw_params_set_stop_threshold to boundary (and zero too just for fun) and I am still getting buffer underrun errors on snd_pcm_writei. I cannot understand why. The documentation is pretty clear on this:

If the stop threshold is equal to boundary (also software parameter - sw_param) then automatic stop will be disabled

Here is the code I am using to initialize alsa:

snd_pcm_sw_params_alloca(&sw);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }
    rc = snd_pcm_sw_params_current(audio->handle, sw);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }

    rc = snd_pcm_sw_params_get_boundary(sw, &boundary);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }

    rc = snd_pcm_sw_params_set_stop_threshold(audio->handle, sw, boundary);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }

    rc = snd_pcm_sw_params(audio->handle, sw);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }

    rc = snd_pcm_sw_params_current(audio->handle, sw);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }

    rc = snd_pcm_sw_params_get_stop_threshold(sw, &boundary);
    cout << rc << endl;
    if (rc < 0) {
        log_err("unable to set sw parameters: " + string(snd_strerror(rc)));
        return false;
    }
    cout << "VALUE " << boundary << endl;

Source: Windows Questions C++

LEAVE A COMMENT