MCPcopy Create free account
hub / github.com/SFML/SFML / Reverb

Method Reverb

examples/sound_effects/SoundEffects.cpp:923–965  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

921{
922public:
923 Reverb() : Processing("Reverb")
924 {
925 auto& music = getMusic();
926
927 static constexpr auto sustain = 0.7f; // [0.f; 1.f]
928
929 // We use a mutable lambda to tie the lifetime of the state to the lambda itself
930 // This is necessary since the Echo object will be destroyed before the Music object
931 // While the Music object exists, it is possible that the audio engine will try to call
932 // this lambda hence we need to always have a usable state until the Music and the
933 // associated lambda are destroyed
934 music.setEffectProcessor(
935 [sampleRate = sf::PlaybackDevice::getDeviceSampleRate().value_or(44100),
936 filters = std::vector<ReverbFilter<float>>(),
937 enabled = getEnabled()](const float* inputFrames,
938 unsigned int& inputFrameCount,
939 float* outputFrames,
940 unsigned int& outputFrameCount,
941 unsigned int frameChannelCount) mutable
942 {
943 // IMPORTANT: The channel count of the audio engine currently sourcing data from this sound
944 // will always be provided in frameChannelCount, this can be different from the channel count
945 // of the audio source so make sure to size your buffers according to the engine and not the source
946 // Ensure we have as many filter objects as the audio engine has channels
947 while (filters.size() < frameChannelCount)
948 filters.emplace_back(sampleRate, sustain);
949
950 for (auto frame = 0u; frame < outputFrameCount; ++frame)
951 {
952 for (auto channel = 0u; channel < frameChannelCount; ++channel)
953 {
954 const auto input = inputFrames ? inputFrames[channel] : 0.f; // Read silence if no input data available
955 outputFrames[channel] = *enabled ? filters[channel](input) : input;
956 }
957
958 inputFrames += (inputFrames ? frameChannelCount : 0u);
959 outputFrames += frameChannelCount;
960 }
961
962 // We processed data 1:1
963 inputFrameCount = outputFrameCount;
964 });
965 }
966
967private:
968 template <typename T>

Callers

nothing calls this directly

Calls 2

getDeviceSampleRateFunction · 0.85
setEffectProcessorMethod · 0.45

Tested by

no test coverage detected