|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const int16_t sine_table[] = { |
|
|
|
|
|
0, 804, 1608, 2410, 3212, 4011, 4808, 5602, 6393, 7179, |
|
|
|
|
|
7962, 8739, 9512, 10278, 11039, 11793, 12539, 13279, 14010, 14732, |
|
|
|
|
|
15446, 16151, 16846, 17530, 18204, 18868, 19519, 20159, 20787, 21403, |
|
|
|
|
|
22005, 22594, 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790, |
|
|
|
|
|
27245, 27683, 28105, 28510, 28898, 29268, 29621, 29956, 30273, 30571, |
|
|
|
|
|
30852, 31113, 31356, 31580, 31785, 31971, 32137, 32285, 32412, 32521, |
|
|
|
|
|
32609, 32678, 32728, 32757, 32767, 32757, 32728, 32678, 32609, 32521, |
|
|
|
|
|
32412, 32285, 32137, 31971, 31785, 31580, 31356, 31113, 30852, 30571, |
|
|
|
|
|
30273, 29956, 29621, 29268, 28898, 28510, 28105, 27683, 27245, 26790, |
|
|
|
|
|
26319, 25832, 25329, 24811, 24279, 23731, 23170, 22594, 22005, 21403, |
|
|
|
|
|
20787, 20159, 19519, 18868, 18204, 17530, 16846, 16151, 15446, 14732, |
|
|
|
|
|
14010, 13279, 12539, 11793, 11039, 10278, 9512, 8739, 7962, 7179, |
|
|
|
|
|
6393, 5602, 4808, 4011, 3212, 2410, 1608, 804, 0, -804, |
|
|
|
|
|
-1608, -2410, -3212, -4011, -4808, -5602, -6393, -7179, -7962, -8739, |
|
|
|
|
|
-9512,-10278,-11039,-11793,-12539,-13279,-14010,-14732,-15446,-16151, |
|
|
|
|
|
-16846,-17530,-18204,-18868,-19519,-20159,-20787,-21403,-22005,-22594, |
|
|
|
|
|
-23170,-23731,-24279,-24811,-25329,-25832,-26319,-26790,-27245,-27683, |
|
|
|
|
|
-28105,-28510,-28898,-29268,-29621,-29956,-30273,-30571,-30852,-31113, |
|
|
|
|
|
-31356,-31580,-31785,-31971,-32137,-32285,-32412,-32521,-32609,-32678, |
|
|
|
|
|
-32728,-32757,-32767,-32757,-32728,-32678,-32609,-32521,-32412,-32285, |
|
|
|
|
|
-32137,-31971,-31785,-31580,-31356,-31113,-30852,-30571,-30273,-29956, |
|
|
|
|
|
-29621,-29268,-28898,-28510,-28105,-27683,-27245,-26790,-26319,-25832, |
|
|
|
|
|
-25329,-24811,-24279,-23731,-23170,-22594,-22005,-21403,-20787,-20159, |
|
|
|
|
|
-19519,-18868,-18204,-17530,-16846,-16151,-15446,-14732,-14010,-13279, |
|
|
|
|
|
-12539,-11793,-11039,-10278, -9512, -8739, -7962, -7179, -6393, -5602, |
|
|
|
|
|
-4808, -4011, -3212, -2410, -1608, -804, 0 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioSineWave::frequency(float f) |
|
|
|
|
|
{ |
|
|
|
|
|
if (f > AUDIO_SAMPLE_RATE_EXACT / 2 || f < 0.0) return; |
|
|
|
|
|
phase_increment = (f / AUDIO_SAMPLE_RATE_EXACT) * 4294967296.0f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void AudioSineWave::update(void) |
|
|
|
|
|
|
|
|
void AudioSynthWaveform::update(void) |
|
|
{ |
|
|
{ |
|
|
audio_block_t *block; |
|
|
audio_block_t *block; |
|
|
uint32_t i, ph, inc, index, scale; |
|
|
uint32_t i, ph, inc, index, scale; |
|
|
int32_t val1, val2, val3; |
|
|
int32_t val1, val2, val3; |
|
|
|
|
|
|
|
|
//Serial.println("AudioSineWave::update"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Serial.println("AudioSynthWaveform::update"); |
|
|
if (magnitude > 0 && (block = allocate()) != NULL) { |
|
|
if (magnitude > 0 && (block = allocate()) != NULL) { |
|
|
ph = phase; |
|
|
ph = phase; |
|
|
inc = phase_increment; |
|
|
inc = phase_increment; |
|
|
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) { |
|
|
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) { |
|
|
index = ph >> 24; |
|
|
index = ph >> 24; |
|
|
val1 = sine_table[index]; |
|
|
|
|
|
val2 = sine_table[index+1]; |
|
|
|
|
|
|
|
|
val1 = wavetable[index]; |
|
|
|
|
|
val2 = wavetable[index+1]; |
|
|
scale = (ph >> 8) & 0xFFFF; |
|
|
scale = (ph >> 8) & 0xFFFF; |
|
|
val2 *= scale; |
|
|
val2 *= scale; |
|
|
val1 *= 0xFFFF - scale; |
|
|
val1 *= 0xFFFF - scale; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
void AudioSineWaveMod::frequency(float f) |
|
|
void AudioSineWaveMod::frequency(float f) |
|
|
{ |
|
|
{ |
|
|
if (f > AUDIO_SAMPLE_RATE_EXACT / 2 || f < 0.0) return; |
|
|
if (f > AUDIO_SAMPLE_RATE_EXACT / 2 || f < 0.0) return; |
|
|
|
|
|
|
|
|
transmit(block); |
|
|
transmit(block); |
|
|
release(block); |
|
|
release(block); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|