WhyCan Forum

本站无需注册,无需积分,无需回复可下载所有资料,如果真的喜欢小站,请您注册之后请至少回复一个帖子激活Id,谢谢支持! 站长QQ: 516333132 (挖坑网/填坑网) admin@whycan.cn

您尚未登录。

#1 2019-09-10 21:59:05

checkout
会员
注册时间: 2018-11-09
累计积分: 70

openwrt使用tinyalsa,无法播放音乐

最近玩openwrt,按之前V3S的套路移植tinyalsa到widora-NEO开发板上

播放wav音乐报错,提示打开pcm0-0失败,但查看了一下声卡是存在的

root@Widora:/mnt# ./tinyalsa/tinyplay 10.wav 
[ 2347.370000] playback free_dma_buffer
[ 2347.380000] ptri2s_config->mmap_index:8
failed to open for pcm 0,0

使用aplay播放wav和使用madplay播放MP3都是没问题,mixer配置应该也没问题
有没大佬知道什么原因??

root@Widora:/mnt# cat /proc/asound/cards 
 0 [I2S            ]: MTK_APSoC_I2S - MTK APSoC I2S
                      MTK APSoC I2S
root@Widora:/mnt# cat /proc/asound/pcm
00-00: WMserious PCM wm8960-hifi-0 :  : playback 1 : capture 1
root@Widora:/mnt# cat /proc/asound/devices 
  0: [ 0]   : control
 16: [ 0- 0]: digital audio playback
 24: [ 0- 0]: digital audio capture
 33:        : timer
root@Widora:/mnt# ./tinyalsa/tinymix contents
Number of controls: 54
ctl     type    num     name                                    value
0       INT     2       Capture Volume                          43, 43 (range 0->63)
1       INT     2       Capture Volume ZC Switch                0, 0 (range 0->1)
2       BOOL    2       Capture Switch                          Off, Off
3       INT     1       Right Input Boost Mixer RINPUT3 Volume  0 (range 0->7)
4       INT     1       Right Input Boost Mixer RINPUT2 Volume  0 (range 0->7)
5       INT     1       Left Input Boost Mixer LINPUT3 Volume   0 (range 0->7)
6       INT     1       Left Input Boost Mixer LINPUT2 Volume   0 (range 0->7)
7       INT     2       Playback Volume                         255, 255 (range 0->255)
8       INT     2       Headphone Playback Volume               127, 127 (range 0->127)
9       BOOL    2       Headphone Playback ZC Switch            On, On
10      INT     2       Speaker Playback Volume                 123, 123 (range 0->127)
11      BOOL    2       Speaker Playback ZC Switch              Off, Off
12      INT     1       Speaker DC Volume                       5 (range 0->5)
13      INT     1       Speaker AC Volume                       5 (range 0->5)
14      BOOL    1       PCM Playback -6dB Switch                Off
15      ENUM    1       ADC Polarity                            , No InversionLeft InvertedRight InvertedStereo Inversion
16      BOOL    1       ADC High Pass Filter Switch             Off
17      ENUM    1       DAC Polarity                            , No InversionLeft InvertedRight InvertedStereo Inversion
18      BOOL    1       DAC Deemphasis Switch                   Off
19      ENUM    1       3D Filter Upper Cut-Off                 0 (range 0->7)
20      ENUM    1       3D Filter Lower Cut-Off                 0 (range 0->7)
21      INT     1       3D Volume                               0 (range 0->7)
22      BOOL    1       3D Switch                               0 (range 0->7)
23      ENUM    1       ALC Function                            , OffRightLeftStereo
24      INT     1       ALC Max Gain                            7 (range 0->7)
25      INT     1       ALC Target                              4 (range 0->15)
26      INT     1       ALC Min Gain                            0 (range 0->7)
27      INT     1       ALC Hold Time                           0 (range 0->15)
28      ENUM    1       ALC Mode                                , ALCLimiter
29      INT     1       ALC Decay                               3 (range 0->15)
30      INT     1       ALC Attack                              2 (range 0->15)
31      INT     1       Noise Gate Threshold                    0 (range 0->31)
32      BOOL    1       Noise Gate Switch                       Off
33      INT     2       ADC PCM Capture Volume                  195, 195 (range 0->255)
34      INT     1       Left Output Mixer Boost Bypass Volume   2 (range 0->7)
35      INT     1       Left Output Mixer LINPUT3 Volume        7 (range 0->7)
36      INT     1       Right Output Mixer Boost Bypass Volume  2 (range 0->7)
37      INT     1       Right Output Mixer RINPUT3 Volume       7 (range 0->7)
38      BOOL    1       Mono Output Mixer Left Switch           Off
39      BOOL    1       Mono Output Mixer Right Switch          Off
40      BOOL    1       Right Output Mixer PCM Playback Switch  On
41      BOOL    1       Right Output Mixer RINPUT3 Switch       Off
42      BOOL    1       Right Output Mixer Boost Bypass Switch  Off
43      BOOL    1       Left Output Mixer PCM Playback Switch   On
44      BOOL    1       Left Output Mixer LINPUT3 Switch        Off
45      BOOL    1       Left Output Mixer Boost Bypass Switch   Off
46      BOOL    1       Right Input Mixer Boost Switch          On
47      BOOL    1       Left Input Mixer Boost Switch           On
48      BOOL    1       Right Boost Mixer RINPUT2 Switch        On
49      BOOL    1       Right Boost Mixer RINPUT3 Switch        Off
50      BOOL    1       Right Boost Mixer RINPUT1 Switch        On
51      BOOL    1       Left Boost Mixer LINPUT2 Switch         On
52      BOOL    1       Left Boost Mixer LINPUT3 Switch         Off
53      BOOL    1       Left Boost Mixer LINPUT1 Switch         On
root@Widora:/mnt# ls /dev/snd/
controlC0  pcmC0D0c   pcmC0D0p   timer

