Browse Source

Fix up synth_tonesweep and the example to conform (more closely) to the naming conventions

dds
Pete (El Supremo) 10 years ago
parent
commit
456a59dc0c
3 changed files with 12 additions and 14 deletions
  1. +5
    -5
      examples/ToneSweep/ToneSweep.ino
  2. +5
    -7
      synth_tonesweep.cpp
  3. +2
    -2
      synth_tonesweep.h

+ 5
- 5
examples/ToneSweep/ToneSweep.ino View File

AudioControlSGTL5000 audioShield; AudioControlSGTL5000 audioShield;




int t_ampx = 20000;
float t_ampx = 0.8;
int t_lox = 10; int t_lox = 10;
int t_hix = 22000; int t_hix = 22000;
// Length of time for the sweep in seconds // Length of time for the sweep in seconds


Serial.println("setup done"); Serial.println("setup done");


if(!myEffect.begin(t_ampx,t_lox,t_hix,t_timex)) {
if(!myEffect.play(t_ampx,t_lox,t_hix,t_timex)) {
Serial.println("AudioSynthToneSweep - begin failed"); Serial.println("AudioSynthToneSweep - begin failed");
while(1); while(1);
} }
// wait for the sweep to end // wait for the sweep to end
while(myEffect.busy());
while(myEffect.isPlaying());


// and now reverse the sweep // and now reverse the sweep
if(!myEffect.begin(t_ampx,t_hix,t_lox,t_timex)) {
if(!myEffect.play(t_ampx,t_hix,t_lox,t_timex)) {
Serial.println("AudioSynthToneSweep - begin failed"); Serial.println("AudioSynthToneSweep - begin failed");
while(1); while(1);
} }
// wait for the sweep to end // wait for the sweep to end
while(myEffect.busy());
while(myEffect.isPlaying());
Serial.println("Done"); Serial.println("Done");
} }



+ 5
- 7
synth_tonesweep.cpp View File

// Written by Pete (El Supremo) Feb 2014 // Written by Pete (El Supremo) Feb 2014




boolean AudioSynthToneSweep::begin(short t_amp,int t_lo,int t_hi,float t_time)
boolean AudioSynthToneSweep::play(float t_amp,int t_lo,int t_hi,float t_time)
{ {
double tone_tmp; double tone_tmp;
} }
tone_amp = 0; tone_amp = 0;
if(t_amp < 0)return false; if(t_amp < 0)return false;
if(t_amp > 1)return false;
if(t_lo < 1)return false; if(t_lo < 1)return false;
if(t_hi < 1)return false; if(t_hi < 1)return false;
if(t_hi >= 44100/2)return false; if(t_hi >= 44100/2)return false;
tone_hi = t_hi; tone_hi = t_hi;
tone_phase = 0; tone_phase = 0;


tone_amp = t_amp;
// Limit the output amplitude to prevent aliasing
// until I can figure out why this "overtops"
// above 29000.
if(tone_amp > 29000)tone_amp = 29000;
tone_amp = t_amp * 32767.0;

tone_tmp = tone_hi - tone_lo; tone_tmp = tone_hi - tone_lo;
tone_sign = 1; tone_sign = 1;
tone_freq = tone_lo*0x100000000LL; tone_freq = tone_lo*0x100000000LL;






unsigned char AudioSynthToneSweep::busy(void)
unsigned char AudioSynthToneSweep::isPlaying(void)
{ {
return(sweep_busy); return(sweep_busy);
} }

+ 2
- 2
synth_tonesweep.h View File

AudioStream(0,NULL), sweep_busy(0) AudioStream(0,NULL), sweep_busy(0)
{ } { }


boolean begin(short 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 busy(void);
unsigned char isPlaying(void);


private: private:
short tone_amp; short tone_amp;

Loading…
Cancel
Save