Преглед изворни кода

Never allow freq modulation to attempt higher than Nyquist

dds
PaulStoffregen пре 6 година
родитељ
комит
2244781c1c
2 измењених фајлова са 15 додато и 4 уклоњено
  1. +12
    -2
      synth_waveform.cpp
  2. +3
    -2
      synth_waveform.h

+ 12
- 2
synth_waveform.cpp Прегледај датотеку

@@ -30,6 +30,10 @@
#include "utility/dspinst.h"


// uncomment for more accurate but more computationally expensive frequency modulation
//#define IMPROVE_EXPONENTIAL_ACCURACY


void AudioSynthWaveform::update(void)
{
audio_block_t *block;
@@ -213,6 +217,7 @@ void AudioSynthWaveformModulated::update(void)
n = multiply_accumulate_32x32_rshift32_rounded(n, sq, 1934101615);
n = n + (multiply_32x32_rshift32_rounded(sq,
multiply_32x32_rshift32_rounded(x, 1358044250)) << 1);
n = n << 1;
#else
// exp2 algorithm by Laurent de Soras
// http://www.musicdsp.org/showone.php?id=106
@@ -222,8 +227,13 @@ void AudioSynthWaveformModulated::update(void)
n = n + 715827882;
#endif
uint32_t scale = n >> (14 - ipart);
uint32_t phinc = ((uint64_t)inc * scale) >> 16; // TODO: saturate 31 bits??
ph += phinc;
uint64_t phstep = (uint64_t)inc * scale;
uint32_t phstep_msw = phstep >> 32;
if (phstep_msw < 0x7FFE) {
ph += phstep >> 16;
} else {
ph += 0x7FFE0000;
}
phasedata[i] = ph;
}
release(moddata);

+ 3
- 2
synth_waveform.h Прегледај датотеку

@@ -64,6 +64,7 @@ public:
freq = AUDIO_SAMPLE_RATE_EXACT / 2;
}
phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT);
if (phase_increment > 0x7FFE0000u) phase_increment = 0x7FFE0000;
}
void phase(float angle) {
if (angle < 0.0) {
@@ -131,7 +132,7 @@ class AudioSynthWaveformModulated : public AudioStream
public:
AudioSynthWaveformModulated(void) : AudioStream(2, inputQueueArray),
phase_accumulator(0), phase_increment(0), modulation_factor(32768),
magnitude(0), arbdata(NULL), priorphase(0), sample(0), tone_offset(0),
magnitude(0), arbdata(NULL), sample(0), tone_offset(0),
tone_type(WAVEFORM_SINE), modulation_type(0) {
}

@@ -142,6 +143,7 @@ public:
freq = AUDIO_SAMPLE_RATE_EXACT / 2;
}
phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT);
if (phase_increment > 0x7FFE0000u) phase_increment = 0x7FFE0000;
}
void amplitude(float n) { // 0 to 1.0
if (n < 0) {
@@ -198,7 +200,6 @@ private:
int32_t magnitude;
const int16_t *arbdata;
uint32_t phasedata[AUDIO_BLOCK_SAMPLES];
uint32_t priorphase;
int16_t sample; // for WAVEFORM_SAMPLE_HOLD
int16_t tone_offset;
uint8_t tone_type;

Loading…
Откажи
Сачувај