跟踪了一下源码
这是tinyplay 打开pcm的源码

/** Opens a PCM.
 * @param card The card that the pcm belongs to.
 *  The default card is zero.
 * @param device The device that the pcm belongs to.
 *  The default device is zero.
 * @param flags Specify characteristics and functionality about the pcm.
 *  May be a bitwise AND of the following:
 *   - @ref PCM_IN
 *   - @ref PCM_OUT
 *   - @ref PCM_MMAP
 *   - @ref PCM_NOIRQ
 *   - @ref PCM_MONOTONIC
 * @param config The hardware and software parameters to open the PCM with.
 * @returns A PCM structure.
 *  If an error occurs allocating memory for the PCM, NULL is returned.
 *  Otherwise, client code should check that the PCM opened properly by calling @ref pcm_is_ready.
 *  If @ref pcm_is_ready, check @ref pcm_get_error for more information.
 * @ingroup libtinyalsa-pcm
 */
struct pcm *pcm_open(unsigned int card, unsigned int device,
                     unsigned int flags, const struct pcm_config *config)
{
    struct pcm *pcm;
    struct snd_pcm_info info;
    char fn[256];
    int rc;

    pcm = calloc(1, sizeof(struct pcm));
    if (!pcm)
        return &bad_pcm;

    snprintf(fn, sizeof(fn), "/dev/snd/pcmC%uD%u%c", card, device,
             flags & PCM_IN ? 'c' : 'p');

    pcm->flags = flags;
    pcm->fd = open(fn, O_RDWR);
    if (pcm->fd < 0) {
        oops(pcm, errno, "cannot open device '%s'", fn);
        return pcm;
    }

    if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_INFO, &info)) {
        oops(pcm, errno, "cannot get info");
        goto fail_close;
    }
    pcm->subdevice = info.subdevice;

    if (pcm_set_config(pcm, config) != 0)
        goto fail_close;

    rc = pcm_hw_mmap_status(pcm);
    if (rc < 0) {
        oops(pcm, rc, "mmap status failed");
        goto fail;
    }

#ifdef SNDRV_PCM_IOCTL_TTSTAMP
    if (pcm->flags & PCM_MONOTONIC) {
        int arg = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
        rc = ioctl(pcm->fd, SNDRV_PCM_IOCTL_TTSTAMP, &arg);
        if (rc < 0) {
            oops(pcm, rc, "cannot set timestamp type");
            goto fail;
        }
    }
#endif

    pcm->underruns = 0;
    return pcm;

fail:
    if (flags & PCM_MMAP)
        munmap(pcm->mmap_buffer, pcm_frames_to_bytes(pcm, pcm->buffer_size));
fail_close:
    close(pcm->fd);
    pcm->fd = -1;
    return pcm;
}

按提示,加了get_pcm_error()跟踪错误信息,貌似是ioctl设置参数的时候出错

root@Widora:/mnt# ./tinyalsa/tinyplay 10.wav
[ 3856.980000] playback free_dma_buffer
[ 3856.980000] ptri2s_config->mmap_index:8
Unable to open PCM device (cannot set hw params: Unknown error -22)

离线

#2 2019-09-10 22:22:08

jimmy
Moderator
注册时间: 2017-10-29
累计积分: 175

Re: openwrt使用tinyalsa,无法播放音乐

是 widora 的固件吗?

离线

#3 2019-09-10 22:28:07

checkout
会员
注册时间: 2018-11-09
累计积分: 70

Re: openwrt使用tinyalsa,无法播放音乐

是的。wiora-NEO,16Mflash,版本0.1.8的固件
widora官方固件网址

jimmy 说:

是 widora 的固件吗?

离线

#4 2019-09-10 22:29:40

jimmy
Moderator
注册时间: 2017-10-29
累计积分: 175

Re: openwrt使用tinyalsa,无法播放音乐

aplay或者madplay有没有声音输出?

离线

#5 2019-09-10 22:50:35

checkout
会员
注册时间: 2018-11-09
累计积分: 70

Re: openwrt使用tinyalsa,无法播放音乐

有声音输出,这两个软件可以正常使用。

jimmy 说:

aplay或者madplay有没有声音输出?

离线

#6 2019-09-10 22:52:27

jimmy
Moderator
注册时间: 2017-10-29
累计积分: 175

Re: openwrt使用tinyalsa,无法播放音乐

我记得 tinyplay 可以指定声卡, 你可以先列出所有声卡

离线

#7 2019-09-10 23:23:29

checkout
会员
注册时间: 2018-11-09
累计积分: 70

Re: openwrt使用tinyalsa,无法播放音乐

可以指定声卡,但系统只有一个声卡,应该不是这个问题

jimmy 说:

我记得 tinyplay 可以指定声卡, 你可以先列出所有声卡

离线

页脚