+ int duplex = 0;
+ std::string audio_device;
+ std::string alsa_device;
+ std::map<std::string, std::string> devices;
+
+ if (_input_audio_device == _("None") && _output_audio_device == _("None")) {
+ PBD::error << _("AlsaAudioBackend: At least one of input or output device needs to be set.");
+ return -1;
+ }
+
+ if (_input_audio_device != _output_audio_device) {
+ if (_input_audio_device != _("None") && _output_audio_device != _("None")) {
+ PBD::error << _("AlsaAudioBackend: Cannot use two different devices.");
+ return -1;
+ }
+ if (_input_audio_device != _("None")) {
+ get_alsa_audio_device_names(devices, HalfDuplexIn);
+ audio_device = _input_audio_device;
+ duplex = 1;
+ } else {
+ get_alsa_audio_device_names(devices, HalfDuplexOut);
+ audio_device = _output_audio_device;
+ duplex = 2;
+ }
+ } else {
+ get_alsa_audio_device_names(devices);
+ audio_device = _input_audio_device;
+ duplex = 3;
+ }
+
+ for (std::map<std::string, std::string>::const_iterator i = devices.begin (); i != devices.end(); ++i) {
+ if (i->first == audio_device) {
+ alsa_device = i->second;
+ break;
+ }
+ }
+ if (alsa_device == "") {
+ PBD::error << _("AlsaAudioBackend: Cannot find configured device. Is it still connected?");
+ return -1;
+ }
+
+ acquire_device(alsa_device.c_str());
+ _pcmi = new Alsa_pcmi (
+ (duplex & 2) ? alsa_device.c_str() : NULL,
+ (duplex & 1) ? alsa_device.c_str() : NULL,
+ 0, _samplerate, _samples_per_period, _periods_per_cycle, 0);
+ switch (_pcmi->state ()) {
+ case 0: /* OK */ break;
+ case -1: PBD::error << _("AlsaAudioBackend: failed to open device.") << endmsg; break;
+ case -2: PBD::error << _("AlsaAudioBackend: failed to allocate parameters.") << endmsg; break;
+ case -3: PBD::error << _("AlsaAudioBackend: cannot set requested sample rate.") << endmsg; break;
+ case -4: PBD::error << _("AlsaAudioBackend: cannot set requested period size.") << endmsg; break;
+ case -5: PBD::error << _("AlsaAudioBackend: cannot set requested number of periods.") << endmsg; break;
+ case -6: PBD::error << _("AlsaAudioBackend: unsupported sample format.") << endmsg; break;
+ default: PBD::error << _("AlsaAudioBackend: initialization failed.") << endmsg; break;
+ }