Player: limit maximum frequency depending to rate

This commit is contained in:
Louis-Joseph Fournier 2016-01-14 19:56:24 +01:00
parent f143dcbb3d
commit 8178009eb5
2 changed files with 5 additions and 1 deletions

View file

@ -27,6 +27,7 @@ template<typename sample_t> FreqPlayer<sample_t>::FreqPlayer(int _rate):
{ {
k = K(); k = K();
k_update = -1; // invalid: don't update k_update = -1; // invalid: don't update
max_harmonic_freq = rate / 2;
} }
template<typename sample_t> void FreqPlayer<sample_t>::Reset() template<typename sample_t> void FreqPlayer<sample_t>::Reset()
@ -92,7 +93,8 @@ template<typename sample_t> sample_t FreqPlayer<sample_t>::AudioFrame()
case W_HARMONIC: case W_HARMONIC:
v = 0; v = 0;
for (i = 1; i <= nb_harmonics; i++) v += sin(r * i) / i; for (i = 1; i <= nb_harmonics; i++) if (freq * i < max_harmonic_freq)
v += sin(r * i) / i;
break; break;
default: default:

View file

@ -46,6 +46,8 @@ template<typename sample_t> class FreqPlayer {
sample_t last_frame; sample_t last_frame;
/// number of hamonics for waveforms (W_HARMONIC only) /// number of hamonics for waveforms (W_HARMONIC only)
int nb_harmonics = 5; int nb_harmonics = 5;
/// max harmonic to play given current frequency
double max_harmonic_freq;
/// return k computed /// return k computed
double K() const; double K() const;