Przeglądaj źródła

Never allow freq modulation to attempt higher than Nyquist

dds
PaulStoffregen 6 lat temu
rodzic
commit
2244781c1c
2 zmienionych plików z 15 dodań i 4 usunięć
  1. +12
    -2
      synth_waveform.cpp
  2. +3
    -2
      synth_waveform.h

+ 12
- 2
synth_waveform.cpp Wyświetl plik

#include "utility/dspinst.h" #include "utility/dspinst.h"




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


void AudioSynthWaveform::update(void) void AudioSynthWaveform::update(void)
{ {
audio_block_t *block; audio_block_t *block;
n = multiply_accumulate_32x32_rshift32_rounded(n, sq, 1934101615); n = multiply_accumulate_32x32_rshift32_rounded(n, sq, 1934101615);
n = n + (multiply_32x32_rshift32_rounded(sq, n = n + (multiply_32x32_rshift32_rounded(sq,
multiply_32x32_rshift32_rounded(x, 1358044250)) << 1); multiply_32x32_rshift32_rounded(x, 1358044250)) << 1);
n = n << 1;
#else #else
// exp2 algorithm by Laurent de Soras // exp2 algorithm by Laurent de Soras
// http://www.musicdsp.org/showone.php?id=106 // http://www.musicdsp.org/showone.php?id=106
n = n + 715827882; n = n + 715827882;
#endif #endif
uint32_t scale = n >> (14 - ipart); 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; phasedata[i] = ph;
} }
release(moddata); release(moddata);

+ 3
- 2
synth_waveform.h Wyświetl plik

freq = AUDIO_SAMPLE_RATE_EXACT / 2; freq = AUDIO_SAMPLE_RATE_EXACT / 2;
} }
phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT); phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT);
if (phase_increment > 0x7FFE0000u) phase_increment = 0x7FFE0000;
} }
void phase(float angle) { void phase(float angle) {
if (angle < 0.0) { if (angle < 0.0) {
public: public:
AudioSynthWaveformModulated(void) : AudioStream(2, inputQueueArray), AudioSynthWaveformModulated(void) : AudioStream(2, inputQueueArray),
phase_accumulator(0), phase_increment(0), modulation_factor(32768), 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) { tone_type(WAVEFORM_SINE), modulation_type(0) {
} }


freq = AUDIO_SAMPLE_RATE_EXACT / 2; freq = AUDIO_SAMPLE_RATE_EXACT / 2;
} }
phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT); phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT);
if (phase_increment > 0x7FFE0000u) phase_increment = 0x7FFE0000;
} }
void amplitude(float n) { // 0 to 1.0 void amplitude(float n) { // 0 to 1.0
if (n < 0) { if (n < 0) {
int32_t magnitude; int32_t magnitude;
const int16_t *arbdata; const int16_t *arbdata;
uint32_t phasedata[AUDIO_BLOCK_SAMPLES]; uint32_t phasedata[AUDIO_BLOCK_SAMPLES];
uint32_t priorphase;
int16_t sample; // for WAVEFORM_SAMPLE_HOLD int16_t sample; // for WAVEFORM_SAMPLE_HOLD
int16_t tone_offset; int16_t tone_offset;
uint8_t tone_type; uint8_t tone_type;

Ładowanie…
Anuluj
Zapisz