11#include < fcntl.h>
22#include < unistd.h>
3- #include < portaudio.h>
43#include < pulse/simple.h>
54#include < pulse/error.h>
65
@@ -15,26 +14,6 @@ using namespace hula;
1514 */
1615LinuxAudio::LinuxAudio ()
1716{
18- #if HL_NO_DEBUG_OUTPUT
19- int out = dup (1 );
20- int temp_null = open (" /dev/null" , O_WRONLY);
21- dup2 (temp_null, 1 );
22- close (temp_null);
23- #endif
24-
25- // Initialize PortAudio
26- PaError err = Pa_Initialize ();
27- if (err != paNoError)
28- {
29- hlDebugf (" PortAudio failed to initialize.\n " );
30- hlDebugf (" PortAudio: %s\n " , Pa_GetErrorText (err));
31- throw AudioException (HL_PA_INIT_CODE, HL_PA_INIT_MSG);
32- }
33-
34- #if HL_NO_DEBUG_OUTPUT
35- dup2 (out, 1 );
36- close (out);
37- #endif
3817}
3918
4019/* *
@@ -62,7 +41,7 @@ std::vector<Device *> LinuxAudio::getDevices(DeviceType type)
6241 HulaAudioSettings *s = HulaAudioSettings::getInstance ();
6342
6443 // Fetch from pactl
65- if (loopSet || recSet)
44+ if (loopSet || recSet || playSet )
6645 {
6746 std::vector<Device *> newDevices = parsePulseAudioDevices ();
6847
@@ -76,49 +55,9 @@ std::vector<Device *> LinuxAudio::getDevices(DeviceType type)
7655 {
7756 devices.push_back (newDevices[i]);
7857 }
79- }
80- }
81-
82- // Get devices from PortAudio if record or playback devices are requested
83- if (playSet)
84- {
85- // Get the total count of audio devices
86- int deviceCount = Pa_GetDeviceCount ();
87- if (deviceCount < 0 )
88- {
89- hlDebugf (" Failed to fetch PortAudio devices.\n " );
90- exit (1 ); // TODO: Handle error
91- }
92-
93- for (uint32_t i = 0 ; i < deviceCount; i++)
94- {
95- const PaDeviceInfo *paDevice = Pa_GetDeviceInfo (i);
96- DeviceType checkType = (DeviceType) 0 ;
97-
98- if (playSet && paDevice->maxOutputChannels > 0 )
99- {
100- checkType = (DeviceType)(checkType | DeviceType::PLAYBACK);
101- }
102-
103- // Disabled until LinuxAudio switches over
104- /* if (recSet && paDevice->maxInputChannels > 0)
105- {
106- checkType = (DeviceType)(checkType | DeviceType::RECORD);
107- } */
108-
109- // Create HulaLoop style device and add to vector
110- // This needs to be freed elsewhere
111- if (checkType)
58+ else if (playSet && newDevices[i]->getType () == DeviceType::PLAYBACK)
11259 {
113- if (checkType == DeviceType::RECORD && !s->getShowRecordDevices ())
114- {
115- continue ;
116- }
117-
118- DeviceID id;
119- id.portAudioID = i;
120- Device *hlDevice = new Device (id, std::string (paDevice->name ), checkType);
121- devices.push_back (hlDevice);
60+ devices.push_back (newDevices[i]);
12261 }
12362 }
12463 }
@@ -254,38 +193,6 @@ bool LinuxAudio::checkDeviceParams(Device *device)
254193{
255194 int err = 0 ;
256195
257- if (device->getID ().portAudioID != -1 )
258- {
259- hlDebug () << " Testing PortAudio device" << std::endl;
260-
261- PaStreamParameters parameters = {0 };
262- parameters.channelCount = NUM_CHANNELS;
263- parameters.device = device->getID ().portAudioID ;
264- parameters.sampleFormat = paFloat32;
265-
266- PaError err;
267- if (device->getType () & DeviceType::PLAYBACK)
268- {
269- err = Pa_IsFormatSupported (nullptr , ¶meters, HulaAudioSettings::getInstance ()->getSampleRate ());
270- }
271- else
272- {
273- err = Pa_IsFormatSupported (¶meters, nullptr , HulaAudioSettings::getInstance ()->getSampleRate ());
274- }
275-
276- if (err == paFormatIsSupported)
277- {
278- hlDebug () << " Sample rate and format were valid." << std::endl;
279- }
280- else
281- {
282- hlDebug () << " Sample rate and format were NOT valid." << std::endl;
283- throw AudioException (HL_CHECK_PARAMS_CODE, HL_CHECK_PARAMS_MSG);
284- }
285-
286- return err == paFormatIsSupported;
287- }
288-
289196 hlDebug () << " Testing PulseAudio device: " << device->getID ().linuxID << std::endl;
290197
291198 // PulseAudio variables
@@ -436,12 +343,4 @@ LinuxAudio::~LinuxAudio()
436343 hlDebugf (" LinuxAudio destructor called\n " );
437344
438345 system (" pkill pavucontrol" );
439-
440- // Close the Port Audio session
441- PaError err = Pa_Terminate ();
442- if (err != paNoError)
443- {
444- hlDebugf (" Could not terminate Port Audio session.\n " );
445- hlDebugf (" PortAudio: %s\n " , Pa_GetErrorText (err));
446- }
447346}
0 commit comments