///////////////////////////////////////////////////////
| 161 | |
| 162 | //////////////////////////////////////////////////////////// |
| 163 | SoundRecorder::SoundRecorder() : m_impl(std::make_unique<Impl>(this)) |
| 164 | { |
| 165 | // Create the log |
| 166 | m_impl->log.emplace(); |
| 167 | |
| 168 | if (const auto result = ma_log_init(nullptr, &*m_impl->log); result != MA_SUCCESS) |
| 169 | { |
| 170 | m_impl->log.reset(); |
| 171 | err() << "Failed to initialize the audio log: " << ma_result_description(result) << std::endl; |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | // Register our logging callback to output any warning/error messages |
| 176 | if (const auto result = ma_log_register_callback(&*m_impl->log, |
| 177 | ma_log_callback_init( |
| 178 | [](void*, std::uint32_t level, const char* message) |
| 179 | { |
| 180 | if (level <= MA_LOG_LEVEL_WARNING) |
| 181 | err() << "miniaudio " << ma_log_level_to_string(level) |
| 182 | << ": " << message << std::flush; |
| 183 | }, |
| 184 | nullptr)); |
| 185 | result != MA_SUCCESS) |
| 186 | err() << "Failed to register audio log callback: " << ma_result_description(result) << std::endl; |
| 187 | |
| 188 | // Create the context |
| 189 | m_impl->context.emplace(); |
| 190 | |
| 191 | auto contextConfig = ma_context_config_init(); |
| 192 | contextConfig.pLog = &*m_impl->log; |
| 193 | std::uint32_t deviceCount = 0; |
| 194 | const auto nullBackend = ma_backend_null; |
| 195 | const std::array<const ma_backend*, 2> backendLists{nullptr, &nullBackend}; |
| 196 | |
| 197 | for (const auto* backendList : backendLists) |
| 198 | { |
| 199 | // We can set backendCount to 1 since it is ignored when backends is set to nullptr |
| 200 | if (const auto result = ma_context_init(backendList, 1, &contextConfig, &*m_impl->context); result != MA_SUCCESS) |
| 201 | { |
| 202 | m_impl->context.reset(); |
| 203 | err() << "Failed to initialize the audio capture context: " << ma_result_description(result) << std::endl; |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | // Count the capture devices |
| 208 | if (const auto result = ma_context_get_devices(&*m_impl->context, nullptr, nullptr, nullptr, &deviceCount); |
| 209 | result != MA_SUCCESS) |
| 210 | { |
| 211 | err() << "Failed to get audio capture devices: " << ma_result_description(result) << std::endl; |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | // Check if there are audio capture devices available on the system |
| 216 | if (deviceCount > 0) |
| 217 | break; |
| 218 | |
| 219 | // Warn if no devices were found using the default backend list |
| 220 | if (backendList == nullptr) |
nothing calls this directly
no test coverage detected