WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: ALSA volume control with a DAC  (Read 6637 times)

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
ALSA volume control with a DAC
« on: September 09, 2015, 02:54:12 PM »
I have a raspberry pi B+ board with an IQaudIODAC+ installed, to which I have added a rotary encoder to control the volume. I have compiled a c++ routine from the IQaudIO site that uses an API call that needs the device name for the volume control. Without the DAC the volume control is "PCM". Using alsamixer I can manipulate the volume by changing the values for the PCM control and the rotary encoder works as it should. However, with the DAC, the volume control should be "Digital". I can use alsamixer, select the IQaudioDAC card and manipulate the volume by changing the values for the Digital control. Compiling with "Digital" instead of "PCM" just gives an error:

Runs with error:IQ_rot: simple.c:282: snd_mixer_selem_get_playback_volume_range: Assertion `elem' failed.

This means ALSA cannot find the control called "Digital". The only control visible to ALSA is "PCM" but modifying this has no effect on the volume. I'm stumped and I'd be grateful for any suggestions.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: ALSA volume control with a DAC
« Reply #1 on: September 11, 2015, 03:47:59 AM »
I think the problem is that the onboard and DAC cards are both defined as default so the control name is only matched to the first. Either the cards need to be reordered or the explicit card name should be used in the code but the latter doesn't seem to work based on the names in /car/proc/asound/cards, i.e. IQaudIODAC.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: ALSA volume control with a DAC
« Reply #2 on: September 11, 2015, 04:03:46 AM »
What is the /car directory?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

gordon64

  • Guest
Re: ALSA volume control with a DAC
« Reply #3 on: September 11, 2015, 05:33:36 AM »
Hi I hope you don't mind me jumping in, before I slink away as I don't have a RPi

I think OP means cat and he is probably looking to show the output to this command,
and suggest he also shows the aplay -l result please?

Code: [Select]
cat /proc/asound/pcm

(my example)
00-00: ALC887-VD Analog : ALC887-VD Analog : playback 1 : capture 1
00-01: ALC887-VD Digital : ALC887-VD Digital : playback 1
00-02: ALC887-VD Alt Analog : ALC887-VD Alt Analog : capture 1

aplay -l

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: ALSA volume control with a DAC
« Reply #4 on: September 11, 2015, 10:02:39 AM »
You are indeed correct. My apologies for the confusion but I was in a bit of a nervous panic.

I had some help and have this working by removing "audio=on" from the config.txt file. The IQaudioDAC is now the only default and the "Digital" control name works. It is a workaround though as I'd like to modify the code to pass the card name and control name as command line parameters without having to remove that line from the config file. I'll also add gpio pins and volume increments as parameters as I imagine no two rotary encoders are alike.

To answer your question directly though.... Without removing "audio = on" I get:

tc@piCorePlayer:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: IQaudIODAC [IQaudIODAC], device 0: IQaudIO DAC HiFi pcm512x-hifi-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0

also...

tc@piCorePlayer:~$ cat /proc/asound/cards
 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA
 1 [IQaudIODAC     ]: IQaudIODAC - IQaudIODAC
                      IQaudIODAC

tc@piCorePlayer:~$ cat /proc/asound/pcm
00-00: bcm2835 ALSA : bcm2835 ALSA : playback 8
00-01: bcm2835 ALSA : bcm2835 IEC958/HDMI : playback 1
01-00: IQaudIO DAC HiFi pcm512x-hifi-0 :  : playback 1


The program is currently hardcoded with the card name as "default" (but both cards are marked as default), and the control name as "Digital". This doesn't work because I believe that the first "default" is used. Removing "audio=on" removes that card completely and the code works. I've also tried hard coding the card name as "IQaudIODAC" but that didn't work.

Thanks for your help.

gordon64

  • Guest
Re: ALSA volume control with a DAC
« Reply #5 on: September 11, 2015, 10:59:56 AM »
Hi

We now know you have 2 cards visible to Alsa and its card 1 you want

first lets try to create a .asoudrc file (dot) asoundrc in home folder......later if this fails we try the index=1 with kernel models to swap card positions

try this as local user

Code: [Select]
echo 'pcm.!default {
type hw
card 1
device 0
}

ctl.card1 {
type hw
card 1
device 0
}' > .asoundrc

reboot and see if alsamixer now shows what was card 1 as the new default card.

good luck

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: ALSA volume control with a DAC
« Reply #6 on: September 11, 2015, 12:23:05 PM »
It looks like you are not using piCore but a derivate, piCorePlayer. In native piCore the built-in sound device not started by default to avoid such issues with an optional sound card, kernel module must be modprobed explicitely.

Also, in piCorePlayer you can manage sound devices via the WEB interface which is expected to work. If not, better to use the piCorePlayer site to get support for the player. You can also PM sbp, author of piCorePlayer.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: ALSA volume control with a DAC
« Reply #7 on: September 11, 2015, 03:22:13 PM »
It looks like you are not using piCore but a derivate, piCorePlayer. In native piCore the built-in sound device not started by default to avoid such issues with an optional sound card, kernel module must be modprobed explicitely.

Also, in piCorePlayer you can manage sound devices via the WEB interface which is expected to work. If not, better to use the piCorePlayer site to get support for the player. You can also PM sbp, author of piCorePlayer.

You are correct. I am seeking help there too but there's now a bit of circular referring going on! I am forking the code and using it as an opportunity to learn some C and crack this nut. Despite both cards being marked as default I would have still expected it to be possible to index the DAC directly by name rather than work around by editing .asoundrc to change the order, but this doesn't appear to be the case so far. The piCore method seems a logical approach so I'll quiz the piCorePlayer board. Thanks for the pointers.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: ALSA volume control with a DAC
« Reply #8 on: September 11, 2015, 03:25:43 PM »
Hi

We now know you have 2 cards visible to Alsa and its card 1 you want

first lets try to create a .asoudrc file (dot) asoundrc in home folder......later if this fails we try the index=1 with kernel models to swap card positions

try this as local user

Code: [Select]
echo 'pcm.!default {
type hw
card 1
device 0
}

ctl.card1 {
type hw
card 1
device 0
}' > .asoundrc

reboot and see if alsamixer now shows what was card 1 as the new default card.

good luck

I don't think the home folder is persistent in piCorePlayer. It has been pointed out that there are some differences with piCore so I'll quiz them about the modprobe before I lead you a merry dance. Thank you for your help.