* @brief Constructs the Audio driver and initializes the MiniAudio backend; * configureInput/configureOutput sync m_config at the end, so no separate * sync call is needed here. */
| 289 | * sync call is needed here. |
| 290 | */ |
| 291 | IO::Drivers::Audio::Audio() |
| 292 | : m_init(false) |
| 293 | , m_isOpen(false) |
| 294 | , m_selectedSampleRate(0) |
| 295 | , m_selectedInputDevice(-1) |
| 296 | , m_selectedInputSampleFormat(0) |
| 297 | , m_selectedInputChannelConfiguration(0) |
| 298 | , m_selectedOutputDevice(-1) |
| 299 | , m_selectedOutputSampleFormat(0) |
| 300 | , m_selectedOutputChannelConfiguration(0) |
| 301 | , m_inputQueue(kAudioQueueCapacity) |
| 302 | , m_outputQueue(kAudioQueueCapacity) |
| 303 | , m_inputWorkerTimer(nullptr) |
| 304 | , m_sampleClockValid(false) |
| 305 | , m_rtCaptureFormat(ma_format_unknown) |
| 306 | , m_rtPlaybackFormat(ma_format_unknown) |
| 307 | , m_rtCaptureChannels(0) |
| 308 | , m_rtPlaybackChannels(0) |
| 309 | { |
| 310 | #if defined(Q_OS_WIN) |
| 311 | ma_backend backend[] = {ma_backend_wasapi}; |
| 312 | #elif defined(Q_OS_APPLE) |
| 313 | ma_backend backend[] = {ma_backend_coreaudio}; |
| 314 | #elif defined(Q_OS_LINUX) |
| 315 | ma_backend backend[] = {ma_backend_alsa}; |
| 316 | #else |
| 317 | # error "Unsupported platform" |
| 318 | #endif |
| 319 | |
| 320 | m_config = ma_device_config_init(ma_device_type_duplex); |
| 321 | m_init = ma_context_init(backend, 1, nullptr, &m_context) == MA_SUCCESS; |
| 322 | if (!m_init) |
| 323 | qWarning("Failed to initialize miniaudio context"); |
| 324 | |
| 325 | m_csvData.reserve(96 * 1024); |
| 326 | m_csvBuffer.setBuffer(&m_csvData); |
| 327 | m_csvBuffer.open(QIODevice::WriteOnly); |
| 328 | |
| 329 | m_csvStream.setRealNumberPrecision(6); |
| 330 | m_csvStream.setDevice(&m_csvBuffer); |
| 331 | m_csvStream.setRealNumberNotation(QTextStream::FixedNotation); |
| 332 | |
| 333 | generateLists(); |
| 334 | refreshAudioDevices(); |
| 335 | |
| 336 | restoreSettings(); |
| 337 | configureInput(); |
| 338 | configureOutput(); |
| 339 | |
| 340 | connect(&Misc::TimerEvents::instance(), |
| 341 | &Misc::TimerEvents::timeout1Hz, |
| 342 | this, |
| 343 | &Audio::refreshAudioDevices); |
| 344 | |
| 345 | connect(&Misc::Translator::instance(), |
| 346 | &Misc::Translator::languageChanged, |
| 347 | this, |
| 348 | &IO::Drivers::Audio::generateLists); |