Reputation: 533
This problem ocured to me while I was writing a c++ program so I created a minimum instance of the code to clarify the problem better:
#include <portaudio.h>
#include <iostream>
int main()
{
Pa_Initialize();
int devices = Pa_GetDeviceCount();
std::cout << devices << std::endl;
for (int i = 0; i != devices; ++i)
{
auto * info = Pa_GetDeviceInfo(i);
std::cout << info->name << std::endl;
}
Pa_Terminate();
}
So this code should print the devices I have for sound io.I have tested this code on two linux pc's with ubuntu 16 and ubuntu 18.10 and with some tweaks that seems irrational to change the result(I will explain this tweaks afterwards)the results were very absurd . I first run my app on Ubuntu 16 and it detected a lot of devices including sysdefault (which was the useful one). Then I run the same app on ubuntu 18 and it didn't found me sysdefault ,I checked with the commands aplay -L
and arecord -L
that Alsa was recognizing sysdefault so I thought it was a pulseaudio problem . I downloaded pavucontrol and did some tweaks with no luck. Finally here is the more irrational thing ,I tried again to use my app on ubuntu 16 after downloading and tweaking pavucontrol and it didn't work, moreover when I deleted pavucontrol on ubuntu 16 it worked but when I did the same on ubuntu 18 it didn't!
It worth's mentioning to say that my ubuntu 16 is an old system that I had installed a lot of cpp libraries and I have done a lot of tweaks during the last years and on the other hand my ubuntu 18 was a formatted laptop with nearly nothing installed on it.
Here I add some console output for better understanding of the problem:
$aplay -L
>
> default
> Playback/recording through the PulseAudio sound server null
> Discard all samples (playback) or generate zero samples (capture) pulse
> PulseAudio Sound Server hdmi:CARD=HDMI,DEV=0
> HDA Intel HDMI, HDMI 0
> HDMI Audio Output hdmi:CARD=HDMI,DEV=1
> HDA Intel HDMI, HDMI 1
> HDMI Audio Output hdmi:CARD=HDMI,DEV=2
> HDA Intel HDMI, HDMI 2
> HDMI Audio Output dmix:CARD=HDMI,DEV=3
> HDA Intel HDMI, HDMI 0
> Direct sample mixing device dmix:CARD=HDMI,DEV=7
> HDA Intel HDMI, HDMI 1
> Direct sample mixing device dmix:CARD=HDMI,DEV=8
> HDA Intel HDMI, HDMI 2
> Direct sample mixing device dsnoop:CARD=HDMI,DEV=3
> HDA Intel HDMI, HDMI 0
> Direct sample snooping device dsnoop:CARD=HDMI,DEV=7
> HDA Intel HDMI, HDMI 1
> Direct sample snooping device dsnoop:CARD=HDMI,DEV=8
> HDA Intel HDMI, HDMI 2
> Direct sample snooping device hw:CARD=HDMI,DEV=3
> HDA Intel HDMI, HDMI 0
> Direct hardware device without any conversions hw:CARD=HDMI,DEV=7
> HDA Intel HDMI, HDMI 1
> Direct hardware device without any conversions hw:CARD=HDMI,DEV=8
> HDA Intel HDMI, HDMI 2
> Direct hardware device without any conversions plughw:CARD=HDMI,DEV=3
> HDA Intel HDMI, HDMI 0
> Hardware device with all software conversions plughw:CARD=HDMI,DEV=7
> HDA Intel HDMI, HDMI 1
> Hardware device with all software conversions plughw:CARD=HDMI,DEV=8
> HDA Intel HDMI, HDMI 2
> Hardware device with all software conversions sysdefault:CARD=PCH
> HDA Intel PCH, ALC3234 Analog
> Default Audio Device front:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> Front speakers surround21:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> 2.1 Surround output to Front and Subwoofer speakers surround40:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> 4.0 Surround output to Front and Rear speakers surround41:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> 4.1 Surround output to Front, Rear and Subwoofer speakers surround50:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> 5.0 Surround output to Front, Center and Rear speakers surround51:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> 5.1 Surround output to Front, Center, Rear and Subwoofer speakers surround71:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers dmix:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> Direct sample mixing device dsnoop:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> Direct sample snooping device hw:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> Direct hardware device without any conversions plughw:CARD=PCH,DEV=0
> HDA Intel PCH, ALC3234 Analog
> Hardware device with all software conversions
And running the app :
$./main
6
HDA Intel HDMI: 0 (hw:0,3)
HDA Intel HDMI: 1 (hw:0,7)
HDA Intel HDMI: 2 (hw:0,8)
hdmi
pulse
default
The question/request is : What creates the problem? It probably is not alsa so is it portaudio? but it worked on the first case so is it pulseaudio?and if yes how can I solve the problem now that I reproduced it?
Upvotes: 4
Views: 2361
Reputation: 533
After all the problem occurred by Alsa . I have two sound cards (or at least two virtual sound cards) on the Ubuntu 18 machine and Alsa was reading by default only the one .There are many workarounds to this problem ,the one that worked for me was to change/create the config file /etc/asound.conf
with this two lines :
defaults.pcm.card 2
defaults.ctl.card 1
~
That changed which was the default card.
Upvotes: 1