2

I have a test.wav file that I wanna play through speaker using ALSA. I also have sox installed on the system. All sound cards are installed properly. aplay -L and arecord -L return the correct value.

However I wasn't able to play this test.wav.

aplay -c1 -r 48000 -f S16_LE test.wav
$ Playing WAVE 'test.wav': Signed 16 bit Little Endian, Rate 48000 Hz, Mono
  aplay: set_params:1345: Channels count non available

But when i used sox, the system had no problem and it shows that the file is indeed 1 channel at 16-bit

$ Encoding: Signed PCM
  Channels: 1 @ 16-bit
  Samplerate: 48000Hz

I really have no clue what the reason could be. Any help is appreciated! Thank you guys in advance!

EDIT:

  1. My mistake when I hand typed the message printed in the terminal, it is indeed 1@16 bit when I used SoX instead.

  2. .asoundrc

pcm.!default {
 type hw
 card 0
}
ctl.!default {
 type hw
 card 0
}
  1. When I use arecord, I need to specify the channel counts: arecord -c 2 -r 48000 -f S16_LE test.wav Otherwise it will return the same error above. But then I have no problem playing test.wav if it is recorded using arecord. It is weird that I can't play a test.wav if it is imported from elsewhere.
4
  • Hmm, Channels: 2@16-bit seems like stereo to me. But: Can you try to play as root? maybe you don't have the rights to change the card-config.
    – stoney
    Commented Oct 21, 2020 at 6:15
  • You do not need -c/r/f options for .wav files. I guess sox automatically converts the samples. Did you do any changes to your .asoundrc or asound.conf?
    – CL.
    Commented Oct 21, 2020 at 12:44
  • @CL. I did changed .asoundrc in order to make my external sound card default. I am using a HiFiberry dac. I will put the file content in the edits
    – Yihan Hu
    Commented Oct 21, 2020 at 15:44
  • @stoney You are correct! It is sudo!! Thank you so much!! Do you know how to change the settings so that my current user pi can also use arecord? I will accept your answer if you don't mind answering below.
    – Yihan Hu
    Commented Oct 21, 2020 at 15:51

2 Answers 2

2

By changing the configuration of the user pi to use hw devices, you have disabled all automatic sample format conversions.

To set only the card number, use:

defaults.pcm.card 0
defaults.ctl.card 0

To change this for all users instead, put this into /etc/asound.conf.

3
  • That is something new i learn today. Sorry, just to clarify, /etc/asound.conf applies to all users, and I'd put the content of .asoundrc in asound.conf instead correct?
    – Yihan Hu
    Commented Oct 21, 2020 at 19:06
  • And where would I set up defaults.pcm.card?
    – Yihan Hu
    Commented Oct 21, 2020 at 19:07
  • This goes into the same file (the user's .asoundrc or the global /etc/asound.conf).
    – CL.
    Commented Oct 22, 2020 at 6:02
2

I was able to solve my sudo permission problem by doing the following:

sudo nano /root/.asoundrc

pcm.!default {
 type hw
 card 0
}
ctl.!default {
 type hw
 card 0
}

And then I commented out .asoundrc in home directory and asound.conf. Now I can use aplay and arecord on wav files without specifying the options.

The solution is from alsa-project web sit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .