8000 Add simple GUI for sound capture example by JonnyPtn · Pull Request #3624 · SFML/SFML · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@JonnyPtn
Copy link
Contributor

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

image

@eXpl0it3r eXpl0it3r added this to the 3.1 milestone Dec 17, 2025
@github-project-automation github-project-automation bot moved this to Planned in SFML 3.1.0 Dec 17, 2025
@eXpl0it3r eXpl0it3r moved this from Planned to In Review in SFML 3.1.0 Dec 17, 2025
Copy link
Member
@eXpl0it3r eXpl0it3r left a 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;
Copy link
Member

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;
Copy link
Member

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");
Copy link
Member

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());
Copy link
Member

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>();
Copy link
Member

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}))
Copy link
Member

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)

@eXpl0it3r eXpl0it3r removed this from SFML 3.1.0 Jan 20, 2026
@github-project-automation github-project-automation bot moved this to Planned in SFML 3.2.0 Jan 20, 2026
@eXpl0it3r eXpl0it3r modified the milestones: 3.1, 3.2 Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Planned

Development

Successfully merging this pull request may close these issues.

2 participants

0