/////////////////////////////////////////////////////// Entry point of application \return Application exit code ///////////////////////////////////////////////////////
| 15 | /// |
| 16 | //////////////////////////////////////////////////////////// |
| 17 | int main() |
| 18 | { |
| 19 | // Check that the device can capture audio |
| 20 | if (!sf::SoundRecorder::isAvailable()) |
| 21 | { |
| 22 | std::cout << "Sorry, audio capture is not supported by your system" << std::endl; |
| 23 | return EXIT_SUCCESS; |
| 24 | } |
| 25 | |
| 26 | // List the available capture devices |
| 27 | auto devices = sf::SoundRecorder::getAvailableDevices(); |
| 28 | |
| 29 | std::cout << "Available capture devices:\n" << std::endl; |
| 30 | |
| 31 | for (auto i = 0u; i < devices.size(); ++i) |
| 32 | std::cout << i << ": " << devices[i] << '\n'; |
| 33 | |
| 34 | std::cout << std::endl; |
| 35 | |
| 36 | std::size_t deviceIndex = 0; |
| 37 | |
| 38 | // Choose the capture device |
| 39 | if (devices.size() > 1) |
| 40 | { |
| 41 | deviceIndex = devices.size(); |
| 42 | std::cout << "Please choose the capture device to use [0-" << devices.size() - 1 << "]: "; |
| 43 | do |
| 44 | { |
| 45 | std::cin >> deviceIndex; |
| 46 | std::cin.ignore(10'000, '\n'); |
| 47 | } while (deviceIndex >= devices.size()); |
| 48 | } |
| 49 | |
| 50 | // Choose the sample rate |
| 51 | unsigned int sampleRate = 0; |
| 52 | std::cout << "Please choose the sample rate for sound capture (44100 is CD quality): "; |
| 53 | std::cin >> sampleRate; |
| 54 | std::cin.ignore(10'000, '\n'); |
| 55 | |
| 56 | // Wait for user input... |
| 57 | std::cout << "Press enter to start recording audio"; |
| 58 | std::cin.ignore(10'000, '\n'); |
| 59 | |
| 60 | // Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer |
| 61 | sf::SoundBufferRecorder recorder; |
| 62 | |
| 63 | if (!recorder.setDevice(devices[deviceIndex])) |
| 64 | { |
| 65 | std::cerr << "Failed to set the capture device" << std::endl; |
| 66 | return EXIT_FAILURE; |
| 67 | } |
| 68 | |
| 69 | // Audio capture is done in a separate thread, so we can block the main thread while it is capturing |
| 70 | if (!recorder.start(sampleRate)) |
| 71 | { |
| 72 | std::cerr << "Failed to start recorder" << std::endl; |
| 73 | return EXIT_FAILURE; |
| 74 | } |
nothing calls this directly
no test coverage detected