@@ -90,11 +90,6 @@ bool CubebBackend::DefaultDeviceChanged()
9090 }
9191
9292 device_handle device = GetDevice ();
93- if (!device.handle )
94- {
95- Cubeb.error (" Selected device not found. Trying alternative approach..." );
96- device = GetDefaultDeviceAlt (m_sampling_rate, m_sample_size, m_channels);
97- }
9893
9994 return !device.handle || device.id != m_default_device;
10095}
@@ -119,20 +114,9 @@ bool CubebBackend::Open(std::string_view dev_id, AudioFreq freq, AudioSampleSize
119114
120115 if (!device.handle )
121116 {
122- if (use_default_device)
123- {
124- device = GetDefaultDeviceAlt (freq, sample_size, static_cast <u32 >(ch_cnt));
125-
126- if (!device.handle )
127- {
128- Cubeb.error (" Cannot detect default device. Channel count detection unavailable." );
129- }
130- }
131- else
132- {
133- Cubeb.error (" Device with id=%s not found" , dev_id);
134- return false ;
135- }
117+ if (use_default_device) Cubeb.error (" Opening default device failed" );
118+ else Cubeb.error (" Device with id=%s not found" , dev_id);
119+ return false ;
136120 }
137121
138122 if (device.ch_cnt == 0 )
@@ -358,68 +342,6 @@ CubebBackend::device_handle CubebBackend::GetDevice(std::string_view dev_id)
358342 return result;
359343};
360344
361- CubebBackend::device_handle CubebBackend::GetDefaultDeviceAlt (AudioFreq freq, AudioSampleSize sample_size, u32 ch_cnt)
362- {
363- Cubeb.notice (" Starting alternative search for default device with freq=%d, sample_size=%d and ch_cnt=%d" , static_cast <u32 >(freq), static_cast <u32 >(sample_size), static_cast <u32 >(ch_cnt));
364-
365- cubeb_stream_params param =
366- {
367- .format = sample_size == AudioSampleSize::S16 ? CUBEB_SAMPLE_S16NE : CUBEB_SAMPLE_FLOAT32NE,
368- .rate = static_cast <u32 >(freq),
369- .channels = static_cast <u32 >(ch_cnt),
370- .layout = CUBEB_LAYOUT_UNDEFINED,
371- .prefs = CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING
372- };
373-
374- u32 min_latency{};
375- if (int err = cubeb_get_min_latency (m_ctx, ¶m, &min_latency))
376- {
377- Cubeb.error (" cubeb_get_min_latency() failed: %i" , err);
378- min_latency = 100 ;
379- }
380-
381- cubeb_stream* tmp_stream{};
382- static auto dummy_data_cb = [](cubeb_stream*, void *, void const *, void *, long ) -> long { return 0 ; };
383- static auto dummy_state_cb = [](cubeb_stream*, void *, cubeb_state) {};
384-
385- if (int err = cubeb_stream_init (m_ctx, &tmp_stream, " Default device detector" , nullptr , nullptr , nullptr , ¶m, min_latency, dummy_data_cb, dummy_state_cb, nullptr ))
386- {
387- Cubeb.error (" cubeb_stream_init() failed: %i" , err);
388- return {};
389- }
390-
391- cubeb_device* crnt_dev{};
392-
393- if (int err = cubeb_stream_get_current_device (tmp_stream, &crnt_dev); err != CUBEB_OK || !crnt_dev)
394- {
395- Cubeb.error (" cubeb_stream_get_current_device() failed: err=%i, crnt_dev=%d" , err, !!crnt_dev);
396- cubeb_stream_destroy (tmp_stream);
397- return {};
398- }
399-
400- std::string out_dev_name;
401-
402- if (crnt_dev->output_name )
403- {
404- out_dev_name = crnt_dev->output_name ;
405- }
406-
407- if (int err = cubeb_stream_device_destroy (tmp_stream, crnt_dev))
408- {
409- Cubeb.error (" cubeb_stream_device_destroy() failed: %i" , err);
410- }
411-
412- cubeb_stream_destroy (tmp_stream);
413-
414- if (out_dev_name.empty ())
415- {
416- Cubeb.notice (" No default device available" );
417- return {};
418- }
419-
420- return GetDevice (out_dev_name);
421- }
422-
423345long CubebBackend::data_cb (cubeb_stream* stream, void * user_ptr, void const * /* input_buffer */ , void * output_buffer, long nframes)
424346{
425347 if (nframes <= 0 )
0 commit comments