Toybrick

标题: RK3399 调试声卡,使用alsa进行录放音,初始化报错? [打印本页]

作者: sunny    时间: 2019-4-24 17:22
标题: RK3399 调试声卡,使用alsa进行录放音,初始化报错?
打印报错如下,请问使用alsa需要注意些什么?这个错误是什么导致?
<audiodev.cpp><sound_alsa_create:694>the para as follow:
<audiodev.cpp><sound_alsa_create:695>m_snd_attrs.soundStd:1
<audiodev.cpp><sound_alsa_create:696>m_snd_attrs.sampleRate:16000
<audiodev.cpp><sound_alsa_create:697>m_snd_handle->channels:2
<audiodev.cpp><sound_alsa_create:698>m_snd_handle->periodSize:512
<audiodev.cpp><sound_alsa_create:702>snd_pcm_open enter 0
<audiodev.cpp><sound_alsa_create:706>snd_pcm_open enter 1
<audiodev.cpp><sound_alsa_create:713>snd_pcm_open over
[  586.588446] rockchip-i2s ff890000.i2s: Fail to set mclk -22
[  586.599372] asoc-simple-card rt5651-sound: ASoC: machine hw_params failed: -22
<audiodev.cpp><_init_hwparams:496>Failed to set ALSA parameters on hw:0,0 (Invalid argument)
<audioserver.cpp><audio_init:223>sound_alsa_create error!
<audioserver.cpp><audioserver_start:282>audio_init error!

alsa初始化部分如下:
int Csound_alsa_soc::_init_hwparams(snd_pcm_t *rc, snd_pcm_hw_params_t *hwParams)
{
    int my_res = 0;
    snd_pcm_uframes_t bufSize = 0;
    snd_pcm_uframes_t periodSize = 0;
    unsigned int buffer_time = 0;
    unsigned int sampleRate = 0;

    ADEBUG(1, "Enter\n");

    /* Fill the params with the defaults */
    my_res = snd_pcm_hw_params_any(rc, hwParams);
    if (my_res < 0) {
        ADEBUG(0, "Failed to init ALSA hardware param structure on %s (%s)\n",
                  AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }

    /* Set the access type to interleaved */
    my_res = snd_pcm_hw_params_set_access(rc, hwParams,
                                          DEF_PCM_ACCESS_MODE);//SND_PCM_ACCESS_RW_INTERLEAVED DEF_PCM_ACCESS_MODE
    if (my_res < 0) {
        ADEBUG(0, "Failed to set ALSA access type on %s (%s)\n",
                  AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }

    /* Set the format to 16 bit little endian */
    my_res = snd_pcm_hw_params_set_format(rc, hwParams, DEF_PCM_FORMAT);
    if (my_res < 0) {
        ADEBUG(0, "Failed to set sample format on %s (%s)\n",
                  AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }

    /* Set the sample rate */
    sampleRate = m_snd_attrs.sampleRate;
    my_res = snd_pcm_hw_params_set_rate_near(rc, hwParams,
                                             &sampleRate, 0);
    if (my_res < 0) {
        ADEBUG(0, "Failed to set sample rate to %d on %s (%s)\n",
                  m_snd_attrs.sampleRate, AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }

    /* Set the number of channels to 2 */
    my_res = snd_pcm_hw_params_set_channels(rc, hwParams, m_snd_attrs.channels);
    if (my_res < 0) {
        ADEBUG(0, "Failed to set channel count to %d on %s (%s)\n",
                  m_snd_attrs.channels, AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }


    /* Set period size equal to input buffer size */
    m_snd_handle->periodSize = 256;
    periodSize = m_snd_handle->periodSize;
    my_res = snd_pcm_hw_params_set_period_size_near (rc, hwParams,
                                                      &periodSize, 0);
    if (my_res < 0) {
        ADEBUG(0, "Failed to set the period size to %ld on %s (%s)\n",
                  periodSize, AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }
    if (periodSize != m_snd_handle->periodSize) {
        ADEBUG(0, "Failed to set period size (%ld) , got (%ld) on %s (%s)\n",
                    m_snd_handle->periodSize, periodSize, AUDIO_DEVICE,
                    snd_strerror(my_res));
        m_snd_handle->periodSize = periodSize;
    }

     /* Set the maximum buffer time */
    my_res = snd_pcm_hw_params_get_buffer_time_max(hwParams, &buffer_time, 0);
    ADEBUG(3, "maximum buffer time<%d>\n", buffer_time);
    if (my_res < 0) {
        ADEBUG(0, "Failed to get maximum buffer time on %s (%s)\n",
                   AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }

    if (buffer_time > DEF_BUF_TIME) {
        buffer_time = DEF_BUF_TIME;
    }

    my_res = snd_pcm_hw_params_set_buffer_time_near(rc, hwParams,
                &buffer_time, 0);

    if (my_res < 0) {
        ADEBUG(0, "Failed to set maximum buffer time on %s (%s)\n",
                   AUDIO_DEVICE, snd_strerror(my_res));
        return SCERR_FAIL;
    }

    /*! check hardware can support pause operation or not */
    if (snd_pcm_hw_params_can_pause(hwParams) == 1)
    {
        ADEBUG(3, "hardware do support pause operation\n");
    }else{
        ADEBUG(3, "hardware not support pause operation\n");
    }
。。。



作者: sunny    时间: 2019-4-24 20:25
先设置成高采样率,比如44.1K、48K后,再设置成16k或者8k,可以正常采样,请问咋回事?
作者: qiu    时间: 2019-4-26 09:09
sunny 发表于 2019-4-24 20:25
先设置成高采样率,比如44.1K、48K后,再设置成16k或者8k,可以正常采样,请问咋回事? ...

RK3399?   不是TB-RK3399Pro的板子吗
作者: sunny    时间: 2019-5-8 13:40
qiu 发表于 2019-4-26 09:09
RK3399?   不是TB-RK3399Pro的板子吗

是友善之臂的板子,也是RK3399的




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3