AudioSynthToneSweep never ends

janbor

Active member
If I do an AudioSynthToneSweep sweep(0.8, 1000, 1000, 1) the sweep never ends. This is because the tone_tmp and tone_incr is 0 and so the loop never triggers the end-check (if((tone_freq >> 32) > tone_hi)). While 1000Hz to 1000Hz is not really a "sweep", it may cause problems.
 
It hadn't occurred to me that anyone would do that :)

It might also be worthwhile making sure that t_time is not zero, and in fact even better would be to ensure that it is greater than some reasonable value (half a second?). With floating point arguments, you can pass pathological values, e.g. a value of 1e-20 for t_time will blow up the calculation of tone_tmp which involves division by t_time. Similarly, the difference between the high and low frequencies should be some reasonable value (2Hz?).
In the play() function of AudioSynthToneSweep, change
Code:
  if(t_time < 0)return false;
to
Code:
  // t_time should not be too small
  if(t_time <= 0.5)return false;
  // Ensure that the difference between t_hi and t_lo is "reasonable"
  if(abs(t_hi - t_lo) < 2)return false;

Pete
 
Thanks. I feel special. ;)

Is this careful/drastic approach necessary. I'm thinking a very small t_time and abs(t_hi-t_lo) is well defined and sometimes even useful - f.inst. when they are the result of some calculation. It is easy enough to allow them and rewrite code so they still work.

Jan
 
Also, the sweep can not handle negative sweeps: sweep(08,1000,900,1), and finally, the duration most certainly is not in milliseconds.
 
Back
Top