Browse Source

Add amplitude() to AudioSynthWaveformSine

dds
PaulStoffregen 10 years ago
parent
commit
7142f4c47d
3 changed files with 20 additions and 6 deletions
  1. +2
    -0
      keywords.txt
  2. +4
    -2
      synth_sine.cpp
  3. +14
    -4
      synth_sine.h

+ 2
- 0
keywords.txt View File

AudioPlaySdWav KEYWORD2 AudioPlaySdWav KEYWORD2
AudioSynthToneSweep KEYWORD2 AudioSynthToneSweep KEYWORD2
AudioSynthWaveform KEYWORD2 AudioSynthWaveform KEYWORD2
AudioSynthWaveformSine KEYWORD2
AudioSynthWaveformSineModulated KEYWORD2
isPlaying KEYWORD2 isPlaying KEYWORD2
positionMillis KEYWORD2 positionMillis KEYWORD2
lengthMillis KEYWORD2 lengthMillis KEYWORD2

+ 4
- 2
synth_sine.cpp View File

scale = (ph >> 8) & 0xFFFF; scale = (ph >> 8) & 0xFFFF;
val2 *= scale; val2 *= scale;
val1 *= 0xFFFF - scale; val1 *= 0xFFFF - scale;
block->data[i] = (val1 + val2) >> 16;
//block->data[i] = (((val1 + val2) >> 16) * magnitude) >> 16;
block->data[i] = multiply_32x32_rshift32(val1 + val2, magnitude);
ph += inc; ph += inc;
} }
phase = ph; phase = ph;
scale = (ph >> 8) & 0xFFFF; scale = (ph >> 8) & 0xFFFF;
val2 *= scale; val2 *= scale;
val1 *= 0xFFFF - scale; val1 *= 0xFFFF - scale;
block->data[i] = (val1 + val2) >> 16;
//block->data[i] = (((val1 + val2) >> 16) * magnitude) >> 16;
block->data[i] = multiply_32x32_rshift32(val1 + val2, magnitude);
// -32768 = no phase increment // -32768 = no phase increment
// 32767 = double phase increment // 32767 = double phase increment
mod = modinput->data[i]; mod = modinput->data[i];

+ 14
- 4
synth_sine.h View File

class AudioSynthWaveformSine : public AudioStream class AudioSynthWaveformSine : public AudioStream
{ {
public: public:
AudioSynthWaveformSine() : AudioStream(0, NULL) {}
AudioSynthWaveformSine() : AudioStream(0, NULL), magnitude(16384) {}
void frequency(float freq); void frequency(float freq);
//void amplitude(q15 n);
void amplitude(float n) {
if (n < 0) n = 0;
else if (n > 1.0) n = 1.0;
magnitude = n * 65536.0;
}
virtual void update(void); virtual void update(void);
private: private:
uint32_t phase; uint32_t phase;
uint32_t phase_increment; uint32_t phase_increment;
int32_t magnitude;
}; };


class AudioSynthWaveformSineModulated : public AudioStream class AudioSynthWaveformSineModulated : public AudioStream
{ {
public: public:
AudioSynthWaveformSineModulated() : AudioStream(1, inputQueueArray) {}
AudioSynthWaveformSineModulated() : AudioStream(1, inputQueueArray), magnitude(16384) {}
void frequency(float freq); void frequency(float freq);
//void amplitude(q15 n);
void amplitude(float n) {
if (n < 0) n = 0;
else if (n > 1.0) n = 1.0;
magnitude = n * 65536.0;
}
virtual void update(void); virtual void update(void);
private: private:
uint32_t phase; uint32_t phase;
uint32_t phase_increment; uint32_t phase_increment;
audio_block_t *inputQueueArray[1]; audio_block_t *inputQueueArray[1];
int32_t magnitude;
}; };





Loading…
Cancel
Save