Browse Source

declare tone_incr to be volatile to prevent the compiler optimizing frequency() out of existence

dds
Pete (El Supremo) 10 years ago
parent
commit
a2682bac25
2 changed files with 7 additions and 5 deletions
  1. +1
    -0
      synth_waveform.cpp
  2. +6
    -5
      synth_waveform.h

+ 1
- 0
synth_waveform.cpp View File

ramp_length = r_length; ramp_length = r_length;
} }



boolean AudioSynthWaveform::begin(float t_amp,int t_hi,short type) boolean AudioSynthWaveform::begin(float t_amp,int t_hi,short type)
{ {
tone_type = type; tone_type = type;

+ 6
- 5
synth_waveform.h View File

ramp_down(0), ramp_up(0), ramp_length(0) ramp_down(0), ramp_up(0), ramp_length(0)
{ {
} }
// Change the frequency on-the-fly to permit a phase-continuous
// change between two frequencies.
void frequency(int t_hi) void frequency(int t_hi)
{ {
// tone_incr = (0x100000000LL*t_hi)/AUDIO_SAMPLE_RATE_EXACT;
tone_incr = (0x80000000LL*t_hi)/AUDIO_SAMPLE_RATE_EXACT; tone_incr = (0x80000000LL*t_hi)/AUDIO_SAMPLE_RATE_EXACT;
} }
// If ramp_length is non-zero this will set up // If ramp_length is non-zero this will set up
// either a rmap up or a ramp down when a wave // either a rmap up or a ramp down when a wave
// first starts or when the amplitude is set // first starts or when the amplitude is set
// set new magnitude // set new magnitude
tone_amp = n * 32767.0; tone_amp = n * 32767.0;
} }
boolean begin(float t_amp,int t_hi,short t_type); boolean begin(float t_amp,int t_hi,short t_type);
virtual void update(void); virtual void update(void);
void set_ramp_length(int16_t r_length); void set_ramp_length(int16_t r_length);
private: private:
short tone_amp; short tone_amp;
short last_tone_amp; short last_tone_amp;
short tone_freq; short tone_freq;
uint32_t tone_phase; uint32_t tone_phase;
uint32_t tone_incr;
// volatile prevents the compiler optimizing out the frequency function
volatile uint32_t tone_incr;
short tone_type; short tone_type;


uint32_t ramp_down; uint32_t ramp_down;

Loading…
Cancel
Save