-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add simple GUI for sound capture example #3624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
bf7451c to
9d44cd7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small suggestions
| if (!sf::SoundRecorder::isAvailable()) | ||
| { | ||
| std::cout << "Sorry, audio capture is not supported by your system" << std::endl; | ||
| sf::err() << "Sorry, audio capture is not supported by your system" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sf::err() should generally speaking only be used by SFML itself
| const auto devices = sf::SoundRecorder::getAvailableDevices(); | ||
| if (devices.empty()) | ||
| { | ||
| sf::err() << "No sound recording devices available" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, either std::cout or std::cerr
| } | ||
|
|
||
| std::cout << "Available capture devices:\n" << std::endl; | ||
| sf::RenderWindow window(sf::VideoMode({800, 600}), "Sound capture example"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could enable anti-aliasing
|
|
||
| // Audio capture is done in a separate thread, so we can block the main thread while it is capturing | ||
| if (!recorder.start(sampleRate)) | ||
| assert(index < devices.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do asserts in an example make sense?
| // Display the playing position | ||
| std::cout << "\rPlaying... " << sound.getPlayingOffset().asSeconds() << " sec "; | ||
| std::cout << std::flush; | ||
| if (const auto* clickEvent = event->getIf<sf::Event::MouseButtonPressed>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider MouseButtonReleased instead
| // Check if a device is selected | ||
| for (auto i = 0u; i < devices.size(); ++i) | ||
| { | ||
| if (deviceTexts[i].getGlobalBounds().contains(sf::Vector2f{clickEvent->position})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transform the mouse position once at the start with window.mapCoordsToPixel(clientEvent->position)
0394846 to
187deeb
Compare
Current example is command line based which is no good for non-desktop platforms, this adds a simple GUI
Will help in testing/implementing sound capture on mobile devices (see #630)
Have lost the ability to specify a custom sample rate, and to save to a file, which I felt added more complexity than they are worth for the purposes of this example, but can add something for them if desired