Skip to content

Commit

Permalink
Make sure easter egg value is >0.
Browse files Browse the repository at this point in the history
Gaussian distribution requires the sigma value to be >0. If the value is too small, we just use the default 1.0 value.
  • Loading branch information
kblaschke committed Feb 15, 2024
1 parent 1477664 commit d6b6446
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/api/include/projectM-4/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ PROJECTM_EXPORT bool projectm_get_aspect_correction(projectm_handle instance);
* <p>See function sampledPresetDuration() of the TimeKeeper class on how it is used.</p>
*
* @param instance The projectM instance handle.
* @param value The new "easter egg" value.
* @param value The new "easter egg" value. Must be greater than zero, otherwise a default sigma value of 1.0 will be used.
*/
PROJECTM_EXPORT void projectm_set_easter_egg(projectm_handle instance, float value);

Expand Down
2 changes: 1 addition & 1 deletion src/libprojectM/ProjectM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class PROJECTM_EXPORT ProjectM
float m_hardCutSensitivity{2.0}; //!< Loudness sensitivity value for hard cuts.
float m_beatSensitivity{1.0}; //!< General beat sensitivity modifier for presets.
bool m_aspectCorrection{true}; //!< If true, corrects aspect ratio for non-rectangular windows.
float m_easterEgg{0.0}; //!< Random preset duration modifier. See TimeKeeper class.
float m_easterEgg{1.0}; //!< Random preset duration modifier. See TimeKeeper class.
float m_previousFrameVolume{}; //!< Volume in previous frame, used for hard cuts.

std::vector<std::string> m_textureSearchPaths; ///!< List of paths to search for texture files
Expand Down
8 changes: 7 additions & 1 deletion src/libprojectM/TimeKeeper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "TimeKeeper.hpp"

#include <algorithm>
#include <random>

namespace libprojectM {

Expand Down Expand Up @@ -105,7 +106,12 @@ double TimeKeeper::PresetTimeA()

double TimeKeeper::sampledPresetDuration()
{
std::normal_distribution<double> gaussianDistribution{m_presetDuration, m_easterEgg};
if (m_easterEgg < 0.001)
{
return m_presetDuration;
}

std::normal_distribution<double> gaussianDistribution(m_presetDuration, m_easterEgg);
return std::max<double>(1.0, gaussianDistribution(m_randomGenerator));
}

Expand Down

0 comments on commit d6b6446

Please sign in to comment.