Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for user defined sound effect implementations. #2973

Merged
merged 1 commit into from May 17, 2024

Conversation

binary1248
Copy link
Member

Title.

Because I found it a pity that #1708 had to be closed due to the miniaudio rewrite and all of @fallahn's work gone to waste, I went ahead and implemented equivalent (maybe even better?) support for user defined sound effects in the spirit of aforementioned PR.

The example has been accordingly extended with demonstrations of how to use the new API to implement basically any effect one can think of. I am by no means a DSP expert (the example implementations were taken from people far more knowledgeable than me 馃榿), so maybe someone can improve the example processing code or even add more interesting effects.

All of the action happens when an effect processor is attached to an sf::SoundSource using:

using EffectProcessor = std::function<void(const float*, unsigned int&, float*, unsigned int&, unsigned int)>;

void setEffectProcessor(EffectProcessor effectProcessor);

The effect processor is passed the raw audio data from the engine and can manipulate it before sending it back to be output through the audio device. Refer to the sf::SoundSource documentation and sound effects example for detailed information on API usage.

@ChrisThrasher
Copy link
Member

Is there anything we can do to reduce the code duplication between Sound.cpp and SoundStream.cpp?

@coveralls
Copy link
Collaborator

coveralls commented May 4, 2024

Pull Request Test Coverage Report for Build 9122177114

Details

  • 80 of 130 (61.54%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 55.481%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/SFML/Audio/Sound.cpp 40 65 61.54%
src/SFML/Audio/SoundStream.cpp 40 65 61.54%
Totals Coverage Status
Change from base Build 9119260362: 0.02%
Covered Lines: 11502
Relevant Lines: 19622

馃挍 - Coveralls

@binary1248
Copy link
Member Author

Is there anything we can do to reduce the code duplication between Sound.cpp and SoundStream.cpp?

Not really... most of the duplicated code references internal members of Impl and since Impl is local to each TU trying to refactor out those blocks would just make the code unnecessarily more complex.

@binary1248
Copy link
Member Author

Rebased onto master.

Copy link
Member

@vittorioromeo vittorioromeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nitpicks

examples/sound_effects/SoundEffects.cpp Outdated Show resolved Hide resolved
examples/sound_effects/SoundEffects.cpp Outdated Show resolved Hide resolved
include/SFML/Audio/SoundSource.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundStream.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundStream.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundStream.cpp Outdated Show resolved Hide resolved
@binary1248
Copy link
Member Author

Updated with @vittorioromeo's suggestions.

@binary1248 binary1248 force-pushed the feature/sound_effects branch 2 times, most recently from c51d7fb to 497a453 Compare May 16, 2024 15:33
@ChrisThrasher
Copy link
Member

Rebased on master to inherit the new Audio module tests

@ChrisThrasher ChrisThrasher force-pushed the feature/sound_effects branch 2 times, most recently from 615dca9 to 37402db Compare May 17, 2024 02:35
@ChrisThrasher ChrisThrasher enabled auto-merge (rebase) May 17, 2024 02:59
@ChrisThrasher ChrisThrasher merged commit 002b895 into master May 17, 2024
205 checks passed
@eXpl0it3r eXpl0it3r deleted the feature/sound_effects branch May 17, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants