ソースを参照

Add amplitude() to AudioSynthWaveformSine

dds
PaulStoffregen 10年前
コミット
7142f4c47d
3個のファイルの変更20行の追加6行の削除
  1. +2
    -0
      keywords.txt
  2. +4
    -2
      synth_sine.cpp
  3. +14
    -4
      synth_sine.h

+ 2
- 0
keywords.txt ファイルの表示

@@ -23,6 +23,8 @@ AudioPlaySdRaw KEYWORD2
AudioPlaySdWav KEYWORD2
AudioSynthToneSweep KEYWORD2
AudioSynthWaveform KEYWORD2
AudioSynthWaveformSine KEYWORD2
AudioSynthWaveformSineModulated KEYWORD2
isPlaying KEYWORD2
positionMillis KEYWORD2
lengthMillis KEYWORD2

+ 4
- 2
synth_sine.cpp ファイルの表示

@@ -57,7 +57,8 @@ void AudioSynthWaveformSine::update(void)
scale = (ph >> 8) & 0xFFFF;
val2 *= 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;
}
phase = ph;
@@ -114,7 +115,8 @@ void AudioSynthWaveformSineModulated::update(void)
scale = (ph >> 8) & 0xFFFF;
val2 *= 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
// 32767 = double phase increment
mod = modinput->data[i];

+ 14
- 4
synth_sine.h ファイルの表示

@@ -30,26 +30,36 @@
class AudioSynthWaveformSine : public AudioStream
{
public:
AudioSynthWaveformSine() : AudioStream(0, NULL) {}
AudioSynthWaveformSine() : AudioStream(0, NULL), magnitude(16384) {}
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);
private:
uint32_t phase;
uint32_t phase_increment;
int32_t magnitude;
};

class AudioSynthWaveformSineModulated : public AudioStream
{
public:
AudioSynthWaveformSineModulated() : AudioStream(1, inputQueueArray) {}
AudioSynthWaveformSineModulated() : AudioStream(1, inputQueueArray), magnitude(16384) {}
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);
private:
uint32_t phase;
uint32_t phase_increment;
audio_block_t *inputQueueArray[1];
int32_t magnitude;
};



読み込み中…
キャンセル
保存