Toybrick

RK3399 调试声卡,使用alsa进行录放音,初始化报错?

sunny

新手上路

积分
21
发表于 2019-4-24 17:22:02    查看: 5933|回复: 3 | [复制链接]    打印 | 显示全部楼层
打印报错如下,请问使用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

新手上路

积分
21
 楼主| 发表于 2019-4-24 20:25:43 | 显示全部楼层
先设置成高采样率,比如44.1K、48K后,再设置成16k或者8k,可以正常采样,请问咋回事?
回复

使用道具 举报

qiu

版主

积分
1130
发表于 2019-4-26 09:09:42 | 显示全部楼层
sunny 发表于 2019-4-24 20:25
先设置成高采样率,比如44.1K、48K后,再设置成16k或者8k,可以正常采样,请问咋回事? ...

RK3399?   不是TB-RK3399Pro的板子吗
回复

使用道具 举报

sunny

新手上路

积分
21
 楼主| 发表于 2019-5-8 13:40:51 | 显示全部楼层
qiu 发表于 2019-4-26 09:09
RK3399?   不是TB-RK3399Pro的板子吗

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

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表