您尚未登录。

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

checkout
会员
注册时间: 2018-11-09
已发帖子: 173
积分: 168

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)

离线

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

checkout
会员
注册时间: 2018-11-09
已发帖子: 173
积分: 168

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

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

jimmy 说:

是 widora 的固件吗?

离线

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

checkout
会员
注册时间: 2018-11-09
已发帖子: 173
积分: 168

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

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

jimmy 说:

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

离线

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

checkout
会员
注册时间: 2018-11-09
已发帖子: 173
积分: 168

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

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

jimmy 说:

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

离线

楼主 #8 2020-01-10 14:35:09

checkout
会员
注册时间: 2018-11-09
已发帖子: 173
积分: 168

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

填坑,原因是tinyplay是从wav文件获取播放参数导致的错误,手动指定播放参数即可。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn