PaulStoffregen 7 years ago
parent
commit
88535e1164
3 changed files with 14 additions and 3 deletions
  1. +3
    -0
      gui/index.html
  2. +3
    -3
      synth_tonesweep.cpp
  3. +8
    -0
      synth_tonesweep.h

+ 3
- 0
gui/index.html View File

<p class=func><span class=keyword>isPlaying</span>();</p> <p class=func><span class=keyword>isPlaying</span>();</p>
<p class=desc>Returns true (non-zero) while the output is active. <p class=desc>Returns true (non-zero) while the output is active.
</p> </p>
<p class=func><span class=keyword>read</span>();</p>
<p class=desc>Returns the current frequency, or zero if the output is not active.
</p>
<h3>Examples</h3> <h3>Examples</h3>
<p class=exam>File &gt; Examples &gt; Audio &gt; HardwareTesting &gt; ToneSweep <p class=exam>File &gt; Examples &gt; Audio &gt; HardwareTesting &gt; ToneSweep
</p> </p>

+ 3
- 3
synth_tonesweep.cpp View File

if(t_hi < 1)return false; if(t_hi < 1)return false;
if(t_hi >= (int) AUDIO_SAMPLE_RATE_EXACT / 2)return false; if(t_hi >= (int) AUDIO_SAMPLE_RATE_EXACT / 2)return false;
if(t_lo >= (int) AUDIO_SAMPLE_RATE_EXACT / 2)return false; if(t_lo >= (int) AUDIO_SAMPLE_RATE_EXACT / 2)return false;
if(t_time < 0)return false;
if(t_time <= 0)return false;
tone_lo = t_lo; tone_lo = t_lo;
tone_hi = t_hi; tone_hi = t_hi;
tone_phase = 0; tone_phase = 0;
uint64_t tone_tmp = (0x400000000000LL * (int)(tmp&0x7fffffff)) / (int) AUDIO_SAMPLE_RATE_EXACT; uint64_t tone_tmp = (0x400000000000LL * (int)(tmp&0x7fffffff)) / (int) AUDIO_SAMPLE_RATE_EXACT;
// Generate the sweep // Generate the sweep
for(i = 0;i < AUDIO_BLOCK_SAMPLES;i++) { for(i = 0;i < AUDIO_BLOCK_SAMPLES;i++) {
*bp++ = (short)(( (short)(arm_sin_q31((uint32_t)((tone_phase >> 15)&0x7fffffff))>>16) *tone_amp) >> 16);
*bp++ = (short)(( (short)(arm_sin_q31((uint32_t)((tone_phase >> 15)&0x7fffffff))>>16) *tone_amp) >> 15);


tone_phase += tone_tmp; tone_phase += tone_tmp;
if(tone_phase & 0x800000000000LL)tone_phase &= 0x7fffffffffffLL; if(tone_phase & 0x800000000000LL)tone_phase &= 0x7fffffffffffLL;
} }
tone_freq += tone_incr; tone_freq += tone_incr;
} else { } else {
if(tmp < tone_hi) {
if(tmp < tone_hi || tone_freq < tone_incr) {
sweep_busy = 0; sweep_busy = 0;


break; break;

+ 8
- 0
synth_tonesweep.h View File

boolean play(float t_amp,int t_lo,int t_hi,float t_time); boolean play(float t_amp,int t_lo,int t_hi,float t_time);
virtual void update(void); virtual void update(void);
unsigned char isPlaying(void); unsigned char isPlaying(void);
float read(void) {
__disable_irq();
uint64_t freq = tone_freq;
unsigned char busy = sweep_busy;
__enable_irq();
if (!busy) return 0.0f;
return (float)(freq >> 32);
}


private: private:
short tone_amp; short tone_amp;

Loading…
Cancel
Save